OGS
GeoLib::Polygon Class Reference

Detailed Description

A polygon is a (closed) polyline. Thus class Polygon is derived from class Polyline.

Definition at line 19 of file Polygon.h.

#include <Polygon.h>

Inheritance diagram for GeoLib::Polygon:
[legend]
Collaboration diagram for GeoLib::Polygon:
[legend]

Public Member Functions

 Polygon (const Polyline &ply, bool init=true)
 Polygon (Polygon const &other)
Polygonoperator= (Polygon const &rhs)=delete
 ~Polygon () override
bool initialise ()
bool isPntInPolygon (MathLib::Point3d const &pnt) const
bool containsSegment (GeoLib::LineSegment const &segment) const
bool isPolylineInPolygon (const Polyline &ply) const
bool isPartOfPolylineInPolygon (const Polyline &ply) const
bool getNextIntersectionPointPolygonLine (GeoLib::LineSegment const &seg, GeoLib::Point &intersection_pnt, std::size_t &seg_num) const
std::list< Polygon * > const & computeListOfSimplePolygons ()
Public Member Functions inherited from GeoLib::Polyline
 Polyline (const std::vector< Point * > &pnt_vec)
 Polyline (const Polyline &ply)
Polylineoperator= (Polyline const &other)=delete
 ~Polyline () override=default
GEOTYPE getGeoType () const override
 return a geometry type
virtual bool addPoint (std::size_t pnt_id)
virtual bool insertPoint (std::size_t pos, std::size_t pnt_id)
void removePoint (std::size_t pos)
void closePolyline ()
std::size_t getNumberOfPoints () const
std::size_t getNumberOfSegments () const
bool isClosed () const
bool isCoplanar () const
bool isPointIDInPolyline (std::size_t pnt_id) const
std::size_t getPointID (std::size_t const i) const
void setPointID (std::size_t idx, std::size_t id)
const PointgetPoint (std::size_t i) const
 returns the i-th point contained in the polyline
SegmentIterator begin () const
SegmentIterator end () const
std::vector< Point * > const & getPointsVec () const
double getDistanceAlongPolyline (const MathLib::Point3d &pnt, const double epsilon_radius) const
Public Member Functions inherited from GeoLib::GeoObject
virtual ~GeoObject ()=default

Private Member Functions

void ensureCCWOrientation ()
void splitPolygonAtIntersection (const std::list< Polygon * >::const_iterator &polygon_it)
void splitPolygonAtPoint (const std::list< Polygon * >::iterator &polygon_it)

Private Attributes

std::list< Polygon * > _simple_polygon_list
AABB _aabb

Friends

bool operator== (Polygon const &lhs, Polygon const &rhs)

Additional Inherited Members

Static Public Member Functions inherited from GeoLib::Polyline
static PolylineconstructPolylineFromSegments (const std::vector< Polyline * > &ply_vec, double prox=0.0)
Protected Member Functions inherited from GeoLib::Polyline
void reverseOrientation ()
std::vector< std::size_t > const & getPolylinePointIDs () const
Protected Attributes inherited from GeoLib::Polyline
const std::vector< Point * > & _ply_pnts

Constructor & Destructor Documentation

◆ Polygon() [1/2]

GeoLib::Polygon::Polygon ( const Polyline & ply,
bool init = true )
explicit

constructor checks if the given polyline is closed, and assures that the orientation is clock wise.

Parameters
plyclosed Polyline
initif true, check if polyline is closed, calculate bounding box

Definition at line 124 of file Polygon.cpp.

125 : Polyline(ply), _aabb(ply.getPointsVec(), ply.getPolylinePointIDs())
126{
127 if (init)
128 {
129 initialise();
130 }
131 _simple_polygon_list.push_back(this);
132}
std::list< Polygon * > _simple_polygon_list
Definition Polygon.h:96
bool initialise()
Definition Polygon.cpp:160
Polyline(const std::vector< Point * > &pnt_vec)
Definition Polyline.cpp:17

References GeoLib::Polyline::Polyline(), _aabb, _simple_polygon_list, GeoLib::Polyline::getPointsVec(), GeoLib::Polyline::getPolylinePointIDs(), and initialise().

Referenced by Polygon(), GeoLib::PolygonWithSegmentMarker::PolygonWithSegmentMarker(), operator=(), operator==, and splitPolygonAtPoint().

◆ Polygon() [2/2]

