From a5b0e3cdf4a48df6381bf1376d5f4ea922ab45e9 Mon Sep 17 00:00:00 2001 From: Tom Hulton-Harrop Date: Thu, 30 Mar 2023 22:43:37 +0100 Subject: [PATCH] add const overload and return by reference Signed-off-by: Tom Hulton-Harrop --- poly2tri/sweep/cdt.cc | 4 ++-- poly2tri/sweep/cdt.h | 4 ++-- poly2tri/sweep/sweep_context.cc | 16 ++++++++++++++-- poly2tri/sweep/sweep_context.h | 2 ++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/poly2tri/sweep/cdt.cc b/poly2tri/sweep/cdt.cc index 4dfe6a6..293efdc 100644 --- a/poly2tri/sweep/cdt.cc +++ b/poly2tri/sweep/cdt.cc @@ -52,12 +52,12 @@ void CDT::Triangulate() sweep_->Triangulate(*sweep_context_); } -std::vector CDT::GetTriangles() +const std::vector& CDT::GetTriangles() const { return sweep_context_->GetTriangles(); } -std::list CDT::GetMap() +const std::list& CDT::GetMap() const { return sweep_context_->GetMap(); } diff --git a/poly2tri/sweep/cdt.h b/poly2tri/sweep/cdt.h index 7c54ea9..ed6f113 100644 --- a/poly2tri/sweep/cdt.h +++ b/poly2tri/sweep/cdt.h @@ -83,12 +83,12 @@ public: /** * Get CDT triangles */ - std::vector GetTriangles(); + const std::vector& GetTriangles() const; /** * Get triangle map */ - std::list GetMap(); + const std::list& GetMap() const; private: diff --git a/poly2tri/sweep/sweep_context.cc b/poly2tri/sweep/sweep_context.cc index 7b9432f..c5a2af9 100644 --- a/poly2tri/sweep/sweep_context.cc +++ b/poly2tri/sweep/sweep_context.cc @@ -57,12 +57,24 @@ void SweepContext::AddPoint(Point* point) { points_.push_back(point); } -std::vector &SweepContext::GetTriangles() +std::vector& SweepContext::GetTriangles() +{ + return const_cast&>( + static_cast(*this).GetTriangles()); +} + +const std::vector& SweepContext::GetTriangles() const { return triangles_; } -std::list &SweepContext::GetMap() +std::list& SweepContext::GetMap() +{ + return const_cast&>( + static_cast(*this).GetMap()); +} + +const std::list& SweepContext::GetMap() const { return map_; } diff --git a/poly2tri/sweep/sweep_context.h b/poly2tri/sweep/sweep_context.h index 11d5739..64029d6 100644 --- a/poly2tri/sweep/sweep_context.h +++ b/poly2tri/sweep/sweep_context.h @@ -91,7 +91,9 @@ AdvancingFront* front() const; void MeshClean(Triangle& triangle); std::vector &GetTriangles(); +const std::vector &GetTriangles() const; std::list &GetMap(); +const std::list &GetMap() const; std::vector edge_list;