1// Boost.Polygon library segment_data.hpp header file
2
3// Copyright (c) Intel Corporation 2008.
4// Copyright (c) 2008-2012 Simonson Lucanus.
5// Copyright (c) 2012-2012 Andrii Sydorchuk.
6
7// See http://www.boost.org for updates, documentation, and revision history.
8// Use, modification and distribution is subject to the Boost Software License,
9// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10// http://www.boost.org/LICENSE_1_0.txt)
11
12#ifndef BOOST_POLYGON_SEGMENT_DATA_HPP
13#define BOOST_POLYGON_SEGMENT_DATA_HPP
14
15#include "isotropy.hpp"
16#include "segment_concept.hpp"
17
18namespace boost {
19namespace polygon {
20
21template <typename T>
22class segment_data {
23 public:
24 typedef T coordinate_type;
25 typedef point_data<T> point_type;
26
27 segment_data()
28#ifndef BOOST_POLYGON_MSVC
29 : points_()
30#endif
31 {}
32
33 segment_data(const point_type& low, const point_type& high) {
34 points_[LOW] = low;
35 points_[HIGH] = high;
36 }
37
38 segment_data(const segment_data& that) {
39 points_[0] = that.points_[0];
40 points_[1] = that.points_[1];
41 }
42
43 segment_data& operator=(const segment_data& that) {
44 points_[0] = that.points_[0];
45 points_[1] = that.points_[1];
46 return *this;
47 }
48
49 template <typename SegmentType>
50 segment_data& operator=(const SegmentType& that) {
51 assign(*this, that);
52 return *this;
53 }
54
55 point_type get(direction_1d dir) const {
56 return points_[dir.to_int()];
57 }
58
59 void set(direction_1d dir, const point_type& point) {
60 points_[dir.to_int()] = point;
61 }
62
63 point_type low() const {
64 return points_[LOW];
65 }
66
67 segment_data& low(const point_type& point) {
68 points_[LOW] = point;
69 return *this;
70 }
71
72 point_type high() const {
73 return points_[HIGH];
74 }
75
76 segment_data& high(const point_type& point) {
77 points_[HIGH] = point;
78 return *this;
79 }
80
81 bool operator==(const segment_data& that) const {
82 return (points_[0] == that.points_[0]) &&
83 (points_[1] == that.points_[1]);
84 }
85
86 bool operator!=(const segment_data& that) const {
87 return (points_[0] != that.points_[0]) ||
88 (points_[1] != that.points_[1]);
89 }
90
91 bool operator<(const segment_data& that) const {
92 if (points_[0] != that.points_[0]) {
93 return points_[0] < that.points_[0];
94 }
95 return points_[1] < that.points_[1];
96 }
97
98 bool operator<=(const segment_data& that) const {
99 return !(that < *this);
100 }
101
102 bool operator>(const segment_data& that) const {
103 return that < *this;
104 }
105
106 bool operator>=(const segment_data& that) const {
107 return !((*this) < that);
108 }
109
110 private:
111 point_type points_[2];
112};
113
114template <typename CType>
115struct geometry_concept<segment_data<CType> > {
116 typedef segment_concept type;
117};
118} // polygon
119} // boost
120
121#endif // BOOST_POLYGON_SEGMENT_DATA_HPP
122

source code of boost/boost/polygon/segment_data.hpp