Fishnet 2.0.1
Framework for Graph-Based Analysis of GIS Vector Data
Loading...
Searching...
No Matches
ISegment.hpp
Go to the documentation of this file.
1#pragma once
2#include "GeometryBase.hpp"
3#include "IPoint.hpp"
4#include "ILine.hpp"
5
6namespace fishnet::geometry::__impl{
7template<typename T>
8class SegmentStub{
9public:
10 using numeric_type = T;
11 constexpr static GeometryType type = GeometryType::SEGMENT;
12 PointStub<T> p() const{
13 return PointStub<T>(0,0);
14 }
15 PointStub<T> q() const{
16 return PointStub<T>(1,1);
17 }
18 SegmentStub(PointStub<T> p, PointStub<T> q){}
19 bool operator==(const SegmentStub & other) const noexcept{
20 return true;
21 }
22 PointStub<T> direction() const{
23 return PointStub<T>(1,1);
24 }
25 double length() const{
26 return 0.0;
27 }
28 PointStub<T> upperEndpoint() const{
29 return PointStub<T>(0,0);
30 }
31 PointStub<T> lowerEndpoint() const{
32 return PointStub<T>(0,0);
33 }
34 PointStub<T> leftEndpoint() const{
35 return PointStub<T>(0,0);
36 }
37 PointStub<T> rightEndpoint() const{
38 return PointStub<T>(0,0);
39 }
40 bool isEndpoint(PointStub<T> point) const{
41 return true;
42 }
43 bool isValid() const{
44 return true;
45 }
46 bool overlaps(SegmentStub segment) const{
47 return true;
48 }
49 bool contains(PointStub<T> point) const{
50 return true;
51 }
52 bool contains(SegmentStub segment) const{
53 return true;
54 }
55 bool touches(SegmentStub segment) const{
56 return true;
57 }
58 double distance(PointStub<T> point) const{
59 return 0.0;
60 }
61 double distance(SegmentStub segment) const{
62 return 0.0;
63 }
64 bool isParallel(LineStub<T> line) const{
65 return true;
66 }
67 bool isParallel(SegmentStub segment) const{
68 return true;
69 }
70 bool intersects(LineStub<T> line) const{
71 return true;
72 }
73 bool intersects(SegmentStub segment) const{
74 return true;
75 }
76 std::optional<PointStub<T>> intersection(LineStub<T> line) const{
77 return {};
78 }
79 std::optional<PointStub<T>> intersection(SegmentStub segment) const{
80 return {};
81 }
82 LineStub<T> toLine() const{
83 return LineStub(p(),q());
84 }
85 SegmentStub flip() const{
86 return SegmentStub(q(),p());
87 }
88 size_t hash() const noexcept {
89 return 0;
90 }
91 std::string toString() const{
92 return {};
93 }
94};
95} // namespace fishnet::geometry::__impl
96
97namespace fishnet::geometry{
98
104template<typename S>
105concept ISegment = GeometryBase<S> && requires (
106 const std::remove_cvref_t<S> & segment,
107 const __impl::SegmentStub<typename std::remove_cvref_t<S>::numeric_type> & otherSegment,
108 const __impl::PointStub<typename std::remove_cvref_t<S>::numeric_type> & point,
109 const __impl::LineStub<typename std::remove_cvref_t<S>::numeric_type> & line
110){
111 {segment.p()} -> IPoint;
112 {segment.q()} -> IPoint;
113 {segment.direction()} -> IPoint;
114 {segment.length()} -> std::convertible_to<double>;
115 {segment.upperEndpoint()} -> IPoint;
116 {segment.lowerEndpoint()} -> IPoint;
117 {segment.leftEndpoint()} -> IPoint;
118 {segment.rightEndpoint()} -> IPoint;
119 {segment.isEndpoint(point)} -> std::same_as<bool>; // test whether any the point is either p or q
120 {segment.isValid()} -> std::same_as<bool>; // a segment is valid if its length is greater than 0, i.e. if p != q
121 {segment.overlaps(otherSegment)} -> std::same_as<bool>; // test whether the segment has a true overlay with another segment (not only touching the endpoints)
122 {segment.contains(point)} -> std::same_as<bool>;
123 {segment.contains(otherSegment)} -> std::same_as<bool>;
124 {segment.touches(otherSegment)} -> std::same_as<bool>;
125 {segment.distance(point)} -> std::convertible_to<double>;
126 {segment.distance(otherSegment)} -> std::convertible_to<double>;
127 {segment.isParallel(line)} -> std::same_as<bool>;
128 {segment.isParallel(otherSegment)} -> std::same_as<bool>;
129 {segment.intersects(line)} -> std::same_as<bool>;
130 {segment.intersects(otherSegment)} -> std::same_as<bool>;
131 {segment.intersection(line)} -> IPointOptional;
132 {segment.intersection(otherSegment)} -> IPointOptional;
133 {segment.toLine()} -> ILine;
134 {segment.flip()} -> std::same_as<std::remove_cvref_t<S>>; // returns a new segment with p and q swapped
135};
136
139
140template<typename R>
141concept SegmentRange = std::ranges::range<R> && ISegment<std::ranges::range_value_t<R>>;
143} // namespace fishnet::geometry
IPolygon implementation backed by an OGRPolygon.
Definition OGRPolygonAdapter.hpp:22
Definition GeometryBase.hpp:11
Interface for a line A line is defined through two points p and q, defining a direction vector.
Definition ILine.hpp:76
Definition IPoint.hpp:135
Interface for a point.
Definition IPoint.hpp:92
Interface for a segment A segment is formed between two points p and q, containing only the points on...
Definition ISegment.hpp:105
Definition ISegment.hpp:141
Definition BoundingBoxWrapper.hpp:5