1 #pragma once
2
3 #include <mapbox/geometry/point.hpp>
4
5 #ifdef DEBUG
6 #include <iostream>
7 #endif
8
9 namespace mapbox {
10 namespace geometry {
11 namespace wagyu {
12
13 template <typename T>
14 struct point;
15
16 template <typename T>
17 using point_ptr = point<T>*;
18
19 template <typename T>
20 using const_point_ptr = point<T>* const;
21
22 template <typename T>
23 struct ring;
24
25 template <typename T>
26 using ring_ptr = ring<T>*;
27
28 template <typename T>
29 using const_ring_ptr = ring<T>* const;
30
31 template <typename T>
32 struct point {
33 using coordinate_type = T;
34 ring_ptr<T> ring;
35 T x;
36 T y;
37 point_ptr<T> next;
38 point_ptr<T> prev;
39
pointmapbox::geometry::wagyu::point40 point() : ring(nullptr), x(0), y(0), prev(this), next(this) {
41 }
42
pointmapbox::geometry::wagyu::point43 point(T x_, T y_) : ring(nullptr), x(x_), y(y_), next(this), prev(this) {
44 }
45
pointmapbox::geometry::wagyu::point46 point(ring_ptr<T> ring_, mapbox::geometry::point<T> const& pt)
47 : ring(ring_), x(pt.x), y(pt.y), next(this), prev(this) {
48 }
49
pointmapbox::geometry::wagyu::point50 point(ring_ptr<T> ring_, mapbox::geometry::point<T> const& pt, point_ptr<T> before_this_point)
51 : ring(ring_), x(pt.x), y(pt.y), next(before_this_point), prev(before_this_point->prev) {
52 before_this_point->prev = this;
53 prev->next = this;
54 }
55 };
56
57 template <typename T>
58 using point_vector = std::vector<point_ptr<T>>;
59
60 template <typename T>
61 using point_vector_itr = typename point_vector<T>::iterator;
62
63 template <typename T>
operator ==(point<T> const & lhs,point<T> const & rhs)64 bool operator==(point<T> const& lhs, point<T> const& rhs) {
65 return lhs.x == rhs.x && lhs.y == rhs.y;
66 }
67
68 template <typename T>
operator ==(mapbox::geometry::point<T> const & lhs,point<T> const & rhs)69 bool operator==(mapbox::geometry::point<T> const& lhs, point<T> const& rhs) {
70 return lhs.x == rhs.x && lhs.y == rhs.y;
71 }
72
73 template <typename T>
operator ==(point<T> const & lhs,mapbox::geometry::point<T> const & rhs)74 bool operator==(point<T> const& lhs, mapbox::geometry::point<T> const& rhs) {
75 return lhs.x == rhs.x && lhs.y == rhs.y;
76 }
77
78 template <typename T>
operator !=(point<T> const & lhs,point<T> const & rhs)79 bool operator!=(point<T> const& lhs, point<T> const& rhs) {
80 return lhs.x != rhs.x || lhs.y != rhs.y;
81 }
82
83 template <typename T>
operator !=(mapbox::geometry::point<T> const & lhs,point<T> const & rhs)84 bool operator!=(mapbox::geometry::point<T> const& lhs, point<T> const& rhs) {
85 return lhs.x != rhs.x || lhs.y != rhs.y;
86 }
87
88 template <typename T>
operator !=(point<T> const & lhs,mapbox::geometry::point<T> const & rhs)89 bool operator!=(point<T> const& lhs, mapbox::geometry::point<T> const& rhs) {
90 return lhs.x != rhs.x || lhs.y != rhs.y;
91 }
92
93 #ifdef DEBUG
94
95 template <class charT, class traits, typename T>
operator <<(std::basic_ostream<charT,traits> & out,const point<T> & p)96 inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& out,
97 const point<T>& p) {
98 out << " point at: " << p.x << ", " << p.y;
99 return out;
100 }
101
102 template <class charT, class traits, typename T>
operator <<(std::basic_ostream<charT,traits> & out,const mapbox::geometry::point<T> & p)103 inline std::basic_ostream<charT, traits>& operator<<(std::basic_ostream<charT, traits>& out,
104 const mapbox::geometry::point<T>& p) {
105 out << " point at: " << p.x << ", " << p.y;
106 return out;
107 }
108 #endif
109 }
110 }
111 }
112