From c3aeae86616e7889fe006b79acb78eb3b3f000b2 Mon Sep 17 00:00:00 2001 From: Richard Brice <37087370+RickBrice@users.noreply.github.com> Date: Fri, 29 Sep 2023 13:27:23 -0700 Subject: [PATCH] Implements recommendation to use map_impl(IfcPolyline*) --- src/ifcgeom/mapping/IfcCurveSegment.cpp | 27 ++++++++++--------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/src/ifcgeom/mapping/IfcCurveSegment.cpp b/src/ifcgeom/mapping/IfcCurveSegment.cpp index 397ac5d2a3..ddc7f969b0 100644 --- a/src/ifcgeom/mapping/IfcCurveSegment.cpp +++ b/src/ifcgeom/mapping/IfcCurveSegment.cpp @@ -261,6 +261,8 @@ public: void operator()(IfcSchema::IfcPolyline* pl) { + auto points = taxonomy::cast(mapping_->map_impl(pl)); + struct Range { double u_start; @@ -271,29 +273,23 @@ public: using Function = std::function(double u)>; std::map fns; - auto p = pl->Points(); - if (p->size() < 2) - { - throw std::runtime_error("invalid polyline - must have at least 2 points"); // this should never happen, but just in case it does - } - auto std_compare = [](double u_start, double u, double u_end) {return u_start <= u && u < u_end; }; auto end_compare = [](double u_start, double u, double u_end) {return u_start <= u && u <= (u_end+0.001); }; - auto iter = p->begin(); - auto end = p->end(); + auto iter = points->children.begin(); + auto end = points->children.end(); auto last = std::prev(end); - auto p1 = *(iter++); auto u = 0.0; for (; iter != end; iter++) { - auto p2 = *iter; + auto edge(*iter); + auto& start_point = boost::get(edge->start); + auto p1x = start_point->components_->x(); + auto p1y = start_point->components_->y(); - auto p1x = p1->Coordinates()[0]; - auto p1y = p1->Coordinates()[1]; - - auto p2x = p2->Coordinates()[0]; - auto p2y = p2->Coordinates()[1]; + auto& end_point = boost::get(edge->end); + auto p2x = end_point->components_->x(); + auto p2y = end_point->components_->y(); auto dx = p2x - p1x; auto dy = p2y - p1y; @@ -311,7 +307,6 @@ public: fns.insert(std::make_pair(Range{ u, u + l,iter == last ? end_compare : std_compare }, fn)); - p1 = p2; u = u + l; }