Skip to content

Commit

Permalink
XMAP: add coords to begin or end
Browse files Browse the repository at this point in the history
(Issue #9)
  • Loading branch information
sembruk committed Jul 12, 2017
1 parent 0c48467 commit cc63a3f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace Main {
Coords coords = osmNode.getCoords();
lastGeographicCoords = coords;
coords = Main::transform.geographicToMap(coords);
way.addCoord(coords,flags);
way.addCoordsToEnd(coords,flags);
}
return lastGeographicCoords;
}
Expand Down
44 changes: 31 additions & 13 deletions src/xmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,25 +158,43 @@ XmapObject::XmapObject(XmapTree* xmapTree, int id, const TagMap& tagMap) {
}

void
XmapObject::addCoord(const Coords& coords, int flags=0) {
XmapObject::addCoords(const Coords& coords, bool toBegin, int flags) {
if (coordsElement.getChildNumber() == 0) {
first = coords;
last = coords;
}
XmlElement coord(coordsElement.addChild("coord"));
coord.addAttribute<int>("x", coords.X());
coord.addAttribute<int>("y", coords.Y());
XmlElement coordEle;
if (toBegin) {
coordEle = coordsElement.addChildToBegin("coord");
first = coords;
}
else {
coordEle = coordsElement.addChildToEnd("coord");
lastCoordElement = coordEle;
last = coords;
}
coordEle.addAttribute<int>("x", coords.X());
coordEle.addAttribute<int>("y", coords.Y());
if (flags != 0) {
coord.addAttribute("flags", flags);
coordEle.addAttribute("flags", flags);
}
lastCoordElement = coord;
last = coords;
}

void
XmapObject::addCoordsToEnd(const Coords& coords, int flags=0) {
addCoords(coords, false, flags);
}

void
XmapObject::addCoordsToBegin(const Coords& coords, int flags=0) {
addCoords(coords, true, flags);
}

XmapPoint::XmapPoint(XmapTree* xmapTree, int id, const TagMap& tagMap, Coords& coords)
: XmapObject(xmapTree,id,tagMap) {
objectElement.addAttribute("type",0);
coordsElement.addAttribute("count",1);
addCoord(coords);
addCoordsToEnd(coords);
}

XmapWay::XmapWay(XmapTree* xmapTree, int id, const TagMap& tagMap = {})
Expand Down Expand Up @@ -209,11 +227,11 @@ XmapRectagngle::XmapRectagngle(XmapTree* xmapTree, int id, Coords& min, Coords&
: XmapWay(xmapTree, id) { ///< xmapAddRectangle()
Coords left (max.X(), min.Y());
Coords right(min.X(), max.Y());
addCoord(min);
addCoord(left);
addCoord(max);
addCoord(right);
addCoord(min); ///< close way
addCoordsToEnd(min);
addCoordsToEnd(left);
addCoordsToEnd(max);
addCoordsToEnd(right);
addCoordsToEnd(min); ///< close way
}

XmapText::XmapText(XmapTree* xmapTree, int id, const TagMap& tagMap, Coords& coords, const char * text)
Expand Down
5 changes: 4 additions & 1 deletion src/xmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ class XmapObject {

XmapObject(XmapTree* xmapTree, int id, const TagMap& tagMap);
public:
void addCoord(const Coords& coords, int flags);
void addCoordsToEnd(const Coords& coords, int flags);
void addCoordsToBegin(const Coords& coords, int flags);
private:
void addCoords(const Coords& coords, bool toBegin, int flags);
};

class XmapPoint
Expand Down

0 comments on commit cc63a3f

Please sign in to comment.