diff options
Diffstat (limited to 'extern/carve/include/carve/polyline_iter.hpp')
-rw-r--r-- | extern/carve/include/carve/polyline_iter.hpp | 46 |
1 files changed, 25 insertions, 21 deletions
diff --git a/extern/carve/include/carve/polyline_iter.hpp b/extern/carve/include/carve/polyline_iter.hpp index 8501e620fea..8c8f9a91a7c 100644 --- a/extern/carve/include/carve/polyline_iter.hpp +++ b/extern/carve/include/carve/polyline_iter.hpp @@ -29,12 +29,12 @@ namespace carve { struct polyline_vertex_iter : public std::iterator<std::random_access_iterator_tag, Vertex *> { Polyline *base; - size_t idx; + ssize_t idx; polyline_vertex_iter(Polyline *_base) : base(_base), idx(0) { } - polyline_vertex_iter(Polyline *_base, size_t _idx) : base(_base), idx(_idx) { + polyline_vertex_iter(Polyline *_base, ssize_t _idx) : base(_base), idx(_idx) { } polyline_vertex_iter operator++(int) { return polyline_vertex_iter(base, idx++); } @@ -46,14 +46,15 @@ namespace carve { polyline_vertex_iter &operator-=(int v) { idx -= v; return *this; } Vertex *operator*() const { - return base->vertex(idx); + CARVE_ASSERT(idx >= 0 && idx < base->vertexCount()); + return base->vertex((size_t)idx); } }; - static inline ptrdiff_t operator-(const polyline_vertex_iter &a, const polyline_vertex_iter &b) { return a.idx - b.idx; } - + static inline ssize_t operator-(const polyline_vertex_iter &a, const polyline_vertex_iter &b) { return a.idx - b.idx; } + static inline bool operator==(const polyline_vertex_iter&a, const polyline_vertex_iter &b) { return a.idx == b.idx; } static inline bool operator!=(const polyline_vertex_iter&a, const polyline_vertex_iter &b) { return a.idx != b.idx; } static inline bool operator<(const polyline_vertex_iter&a, const polyline_vertex_iter &b) { return a.idx < b.idx; } @@ -65,12 +66,12 @@ namespace carve { struct polyline_vertex_const_iter : public std::iterator<std::random_access_iterator_tag, Vertex *> { const Polyline *base; - size_t idx; + ssize_t idx; polyline_vertex_const_iter(const Polyline *_base) : base(_base), idx(0) { } - polyline_vertex_const_iter(const Polyline *_base, size_t _idx) : base(_base), idx(_idx) { + polyline_vertex_const_iter(const Polyline *_base, ssize_t _idx) : base(_base), idx(_idx) { } polyline_vertex_const_iter operator++(int) { return polyline_vertex_const_iter(base, idx++); } @@ -82,13 +83,14 @@ namespace carve { polyline_vertex_const_iter &operator-=(int v) { idx -= v; return *this; } const Vertex *operator*() const { - return base->vertex(idx); + CARVE_ASSERT(idx >= 0 && idx < base->vertexCount()); + return base->vertex((size_t)idx); } }; - static inline ptrdiff_t operator-(const polyline_vertex_const_iter &a, const polyline_vertex_const_iter &b) { return a.idx - b.idx; } + static inline ssize_t operator-(const polyline_vertex_const_iter &a, const polyline_vertex_const_iter &b) { return a.idx - b.idx; } static inline bool operator==(const polyline_vertex_const_iter&a, const polyline_vertex_const_iter &b) { return a.idx == b.idx; } static inline bool operator!=(const polyline_vertex_const_iter&a, const polyline_vertex_const_iter &b) { return a.idx != b.idx; } @@ -101,25 +103,25 @@ namespace carve { return polyline_vertex_const_iter(this, 0); } inline polyline_vertex_const_iter Polyline::vend() const { - return polyline_vertex_const_iter(this, vertexCount()); + return polyline_vertex_const_iter(this, (ssize_t)vertexCount()); } inline polyline_vertex_iter Polyline::vbegin() { return polyline_vertex_iter(this, 0); } inline polyline_vertex_iter Polyline::vend() { - return polyline_vertex_iter(this, vertexCount()); + return polyline_vertex_iter(this, (ssize_t)vertexCount()); } struct polyline_edge_iter : public std::iterator<std::random_access_iterator_tag, PolylineEdge *> { Polyline *base; - size_t idx; + ssize_t idx; polyline_edge_iter(Polyline *_base) : base(_base), idx(0) { } - polyline_edge_iter(Polyline *_base, size_t _idx) : base(_base), idx(_idx) { + polyline_edge_iter(Polyline *_base, ssize_t _idx) : base(_base), idx(_idx) { } polyline_edge_iter operator++(int) { return polyline_edge_iter(base, idx++); } @@ -131,13 +133,14 @@ namespace carve { polyline_edge_iter &operator-=(int v) { idx -= v; return *this; } PolylineEdge *operator*() const { - return base->edge(idx); + CARVE_ASSERT(idx >= 0 && idx < base->edgeCount()); + return base->edge((size_t)idx); } }; - static inline int operator-(const polyline_edge_iter&a, const polyline_edge_iter &b) { return a.idx - b.idx; } + static inline ssize_t operator-(const polyline_edge_iter&a, const polyline_edge_iter &b) { return a.idx - b.idx; } static inline bool operator==(const polyline_edge_iter&a, const polyline_edge_iter &b) { return a.idx == b.idx; } static inline bool operator!=(const polyline_edge_iter&a, const polyline_edge_iter &b) { return a.idx != b.idx; } @@ -150,12 +153,12 @@ namespace carve { struct polyline_edge_const_iter : public std::iterator<std::random_access_iterator_tag, PolylineEdge *> { const Polyline *base; - size_t idx; + ssize_t idx; polyline_edge_const_iter(const Polyline *_base) : base(_base), idx(0) { } - polyline_edge_const_iter(const Polyline *_base, size_t _idx) : base(_base), idx(_idx) { + polyline_edge_const_iter(const Polyline *_base, ssize_t _idx) : base(_base), idx(_idx) { } polyline_edge_const_iter operator++(int) { return polyline_edge_const_iter(base, idx++); } @@ -167,13 +170,14 @@ namespace carve { polyline_edge_const_iter &operator-=(int v) { idx -= v; return *this; } const PolylineEdge *operator*() const { - return base->edge(idx); + CARVE_ASSERT(idx >= 0 && idx < base->edgeCount()); + return base->edge((size_t)idx); } }; - static inline int operator-(const polyline_edge_const_iter&a, const polyline_edge_const_iter &b) { return a.idx - b.idx; } + static inline ssize_t operator-(const polyline_edge_const_iter&a, const polyline_edge_const_iter &b) { return a.idx - b.idx; } static inline bool operator==(const polyline_edge_const_iter&a, const polyline_edge_const_iter &b) { return a.idx == b.idx; } static inline bool operator!=(const polyline_edge_const_iter&a, const polyline_edge_const_iter &b) { return a.idx != b.idx; } @@ -186,13 +190,13 @@ namespace carve { return polyline_edge_const_iter(this, 0); } inline polyline_edge_const_iter Polyline::eend() const { - return polyline_edge_const_iter(this, edgeCount()); + return polyline_edge_const_iter(this, (ssize_t)edgeCount()); } inline polyline_edge_iter Polyline::ebegin() { return polyline_edge_iter(this, 0); } inline polyline_edge_iter Polyline::eend() { - return polyline_edge_iter(this, edgeCount()); + return polyline_edge_iter(this, (ssize_t)edgeCount()); } } |