Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return by reference and const overloads #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion poly2tri/common/shapes.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ bool constrained_edge[3];
bool delaunay_edge[3];

Point* GetPoint(int index);
const Point* GetPoint(int index) const;
Point* PointCW(const Point& point);
Point* PointCCW(const Point& point);
Point* OppositePoint(Triangle& t, const Point& p);
Expand Down Expand Up @@ -288,11 +289,17 @@ inline Point Cross(double s, const Point& a)
return Point(-s * a.y, s * a.x);
}

inline Point* Triangle::GetPoint(int index)
inline const Point* Triangle::GetPoint(int index) const
{
return points_[index];
}

inline Point* Triangle::GetPoint(int index)
{
return const_cast<Point*>(
static_cast<const Triangle&>(*this).GetPoint(index));
}

inline Triangle* Triangle::GetNeighbor(int index)
{
return neighbors_[index];
Expand Down
4 changes: 2 additions & 2 deletions poly2tri/sweep/cdt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ void CDT::Triangulate()
sweep_->Triangulate(*sweep_context_);
}

std::vector<p2t::Triangle*> CDT::GetTriangles()
const std::vector<p2t::Triangle*>& CDT::GetTriangles() const
{
return sweep_context_->GetTriangles();
}

std::list<p2t::Triangle*> CDT::GetMap()
const std::list<p2t::Triangle*>& CDT::GetMap() const
{
return sweep_context_->GetMap();
}
Expand Down
4 changes: 2 additions & 2 deletions poly2tri/sweep/cdt.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ class P2T_DLL_SYMBOL CDT
/**
* Get CDT triangles
*/
std::vector<Triangle*> GetTriangles();
const std::vector<Triangle*>& GetTriangles() const;

/**
* Get triangle map
*/
std::list<Triangle*> GetMap();
const std::list<Triangle*>& GetMap() const;

private:

Expand Down
16 changes: 14 additions & 2 deletions poly2tri/sweep/sweep_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,24 @@ void SweepContext::AddPoint(Point* point) {
points_.push_back(point);
}

std::vector<Triangle*> &SweepContext::GetTriangles()
std::vector<Triangle*>& SweepContext::GetTriangles()
{
return const_cast<std::vector<Triangle*>&>(
static_cast<const SweepContext&>(*this).GetTriangles());
}

const std::vector<Triangle*>& SweepContext::GetTriangles() const
{
return triangles_;
}

std::list<Triangle*> &SweepContext::GetMap()
std::list<Triangle*>& SweepContext::GetMap()
{
return const_cast<std::list<Triangle*>&>(
static_cast<const SweepContext&>(*this).GetMap());
}

const std::list<Triangle*>& SweepContext::GetMap() const
{
return map_;
}
Expand Down
2 changes: 2 additions & 0 deletions poly2tri/sweep/sweep_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ AdvancingFront* front() const;
void MeshClean(Triangle& triangle);

std::vector<Triangle*> &GetTriangles();
const std::vector<Triangle*> &GetTriangles() const;
std::list<Triangle*> &GetMap();
const std::list<Triangle*> &GetMap() const;

std::vector<Edge*> edge_list;

Expand Down