void object::test<2> () { runPtLocator(Location::INTERIOR, Coordinate(0, 0), "POLYGON ((-40 80, -40 -80, 20 0, 20 -100, 40 40, 80 -80, 100 80, 140 -20, 120 140, 40 180, 60 40, 0 120, -20 -20, -40 80))"); }
// TEST THE CHECK ORIENTATION FUNCTION TEST_F(CityTest, CheckOrientation){ std::ofstream stream("Output files/unusedOutput.txt"); City c("XML-Files/stad.xml", stream); EXPECT_EQ("horizontal", c.checkOrientation(Coordinate(3, 0))); EXPECT_EQ("horizontal", c.checkOrientation(Coordinate(11, 0))); EXPECT_EQ("horizontal", c.checkOrientation(Coordinate(14, 0))); EXPECT_EQ("horizontal", c.checkOrientation(Coordinate(19, 0))); EXPECT_EQ("horizontal", c.checkOrientation(Coordinate(3, 5))); EXPECT_EQ("horizontal", c.checkOrientation(Coordinate(11, 5))); EXPECT_EQ("horizontal", c.checkOrientation(Coordinate(14, 5))); EXPECT_EQ("horizontal", c.checkOrientation(Coordinate(19, 5))); EXPECT_EQ("horizontal", c.checkOrientation(Coordinate(3, 10))); EXPECT_EQ("horizontal", c.checkOrientation(Coordinate(11, 10))); EXPECT_EQ("horizontal", c.checkOrientation(Coordinate(14, 10))); EXPECT_EQ("horizontal", c.checkOrientation(Coordinate(19, 10))); EXPECT_EQ("horizontal", c.checkOrientation(Coordinate(3, 15))); EXPECT_EQ("horizontal", c.checkOrientation(Coordinate(11, 15))); EXPECT_EQ("horizontal", c.checkOrientation(Coordinate(14, 15))); EXPECT_EQ("horizontal", c.checkOrientation(Coordinate(19, 15))); EXPECT_EQ("vertical", c.checkOrientation(Coordinate(0, 13))); EXPECT_EQ("vertical", c.checkOrientation(Coordinate(0, 8))); EXPECT_EQ("vertical", c.checkOrientation(Coordinate(0, 6))); EXPECT_EQ("vertical", c.checkOrientation(Coordinate(0, 2))); EXPECT_EQ("vertical", c.checkOrientation(Coordinate(7, 13))); EXPECT_EQ("vertical", c.checkOrientation(Coordinate(7, 8))); EXPECT_EQ("vertical", c.checkOrientation(Coordinate(7, 6))); EXPECT_EQ("vertical", c.checkOrientation(Coordinate(7, 2))); EXPECT_EQ("vertical", c.checkOrientation(Coordinate(16, 13))); EXPECT_EQ("vertical", c.checkOrientation(Coordinate(16, 8))); EXPECT_EQ("vertical", c.checkOrientation(Coordinate(16, 6))); EXPECT_EQ("vertical", c.checkOrientation(Coordinate(16, 2))); EXPECT_EQ("vertical", c.checkOrientation(Coordinate(21, 13))); EXPECT_EQ("vertical", c.checkOrientation(Coordinate(21, 8))); EXPECT_EQ("vertical", c.checkOrientation(Coordinate(21, 6))); EXPECT_EQ("vertical", c.checkOrientation(Coordinate(21, 2))); EXPECT_EQ("crossroad", c.checkOrientation(Coordinate(0, 0))); EXPECT_EQ("crossroad", c.checkOrientation(Coordinate(7, 0))); EXPECT_EQ("crossroad", c.checkOrientation(Coordinate(16, 0))); EXPECT_EQ("crossroad", c.checkOrientation(Coordinate(21, 0))); EXPECT_EQ("crossroad", c.checkOrientation(Coordinate(0, 5))); EXPECT_EQ("crossroad", c.checkOrientation(Coordinate(7, 5))); EXPECT_EQ("crossroad", c.checkOrientation(Coordinate(16, 5))); EXPECT_EQ("crossroad", c.checkOrientation(Coordinate(21, 5))); EXPECT_EQ("crossroad", c.checkOrientation(Coordinate(0, 10))); EXPECT_EQ("crossroad", c.checkOrientation(Coordinate(7, 10))); EXPECT_EQ("crossroad", c.checkOrientation(Coordinate(16, 10))); EXPECT_EQ("crossroad", c.checkOrientation(Coordinate(21, 10))); EXPECT_EQ("crossroad", c.checkOrientation(Coordinate(0, 15))); EXPECT_EQ("crossroad", c.checkOrientation(Coordinate(7, 15))); EXPECT_EQ("crossroad", c.checkOrientation(Coordinate(16, 15))); EXPECT_EQ("crossroad", c.checkOrientation(Coordinate(21, 15))); stream.close(); }
/////////////////////////////////////////////////////////////////////////////// /// @brief Finds the shortest path from start to any target in the list, avoiding units and walls. A path will never be found if all targets are occupied or contains a wall. Returns true if and only if a path was found. /// /// @param path If the return value is true, path will contain the shortest path from start to the nearest target. /// @param start Where pathing is to start from. /// @param targetList A list of target destinations. /////////////////////////////////////////////////////////////////////////////// bool baseAI::findPath(vector<Coordinate>& path, const Coordinate start, const vector<Coordinate> targetList) { int dis[26][26]; int via[26][26]; bool success = false; bool changing = true; int newVal; static bool first = true; //via // 1 // 2 0 // 3 if (start.x() < 0 || start.y() < 0 || start.x() > 25 || start.y() > 25) { cout << "Error: Path was called with a start coordinate that was out of bounds."; return false; } for (int i = 0; i < targetList.size(); i++) { if (targetList[i].x() < 0 || targetList[i].y() < 0 || targetList[i].x() > 25 || targetList[i].y() > 25) { cout << "Error: Path was called with a target coordinate that was out of bounds."; return false; } } if (first) { first = false; plotWalls(); } plotUnits(); for (int x = 0; x < 26; x++) { for (int y = 0; y < 26; y++) { dis[x][y] = 999; via[x][y] = -1; } } for (int i = 0; i < targetList.size(); i++) { if (!occupied[targetList[i].x()][targetList[i].y()] && !walled[targetList[i].x()][targetList[i].y()]) dis[targetList[i].x()][targetList[i].y()] = 0; } while (changing) { changing = false; for (int x = 0; x < 26; x++) { for (int y = 0; y < 26; y++) { if (!walled[x][y] && (!occupied[x][y] || start == Coordinate(x,y))) { //newVal = dis[x][y]; if (x > 0) { if (dis[x-1][y]+1 < dis[x][y]) { dis[x][y] = dis[x-1][y]+1; via[x][y] = 2; changing = true; } } if (x < 25) { if (dis[x+1][y]+1 < dis[x][y]) { dis[x][y] = dis[x+1][y]+1; via[x][y] = 0; changing = true; } } if (y > 0) { if (dis[x][y-1]+1 < dis[x][y]) { dis[x][y] = dis[x][y-1]+1; via[x][y] = 3; changing = true; } } if (y < 25) { if (dis[x][y+1]+1 < dis[x][y]) { dis[x][y] = dis[x][y+1]+1; via[x][y] = 1; changing = true; } } } } } } path.clear(); Coordinate curPos(start.x(), start.y()); if (via[start.x()][start.y()] == -1) { success = false; } else { success = true; while (dis[curPos.x()][curPos.y()] != 0) { switch (via[curPos.x()][curPos.y()]) { case 0: curPos = curPos + Coordinate(1, 0); break; case 1: curPos = curPos + Coordinate(0, 1); break; case 2: curPos = curPos + Coordinate(-1, 0); break; case 3: curPos = curPos + Coordinate(0, -1); break; } path.push_back(curPos); } } return success; }
void SegmentationProxy::subobject_from_id(const quint64 subObjId, const QList<int> & coord) { Segmentation::singleton().subobjectFromId(subObjId, Coordinate(coord)); }
void getCommonCoordinate(geom::Coordinate& c) { c=Coordinate(commonBitsX.getCommon(), commonBitsY.getCommon()); }
Object::Object(int x, int y) { this->c = Coordinate(x,y); }
/* -- Reflex Agent -- */ Coordinate Hunter::move(vector<vector<int> > surroundings) { // Default state // The Hunter is not moving bool eating = false; // The Hunter has now moved moved = true; // The Hunter is not eligable to breed eligable = false; // Steps keeps track of which step the world is on steps++; // Tracks when the Hunter can breed counter++; // Basically a death counter that gets extended when the Hunter eats eaten--; // Influence the decision by seeding the pseudo-random number generation. if (rand() % 3 == 1) srand((unsigned int) time(0)); else if (rand() % 3 == 2) srand((unsigned int) steps); else srand((unsigned int) rand()); vector<Coordinate> coords; // All adjacent empty blocks vector<Coordinate> ally; // All adjacent coordinates of fellow Hunters for (int i = 0; i < surroundings.size(); i++) for (int j = 0; j < surroundings[i].size(); j++) { if (surroundings[i][j] == 2) // If there is an adjacent Hunter { eligable = true; // Eligable for breeding ally.push_back(Coordinate(i-1, j-1)); } if (!eating) { // Default, if there is no Prey adjacent, this block will keep // control until it finds prey. if (surroundings[i][j] == 1) // if there is PREY { eating = true; // change control to PREY mode (search only for prey) eaten = starveIterations; coords.clear(); // clear all non-prey spaces coords.push_back(Coordinate(i-1, j-1)); // This causes Hunters to always choose the first Prey they come // across, and consequently, the Hunters aggregate together // by forming packs. lastMove = Coordinate(i-1, j-1); /* -- Disable Pack AI -- */ } else if (surroundings[i][j] == 0) // if there is empty SPACE coords.push_back(Coordinate(i-1, j-1)); } else { if (surroundings[i][j] == 1) // If the Hunter is eating and there's Prey coords.push_back(Coordinate(i-1, j-1)); } } if (ally.size() && coords.size() && rand() % 6 == 0) { // This causes Hunters to prefer potential movements (when eating or otherwise) // when they bring them closer to other Hunters. The Hunters prefer to be in // packs. int index = 0; for (int i = 0; i < coords.size(); i++) for (int j = 0; j < ally.size(); j++) if (coords[i].x == ally[j].x || coords[i].y == ally[j].y) index = i; lastMove = coords[index]; } else if (coords.size()) { // This causes Hunters to go in a straight line if that path seems like it // will benefit them. for (int i = 0; i < coords.size(); i++) if (coords[i] == lastMove) // If the move candidate is equal to the Last Move return coords[i]; // Do that move lastMove = coords[rand() % coords.size()]; // otherwise, pick a random movement } else // There is no movementd to make. lastMove = Coordinate(0, 0); return lastMove; }
Coordinate Coordinate::operator-(const Coordinate &other) { return (Coordinate(x-other.x, y-other.y)); }
Coordinate Coordinate::operator+(const Coordinate &other) { return (Coordinate(x+other.x, y+other.y)); }
void ClippingService::clipLiangBarsky(ViewWindow* window, DrawableObject *object) { if (object->getCoordinatesWindow().size() % 2 != 0) { throw 32; } list<Coordinate> clippedCoordinates; Coordinate p1, p2; int k = 0; for (Coordinate cord : object->getCoordinatesWindow()) { if (k % 2 == 0) { p1 = cord; } else { p2 = cord; double u1 = 0.0; double u2 = 1.0; double xDelta = p2.getx() - p1.getx(); double yDelta = p2.gety() - p1.gety(); double p, q, r; bool draw = true; for (int i = 0; i < 4; i++) { switch (i) { case 0: { p = -1 * xDelta; q = -1 * (window->getXwmin() - p1.getx()); break; } case 1: { p = xDelta; q = (window->getXwmax() - p1.getx()); break; } case 2: { p = -1 * yDelta; q = -1 * (window->getYwmin() - p1.gety()); break; } case 3: { p = yDelta; q = (window->getYwmax() - p1.gety()); break; } } r = q / p; if ((p == 0 && q < 0) || (p < 0 && r > u2) || (p > 0 && r < u1)) { draw = false; break; } if (p < 0 && r > u1) { u1 = r; } if (p > 0 && r < u2) { u2 = r; } } if (draw) { double x1 = p1.getx() + u1*xDelta; double y1 = p1.gety() + u1*yDelta; double x2 = p1.getx() + u2*xDelta; double y2 = p1.gety() + u2*yDelta; clippedCoordinates.push_back(Coordinate(x1, y1)); clippedCoordinates.push_back(Coordinate(x2, y2)); } } k++; } object->setCoordinatesClipped(clippedCoordinates); }
static const uint8_t DEFAULT_PLAYER1_COLOUR_B = 31; static const uint8_t DEFAULT_PLAYER2_COLOUR_R = 0; // blue static const uint8_t DEFAULT_PLAYER2_COLOUR_G = 0; static const uint8_t DEFAULT_PLAYER2_COLOUR_B = 229; static const uint8_t DEFAULT_PLAYER3_COLOUR_R = 134; // yellow static const uint8_t DEFAULT_PLAYER3_COLOUR_G = 138; static const uint8_t DEFAULT_PLAYER3_COLOUR_B = 8; static const uint8_t DEFAULT_PLAYER4_COLOUR_R = 180; // red static const uint8_t DEFAULT_PLAYER4_COLOUR_G = 4; static const uint8_t DEFAULT_PLAYER4_COLOUR_B = 4; static const int32_t DEFAULT_NROWS = 20; static const int32_t DEFAULT_NCOLS = 20; static const Coordinate PLAYER1_DEFAULT_STARTING_COORD = Coordinate(0, 0); static const Coordinate PLAYER2_DEFAULT_STARTING_COORD = Coordinate(0, DEFAULT_NCOLS - 1); static const Coordinate PLAYER3_DEFAULT_STARTING_COORD = Coordinate(DEFAULT_NROWS - 1, DEFAULT_NCOLS - 1); static const Coordinate PLAYER4_DEFAULT_STARTING_COORD = Coordinate(DEFAULT_NROWS - 1, 0); Game4PlayersConfig::Game4PlayersConfig() : Singleton<Game4PlayersConfig>(), m_nRows(DEFAULT_NROWS), m_nColumns(DEFAULT_NCOLS) { // set default starting coords m_startingCoords[0] = PLAYER1_DEFAULT_STARTING_COORD;
NodePtr GeometryConverter::convertPointToNode(const geos::geom::Point* point, const OsmMapPtr& map, Status s, double circularError) { return _createNode(map, Coordinate(point->getX(), point->getY()), s, circularError); }
void object::test<4> () { runPtLocator(Location::EXTERIOR, Coordinate(11, 11), "LINEARRING(10 10, 10 20, 20 10, 10 10)"); }
void object::test<3> () { runPtLocator(Location::BOUNDARY, Coordinate(0, 0), "GEOMETRYCOLLECTION( LINESTRING(0 0, 10 10), LINEARRING(10 10, 10 20, 20 10, 10 10))"); }
Coordinate operator+ (const Coordinate&a, const Coordinate&b){ return Coordinate(a.x + b.x, a.y + b.y); }
// Build and return a top-down area map around a given coordinate std::string PC::generate_area_map(const std::unique_ptr<World> & world, const std::map<std::string, std::shared_ptr<Character>> & actors) const { std::vector<std::vector<char>> user_map; // three vectors feed into one vector // create a 2D vector to represent whether or not a tree is at a location. // Dimensions are (view+1+view) plus a padding of 1 on each side std::vector<std::vector<bool>> forest_grid((C::VIEW_DISTANCE * 2) + 3, std::vector<bool>((C::VIEW_DISTANCE * 2) + 3, false)); // extract these for convinence - we're using the x and y a lot here const int x = location.get_x(), y = location.get_y(); /* We're looking for presence/absence info on trees in a 11*11 radius, and fitting it into a 13x13 grid, with a ring around for bounds padding. Top row is an example of indexes, botttom row is the forest_grid indexes these have to line up with player ---------v 45 46 47 48 49 (50) 51 52 53 54 55 1 2 3 4 5 6 7 8 9 10 11 The following formula is applied to the indexes we're iterating over: tree_grid index = current index - (player index - (view distance + 1)) */ for (int cx = x - (int)C::VIEW_DISTANCE; cx <= x + (int)C::VIEW_DISTANCE; ++cx) { const int i = cx - (x - (C::VIEW_DISTANCE + 1)); for (int cy = y - (int)C::VIEW_DISTANCE; cy <= y + (int)C::VIEW_DISTANCE; ++cy) { Coordinate current(cx, cy); if (current.is_valid()) forest_grid[i][cy - (y - (C::VIEW_DISTANCE + 1))] = world->room_at(current)->contains(C::TREE_ID); } } /* for each row in sight range for each room in sight range in the row set n, e, s, w to(room contains surface ? ); */ for (int cx = x - (int)C::VIEW_DISTANCE; cx <= x + (int)C::VIEW_DISTANCE; ++cx) { std::vector<char> a, b, c; // three rows for (int cy = y - (int)C::VIEW_DISTANCE; cy <= y + (int)C::VIEW_DISTANCE; ++cy) { Coordinate current(cx, cy); // if the room is out of bounds if (!current.is_valid()) { // draw the "room" a.push_back(C::LAND_CHAR); a.push_back(C::LAND_CHAR); a.push_back(C::LAND_CHAR); b.push_back(C::LAND_CHAR); b.push_back(C::OUT_OF_BOUNDS_CHAR); b.push_back(C::LAND_CHAR); c.push_back(C::LAND_CHAR); c.push_back(C::LAND_CHAR); c.push_back(C::LAND_CHAR); // skip to next room continue; } // if the coordinates are valid but the room is not loaded (this would be a major error) if (world->room_at(current) == nullptr) { // draw the "room" a.push_back(C::LAND_CHAR); a.push_back(C::LAND_CHAR); a.push_back(C::LAND_CHAR); b.push_back(C::LAND_CHAR); b.push_back(C::ERROR_CHAR); b.push_back(C::LAND_CHAR); c.push_back(C::LAND_CHAR); c.push_back(C::LAND_CHAR); c.push_back(C::LAND_CHAR); // skip to next room continue; } // if there is a forest char at the given location // Somehow a tree is currently chosen to represent a forest room. // 23 24 25 26 27 (28) 29 30 31 32 33 // 1 2 3 4 5 6 7 8 9 10 11 // access_x = current index - (player index - (view distance + 1)) */ // 1 = 23 - ( 28 - ( 5 + 1)) // FGA = forest grid access const int fga_x = cx - (x - (C::VIEW_DISTANCE + 1)); const int fga_y = cy - (y - (C::VIEW_DISTANCE + 1)); if (forest_grid[fga_x][fga_y]) // if there is a tree here, determine how the tile should be drawn { // is a forest area at the neighbouring coordinates? f_n == forest_north const bool f_n = forest_grid[fga_x - 1][fga_y]; const bool f_ne = forest_grid[fga_x - 1][fga_y + 1]; const bool f_e = forest_grid[fga_x][fga_y + 1]; const bool f_se = forest_grid[fga_x + 1][fga_y + 1]; const bool f_s = forest_grid[fga_x + 1][fga_y]; const bool f_sw = forest_grid[fga_x + 1][fga_y - 1]; const bool f_w = forest_grid[fga_x][fga_y - 1]; const bool f_nw = forest_grid[fga_x - 1][fga_y - 1]; // conditionally draw a tree or an empty space in the corners, other five are always draw as trees a.push_back(((f_n || f_nw || f_w) ? C::FOREST_CHAR : C::LAND_CHAR)); a.push_back(C::FOREST_CHAR); a.push_back(((f_n || f_ne || f_e) ? C::FOREST_CHAR : C::LAND_CHAR)); b.push_back(C::FOREST_CHAR); b.push_back(((cx == x && cy == y) ? C::PLAYER_CHAR : C::FOREST_CHAR)); b.push_back(C::FOREST_CHAR); c.push_back(((f_s || f_sw || f_w) ? C::FOREST_CHAR : C::LAND_CHAR)); c.push_back(C::FOREST_CHAR); c.push_back(((f_s || f_se || f_e) ? C::FOREST_CHAR : C::LAND_CHAR)); } // if the room is water else if (world->room_at(current)->is_water()) { // Either draw a 3x3 grid with a "wave", or a 3x3 grid with the player's icon. a.push_back(C::LAND_CHAR); a.push_back(C::LAND_CHAR); a.push_back(C::LAND_CHAR); b.push_back(C::LAND_CHAR); b.push_back(((cx == x && cy == y) ? C::PLAYER_CHAR : C::WATER_CHAR)); b.push_back(C::LAND_CHAR); c.push_back(C::LAND_CHAR); c.push_back(C::LAND_CHAR); c.push_back(C::LAND_CHAR); } // there is no tree, so there may be a structure else { // use a boolean value to indicate the presence or absence of a wall in this room const bool n = world->room_at(current)->has_surface(C::NORTH); const bool e = world->room_at(current)->has_surface(C::EAST); const bool s = world->room_at(current)->has_surface(C::SOUTH); const bool w = world->room_at(current)->has_surface(C::WEST); bool // is there a door present in a given location? nd = false, ed = false, sd = false, wd = false, // "north door?" // is a wall rubble in a given direction? nr = false, er = false, sr = false, wr = false; // "north rubble?" /* if a north wall is present -- north_has_door = room_at(x, y)...(surface_ID)...has_door(); -- north_is_rubble = (the wall is rubble OR -- -- (a door exists AND the door is rubble) */ if (n) { nd = world->room_at(current)->get_room_sides().find(C::NORTH)->second.has_door(); nr = (!world->room_at(current)->is_standing_wall(C::NORTH) || (nd && world->room_at(current)->get_room_sides().find(C::NORTH)->second.get_door()->is_rubble())); } if (e) { ed = world->room_at(current)->get_room_sides().find(C::EAST)->second.has_door(); er = (!world->room_at(current)->is_standing_wall(C::EAST) || (ed && world->room_at(current)->get_room_sides().find(C::EAST)->second.get_door()->is_rubble())); } if (s) { sd = world->room_at(current)->get_room_sides().find(C::SOUTH)->second.has_door(); sr = (!world->room_at(current)->is_standing_wall(C::SOUTH) || (sd && world->room_at(current)->get_room_sides().find(C::SOUTH)->second.get_door()->is_rubble())); } if (w) { wd = world->room_at(current)->get_room_sides().find(C::WEST)->second.has_door(); wr = (!world->room_at(current)->is_standing_wall(C::WEST) || (wd && world->room_at(current)->get_room_sides().find(C::WEST)->second.get_door()->is_rubble())); } // count the enemies standing at a coordinate unsigned enemy_count = 0, neutral_count = 0, friendly_count = 0; // for each actor in the room for (const std::string & actor_ID : world->room_at(current)->get_actor_ids()) { // if the actor is a hostile NPC if (U::is<Hostile_NPC>(actors.find(actor_ID)->second)) { ++enemy_count; // count one more enemy NPC in the room } else if (U::is<Neutral_NPC>(actors.find(actor_ID)->second)) { ++neutral_count; // count one more neutral NPC in the room } else if (U::is<PC>(actors.find(actor_ID)->second)) { ++friendly_count; } } // reduce enemy count to a single-digit number enemy_count = ((enemy_count > 9) ? 9 : enemy_count); // keep these for debugging // if (enemy_count > 0) { cout << "\nAt " << cx << "," << cy << " there are " << enemy_count << " enemies."; } // if (neutral_count > 0) { cout << "\nAt " << cx << "," << cy << " there are " << neutral_count << " neutrals."; } char nw_corner = C::LAND_CHAR, ne_corner = C::LAND_CHAR, se_corner = C::LAND_CHAR, sw_corner = C::LAND_CHAR; { // relative to the north west corner of the room, is there a wall to the n/e/s/w const bool wtn = world->room_has_surface(Coordinate(cx - 1, cy), C::WEST); const bool wte = world->room_has_surface(Coordinate(cx, cy), C::NORTH); const bool wts = world->room_has_surface(Coordinate(cx, cy), C::WEST); const bool wtw = world->room_has_surface(Coordinate(cx, cy - 1), C::NORTH); // in order for this corner to render, there must be one adjacent local wall OR two adjacent remote walls if (wte || wts || (wtn && wtw)) { nw_corner = C::WALL_CHAR; } } { // relative to the north east corner of the room, is there a wall to the n/e/s/w const bool wtn = world->room_has_surface(Coordinate(cx - 1, cy), C::EAST); const bool wte = world->room_has_surface(Coordinate(cx, cy + 1), C::NORTH); const bool wts = world->room_has_surface(Coordinate(cx, cy), C::EAST); const bool wtw = world->room_has_surface(Coordinate(cx, cy), C::NORTH); if (wtw || wts || (wtn && wte)) { ne_corner = C::WALL_CHAR; } } { // relative to the south east corner of the room, is there a wall to the n/e/s/w const bool wtn = world->room_has_surface(Coordinate(cx, cy), C::EAST); const bool wte = world->room_has_surface(Coordinate(cx, cy + 1), C::SOUTH); const bool wts = world->room_has_surface(Coordinate(cx + 1, cy), C::EAST); const bool wtw = world->room_has_surface(Coordinate(cx, cy), C::SOUTH); if (wtn || wtw || (wts && wte)) { se_corner = C::WALL_CHAR; } } { // relative to the south west corner of the room, is there a wall to the n/e/s/w const bool wtn = world->room_has_surface(Coordinate(cx, cy), C::WEST); const bool wte = world->room_has_surface(Coordinate(cx, cy), C::SOUTH); const bool wts = world->room_has_surface(Coordinate(cx + 1, cy), C::WEST); const bool wtw = world->room_has_surface(Coordinate(cx, cy - 1), C::SOUTH); if (wtn || wte || (wts && wtw)) { sw_corner = C::WALL_CHAR; } } // time for glorious nested ternary statements to do this cheap a.push_back(nw_corner); a.push_back(((nr) ? C::RUBBLE_CHAR : ((nd) ? C::DOOR_CHAR : ((n) ? C::WALL_CHAR : C::LAND_CHAR)))); a.push_back(ne_corner); b.push_back(((wr) ? C::RUBBLE_CHAR : ((wd) ? C::DOOR_CHAR : ((w) ? C::WALL_CHAR : C::LAND_CHAR)))); // if the current coordinates are the player's, draw an @ icon b.push_back(((cx == x && cy == y) ? C::PLAYER_CHAR // else if there is another player, draw a lowercase 'a' : ((friendly_count > 0) ? C::OTHER_PLAYER_CHAR // else if there is an enemy, draw enemy count : ((enemy_count > 0) ? U::to_char(enemy_count) // else if there are neutrals, draw neutral count : ((neutral_count > 0) ? C::NPC_NEUTRAL_CHAR // else if there is a table, draw a table : ((world->room_at(current)->has_table()) ? C::TABLE_CHAR // else if there is a chest, draw a chest : ((world->room_at(current)->has_chest()) ? C::CHEST_CHAR // else if there is a non-mineral deposit item, draw an item char : ((world->room_at(current)->has_non_mineral_deposit_item()) ? C::ITEM_CHAR // else if there is a mineral deposit, draw a mineral char : ((world->room_at(current)->has_mineral_deposit()) ? C::GENERIC_MINERAL_CHAR // else draw a land char : C::LAND_CHAR))))))))); b.push_back(((er) ? C::RUBBLE_CHAR : ((ed) ? C::DOOR_CHAR : ((e) ? C::WALL_CHAR : C::LAND_CHAR)))); c.push_back(sw_corner); c.push_back(((sr) ? C::RUBBLE_CHAR : ((sd) ? C::DOOR_CHAR : ((s) ? C::WALL_CHAR : C::LAND_CHAR)))); c.push_back(se_corner); } } // end for each room in row // add each row to the user map user_map.push_back(a); user_map.push_back(b); user_map.push_back(c); } // end for each row std::stringstream result; // for each row except the first and last for (unsigned i = 1; i < user_map.size() - 1; ++i) { // for all iterations except the first, append a newline if (i != 1) { result << std::endl; } // for each character in the row except the first and last for (unsigned j = 1; j < user_map[i].size() - 1; ++j) { // add the character to the result result << user_map[i][j]; } } return result.str(); }
Coordinate operator* (const Coordinate&a, const double&b){ return Coordinate(a.x * b, a.y * b); }
/**\brief Retrieves nearby QuadTrees in a square band at <bandIndex> quadrants distant from the coordinate * \param c Coordinate * \param bandIndex number of quadrants distant from c * \return std::list of QuadTree pointers. */ list<QuadTree*> SpriteManager::GetQuadrantsInBand ( Coordinate c, int bandIndex) { // The possibleQuadrants here are the quadrants that are in the square band // at distance bandIndex from the coordinate // After we get the possible quadrants we prune them by making sure they exist // (ie that something is in them) list<QuadTree*> nearbyQuadrants; set<Coordinate> possibleQuadrants; //note that the QUADRANTSIZE define is the // distance from the middle to the edge of a quadrant //to get the square band of co-ordinates we have to // - start at bottom left // loop over increasing Y (to get 'west' line) // loop over increasing X (to get 'south' line) // - start at top right // loop over decreasing Y (to get 'east' line) // loop over decreasing X (to get 'north' line) int edgeDistance = bandIndex * QUADRANTSIZE * 2; //number of pixels from middle to the band Coordinate bottomLeft (c - Coordinate (edgeDistance, edgeDistance)); Coordinate topLeft (c + Coordinate (-edgeDistance, edgeDistance)); Coordinate topRight (c + Coordinate (edgeDistance, edgeDistance)); Coordinate bottomRight (c + Coordinate (edgeDistance, -edgeDistance)); //the 'full' length of one of the lines is (bandindex * 2) + 1 //we don't need the +1 as we deal with the corners individually, separately int bandLength = (bandIndex * 2); //deal with the un-included corners first //we're using bottomLeft and topRight as the anchors, // so topLeft and bottomRight are added here possibleQuadrants.insert (GetQuadrantCenter (topLeft)); possibleQuadrants.insert (GetQuadrantCenter (bottomRight)); for (int i = 0; i < bandLength; i ++) { int offset = ((QUADRANTSIZE * 2) * i); Coordinate west, south, north, east; west = GetQuadrantCenter (bottomLeft + Coordinate (0, offset)); south = GetQuadrantCenter (bottomLeft + Coordinate (offset, 0)); north = GetQuadrantCenter (topRight - Coordinate (offset, 0)); east = GetQuadrantCenter (topRight - Coordinate (0, offset)); possibleQuadrants.insert (west); //west possibleQuadrants.insert (south); //south possibleQuadrants.insert (north); //north possibleQuadrants.insert (east); //east } //here we're checking to see if this possible quadrant is one of the existing quadrants // and if it is then we add its QuadTree to the vector we're returning // if it's not then there's nothing in it anyway so we don't care about it set<Coordinate>::iterator it; map<Coordinate,QuadTree*>::iterator iter; for(it = possibleQuadrants.begin(); it != possibleQuadrants.end(); ++it) { iter = trees.find(*it); if(iter != trees.end()) { nearbyQuadrants.push_back(iter->second); } } return nearbyQuadrants; }
inline Coordinate operator-(const Coordinate & coor, const Vector & vec) { return Coordinate(coor.getX() - vec.getDx(), coor.getY() - vec.getDy()); }
Coordinate vertical(){ return Coordinate(y, -x); }
void SegmentationProxy::create_object(const quint64 objId, const quint64 initialSubobjectId, const QList<int> & location, const bool todo, const bool immutable) { Segmentation::singleton().createObjectFromSubobjectId(initialSubobjectId, Coordinate(location), objId, todo, immutable); }
double getLengthSqr(){ return distanceSqr(Coordinate(0., 0.)); }
quint64 SegmentationProxy::largest_object_containing_subobject(const quint64 subObjId, const QList<int> & coord) { const auto & subobject = Segmentation::singleton().subobjectFromId(subObjId, Coordinate(coord)); const auto objIndex = Segmentation::singleton().largestObjectContainingSubobject(subobject); return Segmentation::singleton().objects[objIndex].id; }
Coordinate setLength(double length = 1.){ double len = sqrt(getLengthSqr()); return Coordinate(x / len * length, y / len * length); }
static IdType invalidId() { return Coordinate(); }
Coordinate clockwiseRotate(double theta){ return Coordinate(x * cos(2. * pi - theta) - y * sin(2. * pi - theta), x * sin(2. * pi - theta) + y * cos(2. * pi - theta)); }
/*public*/ void HCoordinate::getCoordinate(Coordinate& ret) const { ret = Coordinate(static_cast<double>(getX()), static_cast<double>(getY())); }
Coordinate operator- (const Coordinate&a, const Coordinate&b){ return Coordinate(a.x - b.x, a.y - b.y); }
void runLocateAfterTest() { OsmMap::resetCounters(); shared_ptr<OsmMap> map(new OsmMap()); Coordinate c[] = { Coordinate(0.0, 0.0), Coordinate(100.0, 0.0), Coordinate(100.0, 10.0), Coordinate(0.0, 10.0), Coordinate::getNull() }; WayPtr w = TestUtils::createWay(map, Unknown1, c, 1, ""); WayLocation wl(w, 0, 0); HOOT_STR_EQUALS("way: -1 index: 0 fraction: 0", LocationOfPoint(w).locateAfter(Coordinate(0,0), wl)); HOOT_STR_EQUALS("way: -1 index: 0 fraction: 0.1", LocationOfPoint(w).locateAfter(Coordinate(0,0), WayLocation(w, 10.0))); HOOT_STR_EQUALS("way: -1 index: 0 fraction: 0.1", LocationOfPoint(w).locateAfter(Coordinate(10,0), WayLocation(w, 0.0))); HOOT_STR_EQUALS("way: -1 index: 0 fraction: 0.2", LocationOfPoint(w).locateAfter(Coordinate(20,0), WayLocation(w, 0.0))); HOOT_STR_EQUALS("way: -1 index: 0 fraction: 0.5", LocationOfPoint(w).locateAfter(Coordinate(50,0), WayLocation(w, 20.0))); HOOT_STR_EQUALS("way: -1 index: 2 fraction: 0.5", LocationOfPoint(w).locateAfter(Coordinate(50,10), WayLocation(w, 0.0))); HOOT_STR_EQUALS("way: -1 index: 2 fraction: 0.5", LocationOfPoint(w).locateAfter(Coordinate(50,0), WayLocation(w, 100.0))); HOOT_STR_EQUALS("way: -1 index: 1 fraction: 0", LocationOfPoint(w).locateAfter(Coordinate(100,0), WayLocation(w, 0.0))); HOOT_STR_EQUALS("way: -1 index: 1 fraction: 0.2", LocationOfPoint(w).locateAfter(Coordinate(100,0), WayLocation(w, 102.0))); HOOT_STR_EQUALS("way: -1 index: 1 fraction: 0.2", LocationOfPoint(w).locateAfter(Coordinate(100,2), WayLocation(w, 100.0))); HOOT_STR_EQUALS("way: -1 index: 2 fraction: 0", LocationOfPoint(w).locateAfter(Coordinate(100,10), WayLocation(w, 110.0))); HOOT_STR_EQUALS("way: -1 index: 2 fraction: 0.5", LocationOfPoint(w).locateAfter(Coordinate(50,10), WayLocation(w, 110.0))); HOOT_STR_EQUALS("way: -1 index: 3 fraction: 0", LocationOfPoint(w).locateAfter(Coordinate(0,10), WayLocation(w, 0.0))); HOOT_STR_EQUALS("way: -1 index: 3 fraction: 0", LocationOfPoint(w).locateAfter(Coordinate(0,0), WayLocation(w, 3, 0))); HOOT_STR_EQUALS("way: -1 index: 3 fraction: 0", LocationOfPoint(w).locateAfter(Coordinate(0,10), WayLocation(w, 2, 0.3))); }
void object::test<1> () { runPtLocator(Location::INTERIOR, Coordinate(10, 10), "POLYGON ((0 0, 0 20, 20 20, 20 0, 0 0))"); }