GeoLib::Polygon::Polygon ( Polygon const & other)

Definition at line 134 of file Polygon.cpp.

134 : Polyline(other), _aabb(other._aabb)
135{
136 _simple_polygon_list.push_back(this);
137 auto sub_polygon_it(other._simple_polygon_list.begin());
138 for (sub_polygon_it++; // the first entry is the polygon itself, skip the
139 // entry
140 sub_polygon_it != other._simple_polygon_list.end();
141 ++sub_polygon_it)
142 {
143 _simple_polygon_list.emplace_back(new Polygon(*(*sub_polygon_it)));
144 }
145}
friend class Polygon
Definition Polyline.h:79

References Polygon(), GeoLib::Polyline::Polyline(), _aabb, _simple_polygon_list, and GeoLib::Polyline::Polygon.

◆ ~Polygon()

GeoLib::Polygon::~Polygon ( )
override

Definition at line 147 of file Polygon.cpp.

148{
149 // remove polygons from list
150 for (auto& polygon : _simple_polygon_list)
151 {
152 // the first entry of the list can be a pointer the object itself
153 if (polygon != this)
154 {
155 delete polygon;
156 }
157 }
158}

References _simple_polygon_list.

Member Function Documentation

◆ computeListOfSimplePolygons()

std::list< Polygon * > const & GeoLib::Polygon::computeListOfSimplePolygons ( )

Subdivides a self-intersecting polygon into a list of non-intersecting shapes.

Definition at line 682 of file Polygon.cpp.

683{
686
687 for (auto polygon : _simple_polygon_list)
688 {
689 polygon->initialise();
690 }
692}
void splitPolygonAtPoint(const std::list< Polygon * >::iterator &polygon_it)
Definition Polygon.cpp:521
void splitPolygonAtIntersection(const std::list< Polygon * >::const_iterator &polygon_it)
Definition Polygon.cpp:462

References _simple_polygon_list, splitPolygonAtIntersection(), and splitPolygonAtPoint().

◆ containsSegment()

bool GeoLib::Polygon::containsSegment ( GeoLib::LineSegment const & segment) const

Checks if the straight line segment is contained within the polygon.

Parameters
segmentthe straight line segment that is checked with
Returns
true if the straight line segment is within the polygon, else false

Definition at line 250 of file Polygon.cpp.

251{
252 std::vector<GeoLib::Point> s(getAllIntersectionPoints(*this, segment));
253
254 GeoLib::Point const& a{segment.getBeginPoint()};
255 GeoLib::Point const& b{segment.getEndPoint()};
256 // no intersections -> check if at least one point of segment is in polygon
257 if (s.empty())
258 {
259 return (isPntInPolygon(a));
260 }
261
262 const double tol(std::numeric_limits<float>::epsilon());
263
264 // one intersection, intersection in line segment end point
265 if (s.size() == 1)
266 {
267 const double sqr_dist_as(MathLib::sqrDist(a, s[0]));
268 if (sqr_dist_as < tol)
269 {
270 return (isPntInPolygon(b));
271 }
272
273 const double sqr_dist_bs(MathLib::sqrDist(b, s[0]));
274 if (sqr_dist_bs < tol)
275 {
276 return (isPntInPolygon(a));
277 }
278 }
279
280 // Sorting the intersection with respect to the distance to the point a.
281 // This induces a partition of the line segment into sub segments.
282 std::sort(s.begin(), s.end(),
283 [&a](GeoLib::Point const& p0, GeoLib::Point const& p1)
284 { return MathLib::sqrDist(a, p0) < MathLib::sqrDist(a, p1); });
285
286 // remove sub segments with almost zero length
287 for (std::size_t k(0); k < s.size() - 1;)
288 {
289 if (MathLib::sqrDist(s[k], s[k + 1]) < tol)
290 {
291 s.erase(s.begin() + k + 1);
292 }
293 else
294 {
295 k++;
296 }
297 }
298
299 // Check if all sub segments are within the polygon.
300 if (!isPntInPolygon(GeoLib::Point(0.5 * (a[0] + s[0][0]),
301 0.5 * (a[1] + s[0][1]),
302 0.5 * (a[2] + s[0][2]))))
303 {
304 return false;
305 }
306 const std::size_t n_sub_segs(s.size() - 1);
307 for (std::size_t k(0); k < n_sub_segs; k++)
308 {
309 if (!isPntInPolygon(GeoLib::Point(0.5 * (s[k][0] + s[k + 1][0]),
310 0.5 * (s[k][1] + s[k + 1][1]),
311 0.5 * (s[k][2] + s[k + 1][2]))))
312 {
313 return false;
314 }
315 }
316 return isPntInPolygon(GeoLib::Point(0.5 * (s[0][0] + b[0]),
317 0.5 * (s[0][1] + b[1]),
318 0.5 * (s[0][2] + b[2])));
319}
bool isPntInPolygon(MathLib::Point3d const &pnt) const
Definition Polygon.cpp:194
std::vector< GeoLib::Point > getAllIntersectionPoints(Polygon const &polygon, GeoLib::LineSegment const &segment)
Definition Polygon.cpp:178
double sqrDist(MathLib::Point3d const &p0, MathLib::Point3d const &p1)
Definition Point3d.cpp:19

