Skip to content

Commit 0e234ef

Browse files
committed
Refactored point_list_t, linestring_t, ring_t
1 parent c200088 commit 0e234ef

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

src/geom.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,16 @@ bool operator!=(point_list_t const &a, point_list_t const &b) noexcept
2323
return !(a == b);
2424
}
2525

26+
bool operator==(polygon_t const &a, polygon_t const &b) noexcept
27+
{
28+
return (a.outer() == b.outer()) &&
29+
std::equal(a.inners().cbegin(), a.inners().cend(),
30+
b.inners().cbegin(), b.inners().cend());
31+
}
32+
33+
bool operator!=(polygon_t const &a, polygon_t const &b) noexcept
34+
{
35+
return !(a == b);
36+
}
37+
2638
} // namespace geom

src/geom.hpp

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -81,40 +81,41 @@ class point_t
8181
}; // class point_t
8282

8383
/// This type is used as the basis for linestrings and rings.
84-
using point_list_t = std::vector<point_t>;
85-
86-
bool operator==(point_list_t const &a, point_list_t const &b) noexcept;
87-
bool operator!=(point_list_t const &a, point_list_t const &b) noexcept;
88-
89-
class linestring_t : public point_list_t
84+
class point_list_t : public std::vector<point_t>
9085
{
9186
public:
92-
linestring_t() = default;
87+
point_list_t() = default;
9388

9489
template <typename Iterator>
95-
linestring_t(Iterator begin, Iterator end) : point_list_t(begin, end)
90+
point_list_t(Iterator begin, Iterator end)
91+
: std::vector<point_t>(begin, end)
9692
{}
9793

98-
linestring_t(std::initializer_list<point_t> list)
99-
: point_list_t(list.begin(), list.end())
94+
point_list_t(std::initializer_list<point_t> list)
95+
: std::vector<point_t>(list.begin(), list.end())
10096
{}
10197

10298
static std::size_t num_geometries() noexcept { return 1; }
10399

104-
}; // class linestring_t
100+
friend bool operator==(point_list_t const &a,
101+
point_list_t const &b) noexcept;
105102

106-
class ring_t : public point_list_t
103+
friend bool operator!=(point_list_t const &a,
104+
point_list_t const &b) noexcept;
105+
106+
}; // class point_list_t
107+
108+
class linestring_t : public point_list_t
107109
{
108110
public:
109-
ring_t() = default;
111+
using point_list_t::point_list_t;
110112

111-
template <typename Iterator>
112-
ring_t(Iterator begin, Iterator end) : point_list_t(begin, end)
113-
{}
113+
}; // class linestring_t
114114

115-
ring_t(std::initializer_list<point_t> list)
116-
: point_list_t(list.begin(), list.end())
117-
{}
115+
class ring_t : public point_list_t
116+
{
117+
public:
118+
using point_list_t::point_list_t;
118119

119120
}; // class ring_t
120121

@@ -137,17 +138,9 @@ class polygon_t
137138

138139
void add_inner_ring(ring_t &&ring) { m_inners.push_back(std::move(ring)); }
139140

140-
friend bool operator==(polygon_t const &a, polygon_t const &b) noexcept
141-
{
142-
return (a.outer() == b.outer()) &&
143-
std::equal(a.inners().cbegin(), a.inners().cend(),
144-
b.inners().cbegin(), b.inners().cend());
145-
}
141+
friend bool operator==(polygon_t const &a, polygon_t const &b) noexcept;
146142

147-
friend bool operator!=(polygon_t const &a, polygon_t const &b) noexcept
148-
{
149-
return !(a == b);
150-
}
143+
friend bool operator!=(polygon_t const &a, polygon_t const &b) noexcept;
151144

152145
private:
153146
ring_t m_outer;

0 commit comments

Comments
 (0)