add const overload and return by reference

Signed-off-by: Tom Hulton-Harrop <tom.hultonharrop@gmail.com>
This commit is contained in:
Tom Hulton-Harrop 2023-03-30 22:43:37 +01:00
parent 81612cb108
commit a5b0e3cdf4
4 changed files with 20 additions and 6 deletions

View File

@ -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();
}

View File

@ -83,12 +83,12 @@ public:
/**
* 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:

View File

@ -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_;
}

View File

@ -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;