References GeoLib::getAllIntersectionPoints(), GeoLib::LineSegment::getBeginPoint(), GeoLib::LineSegment::getEndPoint(), isPntInPolygon(), and MathLib::sqrDist().

◆ ensureCCWOrientation()

void GeoLib::Polygon::ensureCCWOrientation ( )
private

Definition at line 388 of file Polygon.cpp.

389{
390 // *** pre processing: rotate points to xy-plan
391 // *** copy points to vector - last point is identical to the first
392 std::size_t n_pnts(this->getNumberOfPoints() - 1);
393 std::vector<GeoLib::Point*> tmp_polygon_pnts;
394 for (std::size_t k(0); k < n_pnts; k++)
395 {
396 tmp_polygon_pnts.push_back(new GeoLib::Point(*(this->getPoint(k))));
397 }
398
399 // rotate copied points into x-y-plane
400 GeoLib::rotatePointsToXY(tmp_polygon_pnts);
401
402 for (auto& tmp_polygon_pnt : tmp_polygon_pnts)
403 {
404 (*tmp_polygon_pnt)[2] =
405 0.0; // should be -= d but there are numerical errors
406 }
407
408 // *** get the left most upper point
409 std::size_t min_x_max_y_idx(0); // for orientation check
410 for (std::size_t k(0); k < n_pnts; k++)
411 {
412 if ((*(tmp_polygon_pnts[k]))[0] <=
413 (*(tmp_polygon_pnts[min_x_max_y_idx]))[0])
414 {
415 if ((*(tmp_polygon_pnts[k]))[0] <
416 (*(tmp_polygon_pnts[min_x_max_y_idx]))[0])
417 {
418 min_x_max_y_idx = k;
419 }
420 else if ((*(tmp_polygon_pnts[k]))[1] >
421 (*(tmp_polygon_pnts[min_x_max_y_idx]))[1])
422 {
423 min_x_max_y_idx = k;
424 }
425 }
426 }
427 // *** determine orientation
428 GeoLib::Orientation orient;
429 if (0 < min_x_max_y_idx && min_x_max_y_idx < n_pnts - 2)
430 {
431 orient = GeoLib::getOrientation(*tmp_polygon_pnts[min_x_max_y_idx - 1],
432 *tmp_polygon_pnts[min_x_max_y_idx],
433 *tmp_polygon_pnts[min_x_max_y_idx + 1]);
434 }
435 else
436 {
437 if (0 == min_x_max_y_idx)
438 {
439 orient = GeoLib::getOrientation(*tmp_polygon_pnts[n_pnts - 1],
440 *tmp_polygon_pnts[0],
441 *tmp_polygon_pnts[1]);
442 }
443 else
444 {
445 orient = GeoLib::getOrientation(*tmp_polygon_pnts[n_pnts - 2],
446 *tmp_polygon_pnts[n_pnts - 1],
447 *tmp_polygon_pnts[0]);
448 }
449 }
450
451 if (orient != GeoLib::CCW)
452 {
454 }
455
456 for (std::size_t k(0); k < n_pnts; k++)
457 {
458 delete tmp_polygon_pnts[k];
459 }
460}
std::size_t getNumberOfPoints() const
Definition Polyline.cpp:98
const Point * getPoint(std::size_t i) const
returns the i-th point contained in the polyline
Definition Polyline.cpp:168
void reverseOrientation()
Definition Polyline.cpp:345
Eigen::Matrix3d rotatePointsToXY(InputIterator1 p_pnts_begin, InputIterator1 p_pnts_end, InputIterator2 r_pnts_begin, InputIterator2 r_pnts_end)
Orientation getOrientation(MathLib::Point3d const &p0, MathLib::Point3d const &p1, MathLib::Point3d const &p2)

