52 #ifdef CHECK_MEMORY_LEAKS
54 #endif // CHECK_MEMORY_LEAKS
64 std::copy(v.begin(), v.end(), std::back_inserter(*
this));
74 copy(p.begin(), p.end(), back_inserter(*
this));
100 for (const_iterator i = begin(); i != end() - 1; i++) {
105 (*(i + 1)).x() - p.
x(),
106 (*(i + 1)).y() - p.
y());
110 (*(end() - 1)).x() - p.
x(),
111 (*(end() - 1)).y() - p.
y());
113 (*(begin())).x() - p.
x(),
114 (*(begin())).y() - p.
y());
116 return (!(fabs(angle) <
M_PI));
122 for (const_iterator i = begin(); i != end() - 1; i++) {
123 if (poly.
around(*i, offset)) {
136 for (const_iterator i = begin(); i != end() - 1; i++) {
151 for (const_iterator i = begin(); i != end() - 1; i++) {
164 for (const_iterator i = begin(); i != end() - 1; i++) {
175 for (const_iterator i = begin(); i != end() - 1; i++) {
194 return at(size() + index);
204 return at(size() + index);
211 const_iterator i = begin();
214 const SUMOReal nextLength = (*i).distanceTo(*(i + 1));
215 if (seenLength + nextLength > pos) {
218 seenLength += nextLength;
219 }
while (++i != end() - 1);
226 const_iterator i = begin();
229 const SUMOReal nextLength = (*i).distanceTo2D(*(i + 1));
230 if (seenLength + nextLength > pos) {
233 seenLength += nextLength;
234 }
while (++i != end() - 1);
241 const_iterator i = begin();
244 SUMOReal nextLength = (*i).distanceTo(*(i + 1));
245 if (seenLength + nextLength > pos) {
246 Line l(*i, *(i + 1));
249 seenLength += nextLength;
250 }
while (++i != end() - 1);
251 Line l(*(end() - 2), *(end() - 1));
257 const_iterator i = begin();
260 SUMOReal nextLength = (*i).distanceTo(*(i + 1));
261 if (seenLength + nextLength > pos) {
262 Line l(*i, *(i + 1));
265 seenLength += nextLength;
266 }
while (++i != end() - 1);
267 Line l(*(end() - 2), *(end() - 1));
279 return p1 + (p2 - p1) * (pos / dist);
291 return p1 + (p2 - p1) * (pos / dist);
298 for (const_iterator i = begin(); i != end(); i++) {
309 for (const_iterator i = begin(); i != end(); i++) {
323 const int endIndex = (
int)tmp.size() - 1;
327 if (tmp.
area() != 0) {
329 for (
int i = 0; i < endIndex; i++) {
330 const SUMOReal z = tmp[i].x() * tmp[i + 1].y() - tmp[i + 1].x() * tmp[i].y();
332 x += (tmp[i].x() + tmp[i + 1].x()) * z;
333 y += (tmp[i].y() + tmp[i + 1].y()) * z;
341 for (
int i = 0; i < endIndex; i++) {
343 x += (tmp[i].x() + tmp[i + 1].x()) * length / 2;
344 y += (tmp[i].y() + tmp[i + 1].y()) * length / 2;
347 return Position(x / lengthSum, y / lengthSum);
355 for (
int i = 0; i < static_cast<int>(size()); i++) {
356 (*this)[i] = centroid + (((*this)[i] - centroid) * factor);
364 for (
int i = 0; i < static_cast<int>(size()); i++) {
365 (*this)[i] = centroid + (((*this)[i] - centroid) + offset);
382 for (const_iterator i = begin(); i != end() - 1; i++) {
383 len += (*i).distanceTo(*(i + 1));
391 for (const_iterator i = begin(); i != end() - 1; i++) {
392 len += (*i).distanceTo2D(*(i + 1));
405 const int endIndex = (
int)tmp.size() - 1;
407 for (
int i = 0; i < endIndex; i++) {
408 area += tmp[i].x() * tmp[i + 1].y() - tmp[i + 1].x() * tmp[i].y();
419 for (const_iterator i = begin(); i != end() - 1; i++) {
420 if (poly.
around(*i, offset)) {
434 std::pair<PositionVector, PositionVector>
445 const_iterator it = begin() + 1;
446 SUMOReal next = first.back().distanceTo(*it);
452 next = first.back().distanceTo(*it);
454 if (fabs(where - (seen + next)) >
POSITION_EPS || it == end() - 1) {
457 Line tmpL(first.back(), *it);
458 Position p = tmpL.getPositionAtDistance(where - seen);
465 for (; it != end(); it++) {
468 assert(first.size() >= 2);
469 assert(second.size() >= 2);
470 assert(first.back() == second.front());
472 return std::pair<PositionVector, PositionVector>(first, second);
478 for (PositionVector::const_iterator i = geom.begin(); i != geom.end(); i++) {
479 if (i != geom.begin()) {
496 for (
int i = 0; i < static_cast<int>(size()); i++) {
497 (*this)[i].add(xoff, yoff, zoff);
504 for (
int i = 0; i < static_cast<int>(size()); i++) {
505 (*this)[i].reshiftRotate(xoff, yoff, rot);
513 return atan2(p1.
x(), p1.
y()) < atan2(p2.
x(), p2.
y());
532 if (p1.
x() != p2.
x()) {
533 return p1.
x() < p2.
x();
535 return p1.
y() < p2.
y();
543 return (P1.
x() - P0.
x()) * (P2.
y() - P0.
y()) - (P2.
x() - P0.
x()) * (P1.
y() - P0.
y());
558 for (const_iterator i = begin(); i != end() - 1; i++) {
561 *i, *(i + 1), line.
p1(), line.
p2()));
570 if (back().distanceTo(v[0]) < 2) {
571 copy(v.begin() + 1, v.end(), back_inserter(*
this));
575 Line l1((*
this)[static_cast<int>(size()) - 2], back());
581 (*this)[
static_cast<int>(size()) - 1] = p;
582 copy(v.begin() + 1, v.end(), back_inserter(*
this));
585 copy(v.begin(), v.end(), back_inserter(*
this));
593 if (back().distanceTo(v[0]) < 2) {
594 copy(v.begin() + 1, v.end(), back_inserter(*
this));
596 copy(v.begin(), v.end(), back_inserter(*
this));
615 const_iterator i = begin();
617 while ((i + 1) != end()
619 seen + (*i).distanceTo(*(i + 1)) < beginOffset) {
620 seen += (*i).distanceTo(*(i + 1));
624 while ((i + 1) != end()
626 seen + (*i).distanceTo(*(i + 1)) < endOffset) {
634 seen += (*i).distanceTo(*(i + 1));
657 const_iterator i = begin();
659 while ((i + 1) != end()
661 seen + (*i).distanceTo2D(*(i + 1)) < beginOffset) {
662 seen += (*i).distanceTo2D(*(i + 1));
666 while ((i + 1) != end()
668 seen + (*i).distanceTo2D(*(i + 1)) < endOffset) {
676 seen += (*i).distanceTo2D(*(i + 1));
695 if (currDist >= 0 && currDist < dist) {
700 for (iterator i = begin(); i != end() - 1; i++, currPos++) {
702 if (currDist >= 0 && currDist < dist) {
708 for (
size_t j = 0; j < pos; j++) {
713 (*
this)[0], (*
this)[1], p);
718 if (np != *(begin())) {
720 if (np != *(begin())) {
723 assert(*(begin()) != *(end() - 1));
739 if (currDist >= 0 && currDist < dist) {
744 for (reverse_iterator i = rbegin(); i != rend() - 1; i++, currPos++) {
746 if (currDist >= 0 && currDist < dist) {
752 for (
size_t j = 0; j < pos; j++) {
758 (*
this)[static_cast<int>(size()) - 1], (*
this)[static_cast<int>(size()) - 2], p);
764 if (np != *(end() - 1)) {
766 if (np != *(end() - 1)) {
769 assert(*(begin()) != *(end() - 1));
777 Line tmp(front(), back());
797 for (const_iterator i = begin(); i != end() - 1; i++) {
801 if (dist < minDist) {
802 nearestPos = pos + seen;
805 if (perpendicular && i != begin()) {
808 if (cornerDist < minDist) {
810 minDist = cornerDist;
813 seen += (*i).distanceTo2D(*(i + 1));
825 for (
int i = 0; i < (
int)size(); i++) {
827 if (dist < minDist) {
841 int insertionIndex = 1;
842 for (
int i = 0; i < (
int)size() - 1; i++) {
844 if (dist < minDist) {
845 insertionIndex = i + 1;
850 return insertionIndex;
857 return front().distanceTo(p);
861 for (const_iterator i = begin(); i != end() - 1; i++) {
863 p, *i, *(i + 1), outIntersection));
869 std::vector<SUMOReal>
871 std::vector<SUMOReal> ret;
872 for (const_iterator i = other.begin(); i != other.end() - 1; i++) {
874 copy(atSegment.begin(), atSegment.end(), back_inserter(ret));
880 std::vector<SUMOReal>
882 std::vector<SUMOReal> ret;
884 for (const_iterator i = begin(); i != end() - 1; i++) {
885 Line l((*i), *(i + 1));
890 ret.push_back(atLength + pos);
905 (*
this)[static_cast<int>(size()) - 2], (*
this)[static_cast<int>(size()) - 1], val);
916 for (const_reverse_iterator i = rbegin(); i != rend(); i++) {
929 for (
int i = 0; i < static_cast<int>(size()); i++) {
933 std::pair<SUMOReal, SUMOReal> offsets =
936 from.
y() - offsets.second, from.
z()));
937 }
else if (i == static_cast<int>(size()) - 1) {
940 std::pair<SUMOReal, SUMOReal> offsets =
943 to.
y() - offsets.second, to.
z()));
949 me.
x() - to.
x(), me.
y() - to.
y()) / 2);
953 std::pair<SUMOReal, SUMOReal> off =
958 std::pair<SUMOReal, SUMOReal> offsets =
960 std::pair<SUMOReal, SUMOReal> offsets2 =
963 Position(from.
x() - offsets.first, from.
y() - offsets.second),
964 Position(me.
x() - offsets.first, me.
y() - offsets.second));
967 Position(me.
x() - offsets2.first, me.
y() - offsets2.second),
968 Position(to.
x() - offsets2.first, to.
y() - offsets2.second));
1010 assert((
int)size() > pos + 1);
1011 return Line((*
this)[pos], (*
this)[pos + 1]);
1023 return lineAt((
int)size() - 2);
1029 if ((*
this)[0] == back()) {
1036 std::vector<SUMOReal>
1038 std::vector<SUMOReal> ret;
1040 for (i = begin(); i != end(); i++) {
1043 for (i = s.begin(); i != s.end(); i++) {
1053 insert(begin() + index, p);
1055 insert(end() + index, p);
1062 assert(index < static_cast<int>(size()));
1063 assert(index + static_cast<int>(size()) >= 0);
1067 (*this)[index +
static_cast<int>(size())] = p;
1090 return size() >= 2 && (*this)[0] == back();
1097 iterator last = begin();
1098 for (iterator i = begin() + 1; i != end() && (!assertLength || size() > 2);) {
1099 if (last->almostSame(*i, minDist)) {
1114 for (iterator i = begin() + 1; i != end() - 1;) {
1128 if (size() == v2.size()) {
1129 for (
int i = 0; i < (
int)size(); i++) {
1130 if ((*
this)[i] != v2[i]) {
SUMOReal length2D() const
SUMOReal atan2DegreeAngle() const
static std::pair< SUMOReal, SUMOReal > getNormal90D_CW(const Position &beg, const Position &end, SUMOReal length, SUMOReal wanted_offset)
const Position & p2() const
static SUMOReal Angle2D(SUMOReal x1, SUMOReal y1, SUMOReal x2, SUMOReal y2)
void removeColinearPoints()
void pruneFromBeginAt(const Position &p)
static Position intersection_position2D(const Position &p11, const Position &p12, const Position &p21, const Position &p22)
returns the intersection point of the (infinite) lines p11,p12 and p21,p22. If the given lines are pa...
SUMOReal nearest_offset_to_point2D(const Position &p, bool perpendicular=true) const
PositionVector getSubpart2D(SUMOReal beginOffset, SUMOReal endOffset) const
Position positionAtOffset(SUMOReal pos) const
Returns the position at the given length.
void sortAsPolyCWByAngle()
void replaceAt(int index, const Position &by)
SUMOReal intersectsAtLength2D(const Line &v)
returns distance between myP1 and intersection or -1 if line segments do not intersect ...
void insertAt(int index, const Position &p)
std::vector< SUMOReal > distances(const PositionVector &s) const
SUMOReal atan2DegreeSlope() const
Position getCentroid() const
Returns the centroid (closes the polygon if unclosed)
bool intersects(const Position &p1, const Position &p2) const
void scaleRelative(SUMOReal factor)
enlarges/shrinks the polygon by a factor based at the centroid
bool partialWithin(const AbstractPoly &poly, SUMOReal offset=0) const
Returns the information whether this polygon lies partially within the given polygon.
static Position extrapolate_second(const Position &p1, const Position &p2, SUMOReal length)
SUMOReal distanceTo(const Position &p2) const
returns the euclidean distance in 3 dimension
bool around(const Position &p, SUMOReal offset=0) const
Returns the information whether the position vector describes a polygon lying around the given point ...
bool almostSame(const Position &p2, SUMOReal maxDiv=POSITION_EPS) const
static Position extrapolate_first(const Position &p1, const Position &p2, SUMOReal length)
SUMOReal beginEndAngle() const
const Position & operator[](int index) const
returns the position at the given index !!! exceptions?
SUMOReal x() const
Returns the x-position.
A class that stores a 2D geometrical boundary.
#define WRITE_WARNING(msg)
PositionVector reverse() const
SUMOReal slopeDegreeAtOffset(SUMOReal pos) const
Returns the slope at the given length.
PositionVector convexHull() const
~PositionVector()
Destructor.
SUMOReal length2D() const
Returns the length.
static SUMOReal nearest_offset_on_line_to_point2D(const Position &l1, const Position &l2, const Position &p, bool perpendicular=true)
Line lineAt(int pos) const
static bool intersects(const Position &p11, const Position &p12, const Position &p21, const Position &p22)
return whether given lines intersect
void push_front_noDoublePos(const Position &p)
const Position & p1() const
void reshiftRotate(SUMOReal xoff, SUMOReal yoff, SUMOReal rot)
A point in 2D or 3D with translation and scaling methods.
Position pop_front()
Removes and returns the position at the fron of the list.
void add(SUMOReal xoff, SUMOReal yoff, SUMOReal zoff)
int indexOfClosest(const Position &p) const
int operator()(const Position &p1, const Position &p2) const
comparing operation
void push_front(const Position &p)
Puts the given position at the front of the list.
static SUMOReal distancePointLine(const Position &point, const Position &lineStart, const Position &lineEnd)
SUMOReal z() const
Returns the z-position.
SUMOReal distance(const Position &p) const
int insertAtClosest(const Position &p)
std::string toString(const T &t, std::streamsize accuracy=OUTPUT_ACCURACY)
void sortByIncreasingXY()
Position intersectsAtPoint(const Position &p1, const Position &p2) const
SUMOReal atan2Angle() const
bool intersects(const Line &l) const
bool operator==(const PositionVector &v2) const
comparing operation
std::pair< PositionVector, PositionVector > splitAt(SUMOReal where) const
Returns the two lists made when this list vector is splitted at the given point.
virtual bool around(const Position &p, SUMOReal offset=0) const =0
void extrapolate(SUMOReal val)
PositionVector()
Constructor.
void extrapolateBy(SUMOReal length)
SUMOReal length() const
Returns the length.
SUMOReal rotationDegreeAtOffset(SUMOReal pos) const
Returns the rotation at the given length.
void push_back(const PositionVector &p)
Appends all positions from the given vector.
void add(SUMOReal x, SUMOReal y)
Makes the boundary include the given coordinate.
PositionVector simpleHull_2D(const PositionVector &V)
void removeDoublePoints(SUMOReal minDist=POSITION_EPS, bool assertLength=false)
Removes positions if too near.
PositionVector intersectionPoints2D(const Line &line) const
int appendWithCrossingPoint(const PositionVector &v)
Position positionAtOffset2D(SUMOReal pos) const
Returns the position at the given length.
void scaleAbsolute(SUMOReal offset)
enlarges/shrinks the polygon by an absolute offset based at the centroid
SUMOReal y() const
Returns the y-position.
bool overlapsWith(const AbstractPoly &poly, SUMOReal offset=0) const
Returns the information whether the given polygon overlaps with this Again a boundary may be specifie...
void pruneFromEndAt(const Position &p)
Position getLineCenter() const
SUMOReal distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
void move2side(SUMOReal amount)
void push_back_noDoublePos(const Position &p)
static SUMOReal closestDistancePointLine(const Position &point, const Position &lineStart, const Position &lineEnd, Position &outIntersection)
int operator()(const Position &p1, const Position &p2) const
comparing operation
Position getPolygonCenter() const
Returns the arithmetic of all corner points.
SUMOReal area() const
Returns the area (0 for non-closed)
std::vector< SUMOReal > intersectsAtLengths2D(const PositionVector &other) const
For all intersections between this vector and other, return the 2D-length of the subvector from this ...
void closePolygon()
ensures that the last position equals the first
Boundary getBoxBoundary() const
Returns a boundary enclosing this list of lines.
void append(const PositionVector &v)
increasing_x_y_sorter()
constructor
bool crosses(const Position &p1, const Position &p2) const
Position intersectsAt(const Line &l) const
PositionVector getSubpart(SUMOReal beginOffset, SUMOReal endOffset) const
SUMOReal isLeft(const Position &P0, const Position &P1, const Position &P2) const
std::ostream & operator<<(std::ostream &os, const PositionVector &geom)