From b9487cc07abbe554084c605db3d8b83bb20acd2e Mon Sep 17 00:00:00 2001 From: Matthias Hochsteger Date: Thu, 20 Aug 2020 18:26:25 +0200 Subject: [PATCH] Rename Polygon2d to Loop --- libsrc/geom2d/csg2d.cpp | 54 ++++++++++++++++----------------- libsrc/geom2d/csg2d.hpp | 12 ++++---- libsrc/geom2d/python_geom2d.cpp | 9 ------ python/geom2d.py | 2 +- 4 files changed, 34 insertions(+), 43 deletions(-) diff --git a/libsrc/geom2d/csg2d.cpp b/libsrc/geom2d/csg2d.cpp index b495d902..5430224b 100644 --- a/libsrc/geom2d/csg2d.cpp +++ b/libsrc/geom2d/csg2d.cpp @@ -628,9 +628,9 @@ void ComputeIntersections(Solid2d & sp, Solid2d & sq) auto & PP = sp.polys; auto & QQ = sq.polys; - for (Polygon2d& P : PP) + for (Loop& P : PP) for (Edge edgeP : P.Edges(SOURCE)) - for (Polygon2d& Q : QQ) + for (Loop& Q : QQ) for (Edge edgeQ : Q.Edges(SOURCE)) { double alpha = 0.0; @@ -688,10 +688,10 @@ void ComputeIntersections(Solid2d & sp, Solid2d & sq) } while(!curr->is_source); }; - for (Polygon2d& P : PP) + for (Loop& P : PP) for (Vertex* v : P.Vertices(SOURCE)) split_spline_at_vertex(v); - for (Polygon2d& Q : QQ) + for (Loop& Q : QQ) for (Vertex* v : Q.Vertices(SOURCE)) split_spline_at_vertex(v); } @@ -770,7 +770,7 @@ void LabelIntersections(Solid2d & sp, Solid2d & sq, Solid2d & sr, bool UNION) auto & RR = sr.polys; // 1) initial classification - for (Polygon2d& P : PP) + for (Loop& P : PP) for (Vertex* I : P.Vertices(INTERSECTION)) { @@ -818,7 +818,7 @@ void LabelIntersections(Solid2d & sp, Solid2d & sq, Solid2d & sr, bool UNION) } // 2) classify intersection chains - for (Polygon2d& P : PP) + for (Loop& P : PP) for (Vertex* I : P.Vertices(INTERSECTION)) { @@ -862,19 +862,19 @@ void LabelIntersections(Solid2d & sp, Solid2d & sq, Solid2d & sr, bool UNION) // 3) copy labels from P to Q // loop over intersection vertices of P - for (Polygon2d& P : PP) + for (Loop& P : PP) for (Vertex* I : P.Vertices(INTERSECTION)) I->neighbour->label = I->label; // 3.5) check for special cases - set noIntersection[2]; - set identical[2]; + set noIntersection[2]; + set identical[2]; for (int i=0; i<2; ++i) { - Array* P_or_Q = &PP; // if i=0, then do it for P w.r.t. Q - Array* Q_or_P = &QQ; + Array* P_or_Q = &PP; // if i=0, then do it for P w.r.t. Q + Array* Q_or_P = &QQ; if (i==1) { // if i=1, then do it for Q w.r.t. P P_or_Q = &QQ; @@ -882,7 +882,7 @@ void LabelIntersections(Solid2d & sp, Solid2d & sq, Solid2d & sr, bool UNION) } // loop over all components of P (or Q) - for (Polygon2d& P : *P_or_Q) + for (Loop& P : *P_or_Q) if (P.noCrossingVertex(UNION)) { // P_ has no crossing vertex (but may have bounces or delayed bounces, except for UNION), @@ -899,7 +899,7 @@ void LabelIntersections(Solid2d & sp, Solid2d & sq, Solid2d & sr, bool UNION) // is P inside Q_or_P? bool isInside = false; auto p = P.getNonIntersectionPoint(); - for (Polygon2d& Q : *Q_or_P) + for (Loop& Q : *Q_or_P) if ( Q.IsInside(p) ) isInside = !isInside; if (isInside ^ UNION) @@ -909,20 +909,20 @@ void LabelIntersections(Solid2d & sp, Solid2d & sq, Solid2d & sr, bool UNION) } // handle components of P that are identical to some component of Q - for (Polygon2d* P : identical[0]) + for (Loop* P : identical[0]) { // is P a hole? bool P_isHole = false; - for (Polygon2d& P_ : PP) + for (Loop& P_ : PP) if ( ( P_.first.get() != P->first.get() ) && (P_.IsInside(*P->first)) ) P_isHole = !P_isHole; - for (Polygon2d* Q : identical[1]) + for (Loop* Q : identical[1]) for (Vertex* V : Q->Vertices(ALL)) if (V == P->first->neighbour) { // found Q that matches P // is Q a hole? bool Q_isHole = false; - for (Polygon2d& Q_ : QQ) + for (Loop& Q_ : QQ) if ( ( Q_.first.get() != Q->first.get() ) && (Q_.IsInside(*Q->first)) ) Q_isHole = !Q_isHole; @@ -940,8 +940,8 @@ next_P: ; for (int i=0; i<2; ++i) { - Array* P_or_Q = &PP; // if i=0, then do it for P w.r.t. Q - Array* Q_or_P = &QQ; + Array* P_or_Q = &PP; // if i=0, then do it for P w.r.t. Q + Array* Q_or_P = &QQ; if (i==1) { // if i=1, then do it for Q w.r.t. P P_or_Q = &QQ; @@ -949,7 +949,7 @@ next_P: ; } // loop over all components of P (or Q) - for (Polygon2d& P : *P_or_Q) + for (Loop& P : *P_or_Q) { // ignore P if it does not intersect with Q_or_P (detected in step 3.5 above) @@ -962,7 +962,7 @@ next_P: ; // check if it is inside or outside Q (or P) // and set ENTRY/EXIT status accordingly EntryExitLabel status = ENTRY; - for (Polygon2d& Q : *Q_or_P) + for (Loop& Q : *Q_or_P) if (Q.IsInside(*V)) ToggleLabel(status); @@ -1122,11 +1122,11 @@ void CreateResult(Solid2d & sp, Solid2d & sr, bool UNION) // so that they cannot serve as start vertex of another component // - for (Polygon2d& P : PP) + for (Loop& P : PP) { for (Vertex* I : P.Vertices(CROSSING_INTERSECTION)) { - Polygon2d R; // result polygon component + Loop R; // result polygon component Vertex* V = I; // start traversal at I V->is_intersection = false; // mark visited vertices @@ -1179,7 +1179,7 @@ void CreateResult(Solid2d & sp, Solid2d & sr, bool UNION) void CleanUpResult(Solid2d & sr) { auto & RR = sr.polys; - for (Polygon2d& R : RR) + for (Loop& R : RR) { while ( (R.first.get() != NULL) && (fabs(Area(*R.first->prev,*R.first,*R.first->next)) < EPSILON) ) R.Remove(R.first.get()); @@ -1211,9 +1211,9 @@ void RemoveDuplicates(Solid2d & sr) } } -Polygon2d RectanglePoly(double x0, double x1, double y0, double y1, string bc) +Loop RectanglePoly(double x0, double x1, double y0, double y1, string bc) { - Polygon2d r; + Loop r; r.Append( {x0, y0} ); r.Append( {x1, y0} ); r.Append( {x1, y1} ); @@ -1235,7 +1235,7 @@ Solid2d Circle(double x, double y, double r, string name, string bc) { Solid2d s; s.name = name; - Polygon2d poly; + Loop poly; Point<2> ps[] = { diff --git a/libsrc/geom2d/csg2d.hpp b/libsrc/geom2d/csg2d.hpp index 210c3d81..abf0b128 100644 --- a/libsrc/geom2d/csg2d.hpp +++ b/libsrc/geom2d/csg2d.hpp @@ -356,20 +356,20 @@ inline int CalcSide( const Point<2> & p0, const Point<2> & p1, const Point<2> & return 0; } -struct Polygon2d +struct Loop { unique_ptr first = nullptr; - Polygon2d() = default; + Loop() = default; - Polygon2d(const Polygon2d & p) + Loop(const Loop & p) : first(nullptr) { for(auto v : p.Vertices(ALL)) AppendVertex(*v); } - Polygon2d & operator=(const Polygon2d & p) + Loop & operator=(const Loop & p) { first = nullptr; if(p.first) @@ -532,7 +532,7 @@ struct Polygon2d struct Solid2d { - Array polys; + Array polys; string name = ""; @@ -543,7 +543,7 @@ struct Solid2d Solid2d operator*(Solid2d & other); Solid2d operator-(Solid2d other); - void Append( const Polygon2d & poly ) + void Append( const Loop & poly ) { polys.Append(poly); } diff --git a/libsrc/geom2d/python_geom2d.cpp b/libsrc/geom2d/python_geom2d.cpp index 1875f6ba..f613fa46 100644 --- a/libsrc/geom2d/python_geom2d.cpp +++ b/libsrc/geom2d/python_geom2d.cpp @@ -408,15 +408,6 @@ DLL_HEADER void ExportGeom2d(py::module &m) .def("SetBC", &Solid2d::SetBC) ; - py::class_(m, "Polygon2d") - .def(py::init<>()) - .def("SetBC", &Polygon2d::SetBC) - .def("Append", [](Polygon2d & self, double x, double y) - { - self.Append({x,y}); - }) - ; - m.def("Rectangle", [](double x0, double x1, double y0, double y1, string bc, string mat) { return Rectangle(x0,x1,y0,y1,bc,mat); }, diff --git a/python/geom2d.py b/python/geom2d.py index 96152cc2..c3336e76 100644 --- a/python/geom2d.py +++ b/python/geom2d.py @@ -1,4 +1,4 @@ -from .libngpy._geom2d import SplineGeometry, Solid2d, Polygon2d, CSG2d, Rectangle, Circle +from .libngpy._geom2d import SplineGeometry, Solid2d, CSG2d, Rectangle, Circle from .meshing import meshsize unit_square = SplineGeometry()