References GeoLib::CCW, GeoLib::Polyline::getNumberOfPoints(), GeoLib::getOrientation(), GeoLib::Polyline::getPoint(), GeoLib::Polyline::reverseOrientation(), and GeoLib::rotatePointsToXY().

Referenced by initialise().

◆ getNextIntersectionPointPolygonLine()

bool GeoLib::Polygon::getNextIntersectionPointPolygonLine ( GeoLib::LineSegment const & seg,
GeoLib::Point & intersection_pnt,
std::size_t & seg_num ) const

Calculates the next intersection point between the line segment seg and the polygon starting with segment seg_num.

Parameters
seg(input) Line segment to compute intersection.
intersection_pnt(output) next intersection point
seg_num(in/out) the number of the polygon segment that is intersecting
Returns
true, if there was an intersection, i.e., the intersection_pnt and seg_num contains new valid values

Definition at line 354 of file Polygon.cpp.

357{
358 if (_simple_polygon_list.size() == 1)
359 {
360 for (auto seg_it(begin() + seg_num); seg_it != end(); ++seg_it)
361 {
362 if (GeoLib::lineSegmentIntersect(*seg_it, seg, intersection_pnt))
363 {
364 seg_num = seg_it.getSegmentNumber();
365 return true;
366 }
367 }
368 }
369 else
370 {
371 for (auto const* polygon : _simple_polygon_list)
372 {
373 for (auto seg_it(polygon->begin()); seg_it != polygon->end();
374 ++seg_it)
375 {
376 if (GeoLib::lineSegmentIntersect(*seg_it, seg,
377 intersection_pnt))
378 {
379 seg_num = seg_it.getSegmentNumber();
380 return true;
381 }
382 }
383 }
384 }
385 return false;
386}
SegmentIterator begin() const
Definition Polyline.h:177
SegmentIterator end() const
Definition Polyline.h:179
bool lineSegmentIntersect(GeoLib::LineSegment const &s0, GeoLib::LineSegment const &s1, GeoLib::Point &s)

References _simple_polygon_list, GeoLib::Polyline::begin(), GeoLib::Polyline::end(), and GeoLib::lineSegmentIntersect().

◆ initialise()

bool GeoLib::Polygon::initialise ( )

Definition at line 160 of file Polygon.cpp.

161{
162 if (this->isClosed())
163 {
165 return true;
166 }
167 WARN("Polygon::initialise(): base polyline is not closed.");
168 return false;
169}
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:34
void ensureCCWOrientation()
Definition Polygon.cpp:388
bool isClosed() const
Definition Polyline.cpp:108

References ensureCCWOrientation(), GeoLib::Polyline::isClosed(), and WARN().

Referenced by Polygon().

◆ isPartOfPolylineInPolygon()

bool GeoLib::Polygon::isPartOfPolylineInPolygon ( const Polyline & ply) const

Method checks first if at least one (end!) point of a line segment of the polyline is inside of the polygon. If this test fails each line segment of the polyline will be tested against each polygon segment for intersection.

Parameters
plythe polyline that should be checked
Returns
true if a part of the polyline is within the polygon

Definition at line 328 of file Polygon.cpp.

329{
330 const std::size_t ply_size(ply.getNumberOfPoints());
331 // check points
332 for (std::size_t k(0); k < ply_size; k++)
333 {
334 if (isPntInPolygon(*(ply.getPoint(k))))
335 {
336 return true;
337 }
338 }
339
340 auto polygon_segment_intersects_line = [&](auto const& polygon_seg)
341 {
342 GeoLib::Point s;
343 return std::any_of(ply.begin(), ply.end(),
344 [&polygon_seg, &s](auto const& polyline_seg) {
345 return GeoLib::lineSegmentIntersect(
346 polyline_seg, polygon_seg, s);
347 });
348 };
349
350 return std::any_of(std::cbegin(*this), std::cend(*this),
351 polygon_segment_intersects_line);
352}

References GeoLib::Polyline::Polyline(), GeoLib::Polyline::begin(), GeoLib::Polyline::end(), GeoLib::Polyline::getNumberOfPoints(), GeoLib::Polyline::getPoint(), and isPntInPolygon().

