From b5abae7c15eb9416ada1622480093c5ee9b62c72 Mon Sep 17 00:00:00 2001 From: Giemsa Date: Tue, 21 Jan 2014 21:38:22 +0900 Subject: [PATCH] modify definitions(for more high performance and safety) --- poly2tri/common/shapes.cc | 30 ++++----- poly2tri/common/shapes.h | 60 ++++++++--------- poly2tri/common/utils.h | 4 +- poly2tri/sweep/advancing_front.cc | 4 +- poly2tri/sweep/advancing_front.h | 4 +- poly2tri/sweep/cdt.cc | 8 +-- poly2tri/sweep/cdt.h | 8 +-- poly2tri/sweep/sweep.cc | 105 +++++++++++++++--------------- poly2tri/sweep/sweep.h | 16 ++--- poly2tri/sweep/sweep_context.cc | 12 ++-- poly2tri/sweep/sweep_context.h | 28 ++++---- 11 files changed, 138 insertions(+), 141 deletions(-) diff --git a/poly2tri/common/shapes.cc b/poly2tri/common/shapes.cc index 50c1043..770983f 100644 --- a/poly2tri/common/shapes.cc +++ b/poly2tri/common/shapes.cc @@ -88,7 +88,7 @@ void Triangle::Clear() points_[0]=points_[1]=points_[2] = NULL; } -void Triangle::ClearNeighbor(Triangle *triangle ) +void Triangle::ClearNeighbor(const Triangle *triangle ) { if( neighbors_[0] == triangle ) { @@ -116,7 +116,7 @@ void Triangle::ClearDelunayEdges() delaunay_edge[0] = delaunay_edge[1] = delaunay_edge[2] = false; } -Point* Triangle::OppositePoint(Triangle& t, Point& p) +Point* Triangle::OppositePoint(Triangle& t, const Point& p) { Point *cw = t.PointCW(p); return PointCW(*cw); @@ -210,7 +210,7 @@ void Triangle::MarkConstrainedEdge(Point* p, Point* q) } // The point counter-clockwise to given point -Point* Triangle::PointCW(Point& point) +Point* Triangle::PointCW(const Point& point) { if (&point == points_[0]) { return points_[2]; @@ -224,7 +224,7 @@ Point* Triangle::PointCW(Point& point) } // The point counter-clockwise to given point -Point* Triangle::PointCCW(Point& point) +Point* Triangle::PointCCW(const Point& point) { if (&point == points_[0]) { return points_[1]; @@ -238,7 +238,7 @@ Point* Triangle::PointCCW(Point& point) } // The neighbor clockwise to given point -Triangle* Triangle::NeighborCW(Point& point) +Triangle* Triangle::NeighborCW(const Point& point) { if (&point == points_[0]) { return neighbors_[1]; @@ -249,7 +249,7 @@ Triangle* Triangle::NeighborCW(Point& point) } // The neighbor counter-clockwise to given point -Triangle* Triangle::NeighborCCW(Point& point) +Triangle* Triangle::NeighborCCW(const Point& point) { if (&point == points_[0]) { return neighbors_[2]; @@ -259,7 +259,7 @@ Triangle* Triangle::NeighborCCW(Point& point) return neighbors_[1]; } -bool Triangle::GetConstrainedEdgeCCW(Point& p) +bool Triangle::GetConstrainedEdgeCCW(const Point& p) { if (&p == points_[0]) { return constrained_edge[2]; @@ -269,7 +269,7 @@ bool Triangle::GetConstrainedEdgeCCW(Point& p) return constrained_edge[1]; } -bool Triangle::GetConstrainedEdgeCW(Point& p) +bool Triangle::GetConstrainedEdgeCW(const Point& p) { if (&p == points_[0]) { return constrained_edge[1]; @@ -279,7 +279,7 @@ bool Triangle::GetConstrainedEdgeCW(Point& p) return constrained_edge[0]; } -void Triangle::SetConstrainedEdgeCCW(Point& p, bool ce) +void Triangle::SetConstrainedEdgeCCW(const Point& p, const bool ce) { if (&p == points_[0]) { constrained_edge[2] = ce; @@ -290,7 +290,7 @@ void Triangle::SetConstrainedEdgeCCW(Point& p, bool ce) } } -void Triangle::SetConstrainedEdgeCW(Point& p, bool ce) +void Triangle::SetConstrainedEdgeCW(const Point& p, const bool ce) { if (&p == points_[0]) { constrained_edge[1] = ce; @@ -301,7 +301,7 @@ void Triangle::SetConstrainedEdgeCW(Point& p, bool ce) } } -bool Triangle::GetDelunayEdgeCCW(Point& p) +bool Triangle::GetDelunayEdgeCCW(const Point& p) { if (&p == points_[0]) { return delaunay_edge[2]; @@ -311,7 +311,7 @@ bool Triangle::GetDelunayEdgeCCW(Point& p) return delaunay_edge[1]; } -bool Triangle::GetDelunayEdgeCW(Point& p) +bool Triangle::GetDelunayEdgeCW(const Point& p) { if (&p == points_[0]) { return delaunay_edge[1]; @@ -321,7 +321,7 @@ bool Triangle::GetDelunayEdgeCW(Point& p) return delaunay_edge[0]; } -void Triangle::SetDelunayEdgeCCW(Point& p, bool e) +void Triangle::SetDelunayEdgeCCW(const Point& p, const bool e) { if (&p == points_[0]) { delaunay_edge[2] = e; @@ -332,7 +332,7 @@ void Triangle::SetDelunayEdgeCCW(Point& p, bool e) } } -void Triangle::SetDelunayEdgeCW(Point& p, bool e) +void Triangle::SetDelunayEdgeCW(const Point& p, const bool e) { if (&p == points_[0]) { delaunay_edge[1] = e; @@ -344,7 +344,7 @@ void Triangle::SetDelunayEdgeCW(Point& p, bool e) } // The neighbor across to given point -Triangle& Triangle::NeighborAcross(Point& opoint) +Triangle& Triangle::NeighborAcross(const Point& opoint) { if (&opoint == points_[0]) { return *neighbors_[0]; diff --git a/poly2tri/common/shapes.h b/poly2tri/common/shapes.h index 7ee1909..e710143 100644 --- a/poly2tri/common/shapes.h +++ b/poly2tri/common/shapes.h @@ -57,7 +57,7 @@ struct Point { std::vector edge_list; /// Construct using coordinates. - Point(double x, double y) : x(x), y(y) {} + Point(const double x, const double y) : x(x), y(y) {} /// Set this point to all zeros. void set_zero() @@ -67,7 +67,7 @@ struct Point { } /// Set this point to some specified coordinates. - void set(double x_, double y_) + void set(const double x_, const double y_) { x = x_; y = y_; @@ -96,7 +96,7 @@ struct Point { } /// Multiply this point by a scalar. - void operator *=(double a) + void operator *=(const double a) { x *= a; y *= a; @@ -111,7 +111,7 @@ struct Point { /// Convert this point into a unit point. Returns the Length. double Normalize() { - double len = Length(); + const double len = Length(); x /= len; y /= len; return len; @@ -158,12 +158,12 @@ bool constrained_edge[3]; /// Flags to determine if an edge is a Delauney edge bool delaunay_edge[3]; -Point* GetPoint(const int& index); -Point* PointCW(Point& point); -Point* PointCCW(Point& point); -Point* OppositePoint(Triangle& t, Point& p); +Point* GetPoint(const int index); +Point* PointCW(const Point& point); +Point* PointCCW(const Point& point); +Point* OppositePoint(Triangle& t, const Point& p); -Triangle* GetNeighbor(const int& index); +Triangle* GetNeighbor(const int index); void MarkNeighbor(Point* p1, Point* p2, Triangle* t); void MarkNeighbor(Triangle& t); @@ -174,34 +174,34 @@ void MarkConstrainedEdge(Point* p, Point* q); int Index(const Point* p); int EdgeIndex(const Point* p1, const Point* p2); -Triangle* NeighborCW(Point& point); -Triangle* NeighborCCW(Point& point); -bool GetConstrainedEdgeCCW(Point& p); -bool GetConstrainedEdgeCW(Point& p); -void SetConstrainedEdgeCCW(Point& p, bool ce); -void SetConstrainedEdgeCW(Point& p, bool ce); -bool GetDelunayEdgeCCW(Point& p); -bool GetDelunayEdgeCW(Point& p); -void SetDelunayEdgeCCW(Point& p, bool e); -void SetDelunayEdgeCW(Point& p, bool e); +Triangle* NeighborCW(const Point& point); +Triangle* NeighborCCW(const Point& point); +bool GetConstrainedEdgeCCW(const Point& p); +bool GetConstrainedEdgeCW(const Point& p); +void SetConstrainedEdgeCCW(const Point& p, const bool ce); +void SetConstrainedEdgeCW(const Point& p, const bool ce); +bool GetDelunayEdgeCCW(const Point& p); +bool GetDelunayEdgeCW(const Point& p); +void SetDelunayEdgeCCW(const Point& p, const bool e); +void SetDelunayEdgeCW(const Point& p, const bool e); -bool Contains(Point* p); +bool Contains(const Point* p); bool Contains(const Edge& e); -bool Contains(Point* p, Point* q); +bool Contains(const Point* p, const Point* q); void Legalize(Point& point); void Legalize(Point& opoint, Point& npoint); /** * Clears all references to all other triangles and points */ void Clear(); -void ClearNeighbor(Triangle *triangle ); +void ClearNeighbor(const Triangle *triangle); void ClearNeighbors(); void ClearDelunayEdges(); inline bool IsInterior(); -inline void IsInterior(bool b); +inline void IsInterior(const bool b); -Triangle& NeighborAcross(Point& opoint); +Triangle& NeighborAcross(const Point& opoint); void DebugPrint(); @@ -271,7 +271,7 @@ inline double Cross(const Point& a, const Point& b) /// Perform the cross product on a point and a scalar. In 2D this produces /// a point. -inline Point Cross(const Point& a, double s) +inline Point Cross(const Point& a, const double s) { return Point(s * a.y, -s * a.x); } @@ -283,17 +283,17 @@ inline Point Cross(const double s, const Point& a) return Point(-s * a.y, s * a.x); } -inline Point* Triangle::GetPoint(const int& index) +inline Point* Triangle::GetPoint(const int index) { return points_[index]; } -inline Triangle* Triangle::GetNeighbor(const int& index) +inline Triangle* Triangle::GetNeighbor(const int index) { return neighbors_[index]; } -inline bool Triangle::Contains(Point* p) +inline bool Triangle::Contains(const Point* p) { return p == points_[0] || p == points_[1] || p == points_[2]; } @@ -303,7 +303,7 @@ inline bool Triangle::Contains(const Edge& e) return Contains(e.p) && Contains(e.q); } -inline bool Triangle::Contains(Point* p, Point* q) +inline bool Triangle::Contains(const Point* p, const Point* q) { return Contains(p) && Contains(q); } @@ -313,7 +313,7 @@ inline bool Triangle::IsInterior() return interior_; } -inline void Triangle::IsInterior(bool b) +inline void Triangle::IsInterior(const bool b) { interior_ = b; } diff --git a/poly2tri/common/utils.h b/poly2tri/common/utils.h index dcfb812..ffb713f 100644 --- a/poly2tri/common/utils.h +++ b/poly2tri/common/utils.h @@ -56,7 +56,7 @@ enum Orientation { CW, CCW, COLLINEAR }; * = (x1-x3)*(y2-y3) - (y1-y3)*(x2-x3) * */ -Orientation Orient2d(Point& pa, Point& pb, Point& pc) +Orientation Orient2d(const Point& pa, const Point& pb, const Point& pc) { double detleft = (pa.x - pc.x) * (pb.y - pc.y); double detright = (pa.y - pc.y) * (pb.x - pc.x); @@ -103,7 +103,7 @@ bool InScanArea(Point& pa, Point& pb, Point& pc, Point& pd) */ -bool InScanArea(Point& pa, Point& pb, Point& pc, Point& pd) +bool InScanArea(const Point& pa, const Point& pb, const Point& pc, const Point& pd) { double oadb = (pa.x - pb.x)*(pd.y - pb.y) - (pd.x - pb.x)*(pa.y - pb.y); if (oadb >= -EPSILON) { diff --git a/poly2tri/sweep/advancing_front.cc b/poly2tri/sweep/advancing_front.cc index d81a41c..e9079ce 100644 --- a/poly2tri/sweep/advancing_front.cc +++ b/poly2tri/sweep/advancing_front.cc @@ -39,7 +39,7 @@ AdvancingFront::AdvancingFront(Node& head, Node& tail) search_node_ = &head; } -Node* AdvancingFront::LocateNode(const double& x) +Node* AdvancingFront::LocateNode(const double x) { Node* node = search_node_; @@ -61,7 +61,7 @@ Node* AdvancingFront::LocateNode(const double& x) return NULL; } -Node* AdvancingFront::FindSearchNode(const double& x) +Node* AdvancingFront::FindSearchNode(const double x) { (void)x; // suppress compiler warnings "unused parameter 'x'" // TODO: implement BST index diff --git a/poly2tri/sweep/advancing_front.h b/poly2tri/sweep/advancing_front.h index 9268395..6a6e7ce 100644 --- a/poly2tri/sweep/advancing_front.h +++ b/poly2tri/sweep/advancing_front.h @@ -74,7 +74,7 @@ Node* search(); void set_search(Node* node); /// Locate insertion point along advancing front -Node* LocateNode(const double& x); +Node* LocateNode(const double x); Node* LocatePoint(const Point* point); @@ -82,7 +82,7 @@ private: Node* head_, *tail_, *search_node_; -Node* FindSearchNode(const double& x); +Node* FindSearchNode(const double x); }; inline Node* AdvancingFront::head() diff --git a/poly2tri/sweep/cdt.cc b/poly2tri/sweep/cdt.cc index f983858..fb19dd9 100644 --- a/poly2tri/sweep/cdt.cc +++ b/poly2tri/sweep/cdt.cc @@ -32,13 +32,13 @@ namespace p2t { -CDT::CDT(std::vector polyline) +CDT::CDT(const std::vector &polyline) { sweep_context_ = new SweepContext(polyline); sweep_ = new Sweep; } -void CDT::AddHole(std::vector polyline) +void CDT::AddHole(const std::vector &polyline) { sweep_context_->AddHole(polyline); } @@ -52,12 +52,12 @@ void CDT::Triangulate() sweep_->Triangulate(*sweep_context_); } -std::vector CDT::GetTriangles() +std::vector &CDT::GetTriangles() { return sweep_context_->GetTriangles(); } -std::list CDT::GetMap() +std::list &CDT::GetMap() { return sweep_context_->GetMap(); } diff --git a/poly2tri/sweep/cdt.h b/poly2tri/sweep/cdt.h index a77734b..46af402 100644 --- a/poly2tri/sweep/cdt.h +++ b/poly2tri/sweep/cdt.h @@ -53,7 +53,7 @@ public: * * @param polyline */ - CDT(std::vector polyline); + CDT(const std::vector &polyline); /** * Destructor - clean up memory @@ -65,7 +65,7 @@ public: * * @param polyline */ - void AddHole(std::vector polyline); + void AddHole(const std::vector &polyline); /** * Add a steiner point @@ -82,12 +82,12 @@ public: /** * Get CDT triangles */ - std::vector GetTriangles(); + std::vector &GetTriangles(); /** * Get triangle map */ - std::list GetMap(); + std::list &GetMap(); private: diff --git a/poly2tri/sweep/sweep.cc b/poly2tri/sweep/sweep.cc index cfd675c..8d2b576 100644 --- a/poly2tri/sweep/sweep.cc +++ b/poly2tri/sweep/sweep.cc @@ -161,7 +161,7 @@ void Sweep::EdgeEvent(SweepContext& tcx, Point& ep, Point& eq, Triangle* triangl bool Sweep::IsEdgeSideOfTriangle(Triangle& triangle, Point& ep, Point& eq) { - int index = triangle.EdgeIndex(&ep, &eq); + const int index = triangle.EdgeIndex(&ep, &eq); if (index != -1) { triangle.MarkConstrainedEdge(index); @@ -243,7 +243,7 @@ void Sweep::FillAdvancingFront(SweepContext& tcx, Node& n) // Fill right basins if (n.next && n.next->next) { - double angle = BasinAngle(n); + const double angle = BasinAngle(n); if (angle < PI_3div4) { FillBasin(tcx, n); } @@ -251,20 +251,20 @@ void Sweep::FillAdvancingFront(SweepContext& tcx, Node& n) } // True if HoleAngle exceeds 90 degrees. -bool Sweep::LargeHole_DontFill(Node* node) { +bool Sweep::LargeHole_DontFill(const Node* node) const { - Node* nextNode = node->next; - Node* prevNode = node->prev; + const Node* nextNode = node->next; + const Node* prevNode = node->prev; if (!AngleExceeds90Degrees(node->point, nextNode->point, prevNode->point)) return false; // Check additional points on front. - Node* next2Node = nextNode->next; + const Node* next2Node = nextNode->next; // "..Plus.." because only want angles on same side as point being added. if ((next2Node != NULL) && !AngleExceedsPlus90DegreesOrIsNegative(node->point, next2Node->point, prevNode->point)) return false; - Node* prev2Node = prevNode->prev; + const Node* prev2Node = prevNode->prev; // "..Plus.." because only want angles on same side as point being added. if ((prev2Node != NULL) && !AngleExceedsPlus90DegreesOrIsNegative(node->point, nextNode->point, prev2Node->point)) return false; @@ -272,19 +272,17 @@ bool Sweep::LargeHole_DontFill(Node* node) { return true; } -bool Sweep::AngleExceeds90Degrees(Point* origin, Point* pa, Point* pb) { - double angle = Angle(*origin, *pa, *pb); - bool exceeds90Degrees = ((angle > PI_div2) || (angle < -PI_div2)); - return exceeds90Degrees; +bool Sweep::AngleExceeds90Degrees(const Point* origin, const Point* pa, const Point* pb) const { + const double angle = Angle(origin, pa, pb); + return ((angle > PI_div2) || (angle < -PI_div2)); } -bool Sweep::AngleExceedsPlus90DegreesOrIsNegative(Point* origin, Point* pa, Point* pb) { - double angle = Angle(*origin, *pa, *pb); - bool exceedsPlus90DegreesOrIsNegative = (angle > PI_div2) || (angle < 0); - return exceedsPlus90DegreesOrIsNegative; +bool Sweep::AngleExceedsPlus90DegreesOrIsNegative(const Point* origin, const Point* pa, const Point* pb) const { + const double angle = Angle(origin, pa, pb); + return (angle > PI_div2) || (angle < 0); } -double Sweep::Angle(Point& origin, Point& pa, Point& pb) { +double Sweep::Angle(const Point* origin, const Point* pa, const Point* pb) const { /* Complex plane * ab = cosA +i*sinA * ab = (ax + ay*i)(bx + by*i) = (ax*bx + ay*by) + i(ax*by-ay*bx) @@ -293,26 +291,25 @@ double Sweep::Angle(Point& origin, Point& pa, Point& pb) { * Where x = ax*bx + ay*by * y = ax*by - ay*bx */ - double px = origin.x; - double py = origin.y; - double ax = pa.x- px; - double ay = pa.y - py; - double bx = pb.x - px; - double by = pb.y - py; - double x = ax * by - ay * bx; - double y = ax * bx + ay * by; - double angle = atan2(x, y); - return angle; + const double px = origin->x; + const double py = origin->y; + const double ax = pa->x- px; + const double ay = pa->y - py; + const double bx = pb->x - px; + const double by = pb->y - py; + const double x = ax * by - ay * bx; + const double y = ax * bx + ay * by; + return atan2(x, y); } -double Sweep::BasinAngle(Node& node) +double Sweep::BasinAngle(const Node& node) const { - double ax = node.point->x - node.next->next->point->x; - double ay = node.point->y - node.next->next->point->y; + const double ax = node.point->x - node.next->next->point->x; + const double ay = node.point->y - node.next->next->point->y; return atan2(ay, ax); } -double Sweep::HoleAngle(Node& node) +double Sweep::HoleAngle(const Node& node) const { /* Complex plane * ab = cosA +i*sinA @@ -322,10 +319,10 @@ double Sweep::HoleAngle(Node& node) * Where x = ax*bx + ay*by * y = ax*by - ay*bx */ - double ax = node.next->point->x - node.point->x; - double ay = node.next->point->y - node.point->y; - double bx = node.prev->point->x - node.point->x; - double by = node.prev->point->y - node.point->y; + const double ax = node.next->point->x - node.point->x; + const double ay = node.next->point->y - node.point->y; + const double bx = node.prev->point->x - node.point->x; + const double by = node.prev->point->y - node.point->y; return atan2(ax * by - ay * bx, ax * bx + ay * by); } @@ -390,43 +387,43 @@ bool Sweep::Legalize(SweepContext& tcx, Triangle& t) return false; } -bool Sweep::Incircle(Point& pa, Point& pb, Point& pc, Point& pd) +bool Sweep::Incircle(const Point& pa, const Point& pb, const Point& pc, const Point& pd) const { - double adx = pa.x - pd.x; - double ady = pa.y - pd.y; - double bdx = pb.x - pd.x; - double bdy = pb.y - pd.y; + const double adx = pa.x - pd.x; + const double ady = pa.y - pd.y; + const double bdx = pb.x - pd.x; + const double bdy = pb.y - pd.y; - double adxbdy = adx * bdy; - double bdxady = bdx * ady; - double oabd = adxbdy - bdxady; + const double adxbdy = adx * bdy; + const double bdxady = bdx * ady; + const double oabd = adxbdy - bdxady; if (oabd <= 0) return false; - double cdx = pc.x - pd.x; - double cdy = pc.y - pd.y; + const double cdx = pc.x - pd.x; + const double cdy = pc.y - pd.y; - double cdxady = cdx * ady; - double adxcdy = adx * cdy; - double ocad = cdxady - adxcdy; + const double cdxady = cdx * ady; + const double adxcdy = adx * cdy; + const double ocad = cdxady - adxcdy; if (ocad <= 0) return false; - double bdxcdy = bdx * cdy; - double cdxbdy = cdx * bdy; + const double bdxcdy = bdx * cdy; + const double cdxbdy = cdx * bdy; - double alift = adx * adx + ady * ady; - double blift = bdx * bdx + bdy * bdy; - double clift = cdx * cdx + cdy * cdy; + const double alift = adx * adx + ady * ady; + const double blift = bdx * bdx + bdy * bdy; + const double clift = cdx * cdx + cdy * cdy; - double det = alift * (bdxcdy - cdxbdy) + blift * ocad + clift * oabd; + const double det = alift * (bdxcdy - cdxbdy) + blift * ocad + clift * oabd; return det > 0; } -void Sweep::RotateTrianglePair(Triangle& t, Point& p, Triangle& ot, Point& op) +void Sweep::RotateTrianglePair(Triangle& t, Point& p, Triangle& ot, Point& op) const { Triangle* n1, *n2, *n3, *n4; n1 = t.NeighborCCW(p); diff --git a/poly2tri/sweep/sweep.h b/poly2tri/sweep/sweep.h index addd3d4..33e34a7 100644 --- a/poly2tri/sweep/sweep.h +++ b/poly2tri/sweep/sweep.h @@ -142,7 +142,7 @@ private: * @param d - point opposite a * @return true if d is inside circle, false if on circle edge */ - bool Incircle(Point& pa, Point& pb, Point& pc, Point& pd); + bool Incircle(const Point& pa, const Point& pb, const Point& pc, const Point& pd) const; /** * Rotates a triangle pair one vertex CW @@ -158,7 +158,7 @@ private: * n4 n4 * */ - void RotateTrianglePair(Triangle& t, Point& p, Triangle& ot, Point& op); + void RotateTrianglePair(Triangle& t, Point& p, Triangle& ot, Point& op) const; /** * Fills holes in the Advancing Front @@ -171,22 +171,22 @@ private: // Decision-making about when to Fill hole. // Contributed by ToolmakerSteve2 - bool LargeHole_DontFill(Node* node); - bool AngleExceeds90Degrees(Point* origin, Point* pa, Point* pb); - bool AngleExceedsPlus90DegreesOrIsNegative(Point* origin, Point* pa, Point* pb); - double Angle(Point& origin, Point& pa, Point& pb); + bool LargeHole_DontFill(const Node* node) const; + bool AngleExceeds90Degrees(const Point* origin, const Point* pa, const Point* pb) const; + bool AngleExceedsPlus90DegreesOrIsNegative(const Point* origin, const Point* pa, const Point* pb) const; + double Angle(const Point* origin, const Point* pa, const Point* pb) const; /** * * @param node - middle node * @return the angle between 3 front nodes */ - double HoleAngle(Node& node); + double HoleAngle(const Node& node) const; /** * The basin angle is decided against the horizontal line [1,0] */ - double BasinAngle(Node& node); + double BasinAngle(const Node& node) const; /** * Fills a basin that has formed on the Advancing Front to the right diff --git a/poly2tri/sweep/sweep_context.cc b/poly2tri/sweep/sweep_context.cc index 150f1a0..17d43f0 100644 --- a/poly2tri/sweep/sweep_context.cc +++ b/poly2tri/sweep/sweep_context.cc @@ -34,7 +34,7 @@ namespace p2t { -SweepContext::SweepContext(std::vector polyline) : points_(polyline), +SweepContext::SweepContext(const std::vector &polyline) : points_(polyline), front_(0), head_(0), tail_(0), @@ -45,7 +45,7 @@ SweepContext::SweepContext(std::vector polyline) : points_(polyline), InitEdges(points_); } -void SweepContext::AddHole(std::vector polyline) +void SweepContext::AddHole(const std::vector &polyline) { InitEdges(polyline); for(unsigned int i = 0; i < polyline.size(); i++) { @@ -57,12 +57,12 @@ void SweepContext::AddPoint(Point* point) { points_.push_back(point); } -std::vector SweepContext::GetTriangles() +std::vector &SweepContext::GetTriangles() { return triangles_; } -std::list SweepContext::GetMap() +std::list &SweepContext::GetMap() { return map_; } @@ -114,13 +114,13 @@ void SweepContext::AddToMap(Triangle* triangle) map_.push_back(triangle); } -Node& SweepContext::LocateNode(Point& point) +Node& SweepContext::LocateNode(const Point& point) { // TODO implement search tree return *front_->LocateNode(point.x); } -void SweepContext::CreateAdvancingFront(std::vector nodes) +void SweepContext::CreateAdvancingFront(const std::vector &nodes) { (void) nodes; diff --git a/poly2tri/sweep/sweep_context.h b/poly2tri/sweep/sweep_context.h index 2853a1e..d7023ce 100644 --- a/poly2tri/sweep/sweep_context.h +++ b/poly2tri/sweep/sweep_context.h @@ -52,25 +52,25 @@ class SweepContext { public: /// Constructor -SweepContext(std::vector polyline); +SweepContext(const std::vector &polyline); /// Destructor ~SweepContext(); void set_head(Point* p1); -Point* head(); +Point* head() const; void set_tail(Point* p1); -Point* tail(); +Point* tail() const; -size_t point_count(); +size_t point_count() const; -Node& LocateNode(Point& point); +Node& LocateNode(const Point& point); void RemoveNode(Node* node); -void CreateAdvancingFront(std::vector nodes); +void CreateAdvancingFront(const std::vector &nodes); /// Try to map a node to all sides of this triangle that don't have a neighbor void MapTriangleToNodes(Triangle& t); @@ -83,16 +83,16 @@ Point* GetPoints(); void RemoveFromMap(Triangle* triangle); -void AddHole(std::vector polyline); +void AddHole(const std::vector &polyline); void AddPoint(Point* point); -AdvancingFront* front(); +AdvancingFront* front() const; void MeshClean(Triangle& triangle); -std::vector GetTriangles(); -std::list GetMap(); +std::vector &GetTriangles(); +std::list &GetMap(); std::vector edge_list; @@ -151,12 +151,12 @@ void InitEdges(std::vector polyline); }; -inline AdvancingFront* SweepContext::front() +inline AdvancingFront* SweepContext::front() const { return front_; } -inline size_t SweepContext::point_count() +inline size_t SweepContext::point_count() const { return points_.size(); } @@ -166,7 +166,7 @@ inline void SweepContext::set_head(Point* p1) head_ = p1; } -inline Point* SweepContext::head() +inline Point* SweepContext::head() const { return head_; } @@ -176,7 +176,7 @@ inline void SweepContext::set_tail(Point* p1) tail_ = p1; } -inline Point* SweepContext::tail() +inline Point* SweepContext::tail() const { return tail_; }