◆ isPntInPolygon()

bool GeoLib::Polygon::isPntInPolygon ( MathLib::Point3d const & pnt) const

Method checks if the given point is inside the polygon. The method requires that the polygon has clock wise orientation.

Parameters
pntthe Point
Returns
if point is inside the polygon true, else false

Definition at line 194 of file Polygon.cpp.

195{
196 auto const [min_aabb_pnt, max_aabb_pnt] = _aabb.getMinMaxPoints();
197
198 if (pnt[0] < min_aabb_pnt[0] || max_aabb_pnt[0] < pnt[0] ||
199 pnt[1] < min_aabb_pnt[1] || max_aabb_pnt[1] < pnt[1])
200 {
201 return false;
202 }
203
204 if (_simple_polygon_list.size() == 1)
205 {
206 std::size_t n_intersections(0);
207 const std::size_t n_nodes(getNumberOfPoints() - 1);
208 for (std::size_t k(0); k < n_nodes; k++)
209 {
210 if (((*(getPoint(k)))[1] <= pnt[1] &&
211 pnt[1] <= (*(getPoint(k + 1)))[1]) ||
212 ((*(getPoint(k + 1)))[1] <= pnt[1] &&
213 pnt[1] <= (*(getPoint(k)))[1]))
214 {
215 switch (getEdgeType(*getPoint(k), *getPoint(k + 1), pnt))
216 {
218 return true;
220 n_intersections++;
221 break;
223 break;
224 default:
225 // do nothing
226 ;
227 }
228 }
229 }
230 if (n_intersections % 2 == 1)
231 {
232 return true;
233 }
234 }
235 else
236 {
237 for (auto it(_simple_polygon_list.begin()++);
238 it != _simple_polygon_list.end();
239 ++it)
240 {
241 if ((*it)->isPntInPolygon(pnt))
242 {
243 return true;
244 }
245 }
246 }
247 return false;
248}
EdgeType getEdgeType(MathLib::Point3d const &a, MathLib::Point3d const &b, MathLib::Point3d const &pnt)
Definition Polygon.cpp:91
@ INESSENTIAL
INESSENTIAL.
Definition Polygon.cpp:31
@ CROSSING
CROSSING.
Definition Polygon.cpp:30
@ TOUCHING
TOUCHING.
Definition Polygon.cpp:29

References _aabb, _simple_polygon_list, GeoLib::CROSSING, GeoLib::getEdgeType(), GeoLib::Polyline::getNumberOfPoints(), GeoLib::Polyline::getPoint(), GeoLib::INESSENTIAL, and GeoLib::TOUCHING.

Referenced by containsSegment(), isPartOfPolylineInPolygon(), main(), MeshGeoToolsLib::markNodesOutSideOfPolygon(), and FileIO::FEFLOWMeshInterface::setMaterialIDs().

◆ isPolylineInPolygon()

bool GeoLib::Polygon::isPolylineInPolygon ( const Polyline & ply) const

Method checks if all points of the polyline ply are inside of the polygon.

Parameters
plythe polyline that should be checked

Definition at line 321 of file Polygon.cpp.

322{
323 return std::all_of(ply.begin(), ply.end(),
324 [this](auto const& segment)
325 { return containsSegment(segment); });
326}

References GeoLib::Polyline::Polyline(), GeoLib::Polyline::begin(), and GeoLib::Polyline::end().

◆ operator=()

Polygon & GeoLib::Polygon::operator= ( Polygon const & rhs)
delete

◆ splitPolygonAtIntersection()

void GeoLib::Polygon::splitPolygonAtIntersection ( const std::list< Polygon * >::const_iterator & polygon_it)
private

Definition at line 462 of file Polygon.cpp.

464{
465 GeoLib::Polyline::SegmentIterator seg_it0((*polygon_it)->begin());
466 GeoLib::Polyline::SegmentIterator seg_it1((*polygon_it)->begin());
467 GeoLib::Point intersection_pnt;
468 if (!GeoLib::lineSegmentsIntersect(*polygon_it, seg_it0, seg_it1,
469 intersection_pnt))
470 {
471 return;
472 }
473
474 std::size_t idx0(seg_it0.getSegmentNumber());
475 std::size_t idx1(seg_it1.getSegmentNumber());
476 // adding intersection point to pnt_vec
477 std::size_t const intersection_pnt_id(_ply_pnts.size());
478 const_cast<std::vector<Point*>&>(_ply_pnts).push_back(
479 new GeoLib::Point(intersection_pnt));
480
481 // split Polygon
482 if (idx0 > idx1)
483 {
484 std::swap(idx0, idx1);
485 }
486
487 GeoLib::Polyline polyline0{(*polygon_it)->getPointsVec()};
488 for (std::size_t k(0); k <= idx0; k++)
489 {
490 polyline0.addPoint((*polygon_it)->getPointID(k));
491 }
492 polyline0.addPoint(intersection_pnt_id);
493 for (std::size_t k(idx1 + 1); k < (*polygon_it)->getNumberOfPoints(); k++)
494 {
495 polyline0.addPoint((*polygon_it)->getPointID(k));
496 }
497
498 GeoLib::Polyline polyline1{(*polygon_it)->getPointsVec()};
499 polyline1.addPoint(intersection_pnt_id);
500 for (std::size_t k(idx0 + 1); k <= idx1; k++)
501 {
502 polyline1.addPoint((*polygon_it)->getPointID(k));
503 }
504 polyline1.addPoint(intersection_pnt_id);
505
506 // remove the polygon except the first
507 if (*polygon_it != this)
508 {
509 delete *polygon_it;
510 }
511 // erase polygon_it and add two new polylines
512 auto polygon1_it = _simple_polygon_list.insert(
513 _simple_polygon_list.erase(polygon_it), new GeoLib::Polygon(polyline1));
514 auto polygon0_it = _simple_polygon_list.insert(
515 polygon1_it, new GeoLib::Polygon(polyline0));
516
517 splitPolygonAtIntersection(polygon0_it);
518 splitPolygonAtIntersection(polygon1_it);
519}
virtual bool addPoint(std::size_t pnt_id)
Definition Polyline.cpp:24
const std::vector< Point * > & _ply_pnts
Definition Polyline.h:200
bool lineSegmentsIntersect(const GeoLib::Polyline *ply, GeoLib::Polyline::SegmentIterator &seg_it0, GeoLib::Polyline::SegmentIterator &seg_it1, GeoLib::Point &intersection_pnt)

References GeoLib::Polyline::_ply_pnts, _simple_polygon_list, GeoLib::Polyline::addPoint(), GeoLib::Polyline::SegmentIterator::getSegmentNumber(), GeoLib::lineSegmentsIntersect(), and splitPolygonAtIntersection().

Referenced by computeListOfSimplePolygons(), and splitPolygonAtIntersection().

◆ splitPolygonAtPoint()

void GeoLib::Polygon::splitPolygonAtPoint ( const std::list< Polygon * >::iterator & polygon_it)
private

Definition at line 521 of file Polygon.cpp.

523{
524 std::size_t const n((*polygon_it)->getNumberOfPoints() - 1);
525 std::vector<std::size_t> id_vec(n);
526 std::vector<std::size_t> perm(n);
527 for (std::size_t k(0); k < n; k++)
528 {
529 id_vec[k] = (*polygon_it)->getPointID(k);
530 perm[k] = k;
531 }
532
533 BaseLib::quicksort(id_vec, 0, n, perm);
534
535 for (std::size_t k(0); k < n - 1; k++)
536 {
537 if (id_vec[k] == id_vec[k + 1])
538 {
539 std::size_t idx0 = perm[k];
540 std::size_t idx1 = perm[k + 1];
541
542 if (idx0 > idx1)
543 {
544 std::swap(idx0, idx1);
545 }
546
547 // create two closed polylines
548 GeoLib::Polyline polyline0{*(*polygon_it)};
549 for (std::size_t j(0); j <= idx0; j++)
550 {
551 polyline0.addPoint((*polygon_it)->getPointID(j));
552 }
553 for (std::size_t j(idx1 + 1);
554 j < (*polygon_it)->getNumberOfPoints();
555 j++)
556 {
557 polyline0.addPoint((*polygon_it)->getPointID(j));
558 }
559
560 GeoLib::Polyline polyline1{*(*polygon_it)};
561 for (std::size_t j(idx0); j <= idx1; j++)
562 {
563 polyline1.addPoint((*polygon_it)->getPointID(j));
564 }
565
566 // remove the polygon except the first
567 if (*polygon_it != this)
568 {
569 delete *polygon_it;
570 }
571 // erase polygon_it and add two new polygons
572 auto polygon1_it = _simple_polygon_list.insert(
573 _simple_polygon_list.erase(polygon_it), new Polygon(polyline1));
574 auto polygon0_it = _simple_polygon_list.insert(
575 polygon1_it, new Polygon(polyline0));
576
577 splitPolygonAtPoint(polygon0_it);
578 splitPolygonAtPoint(polygon1_it);
579
580 return;
581 }
582 }
583}
Polygon(const Polyline &ply, bool init=true)
Definition Polygon.cpp:124
void quicksort(It1 first1, It1 last1, It2 first2, Comparator compare)
Definition quicksort.h:17

References Polygon(), _simple_polygon_list, GeoLib::Polyline::addPoint(), GeoLib::Polyline::Polygon, BaseLib::quicksort(), and splitPolygonAtPoint().

Referenced by computeListOfSimplePolygons(), and splitPolygonAtPoint().

◆ operator==

bool operator== ( Polygon const & lhs,
Polygon const & rhs )
friend

comparison operator for polygons

Parameters
lhsthe first polygon
rhsthe second polygon
Returns
true, if the polygons describe the same geometrical object

Definition at line 585 of file Polygon.cpp.

586{
587 if (lhs.getNumberOfPoints() != rhs.getNumberOfPoints())
588 {
589 return false;
590 }
591
592 const std::size_t n(lhs.getNumberOfPoints());
593 const std::size_t start_pnt(lhs.getPointID(0));
594
595 // search start point of first polygon in second polygon
596 bool nfound(true);
597 std::size_t k(0);
598 for (; k < n - 1 && nfound; k++)
599 {
600 if (start_pnt == rhs.getPointID(k))
601 {
602 nfound = false;
603 break;
604 }
605 }
606
607 // case: start point not found in second polygon
608 if (nfound)
609 {
610 return false;
611 }
612
613 // *** determine direction
614 // opposite direction
615 if (k == n - 2)
616 {
617 for (k = 1; k < n - 1; k++)
618 {
619 if (lhs.getPointID(k) != rhs.getPointID(n - 1 - k))
620 {
621 return false;
622 }
623 }
624 return true;
625 }
626
627 // same direction - start point of first polygon at arbitrary position in
628 // second polygon
629 if (lhs.getPointID(1) == rhs.getPointID(k + 1))
630 {
631 std::size_t j(k + 2);
632 for (; j < n - 1; j++)
633 {
634 if (lhs.getPointID(j - k) != rhs.getPointID(j))
635 {
636 return false;
637 }
638 }
639 j = 0; // new start point at second polygon
640 for (; j < k + 1; j++)
641 {
642 if (lhs.getPointID(n - (k + 2) + j + 1) != rhs.getPointID(j))
643 {
644 return false;
645 }
646 }
647 return true;
648 }
649 // opposite direction with start point of first polygon at arbitrary
650 // position
651 // *** ATTENTION
652 WARN(
653 "operator==(Polygon const& lhs, Polygon const& rhs) - not tested case "
654 "(implementation is probably buggy) - please contact "
655 "thomas.fischer@ufz.de mentioning the problem.");
656 // in second polygon
657 if (lhs.getPointID(1) == rhs.getPointID(k - 1))
658 {
659 std::size_t j(k - 2);
660 for (; j > 0; j--)
661 {
662 if (lhs.getPointID(k - 2 - j) != rhs.getPointID(j))
663 {
664 return false;
665 }
666 }
667 // new start point at second polygon - the point n-1 of a polygon is
668 // equal to the first point of the polygon (for this reason: n-2)
669 j = n - 2;
670 for (; j > k - 1; j--)
671 {
672 if (lhs.getPointID(n - 2 + j + k - 2) != rhs.getPointID(j))
673 {
674 return false;
675 }
676 }
677 return true;
678 }
679 return false;
680}

References Polygon(), GeoLib::Polyline::getNumberOfPoints(), GeoLib::Polyline::getPointID(), and WARN().

Member Data Documentation

◆ _aabb

AABB GeoLib::Polygon::_aabb
private

Definition at line 97 of file Polygon.h.

Referenced by Polygon(), Polygon(), and isPntInPolygon().

◆ _simple_polygon_list

std::list<Polygon*> GeoLib::Polygon::_simple_polygon_list
private

The documentation for this class was generated from the following files: