Fishnet 2.0.1
Framework for Graph-Based Analysis of GIS Vector Data
Loading...
Searching...
No Matches
PolygonalRingVerification.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <fishnet/Segment.hpp>
5
7
8namespace fishnet::geometry {
9
18template<fishnet::math::Number T>
19constexpr static bool isValidPolygonalRing(util::random_access_range_of<Segment<T>> auto const & segments) noexcept{
20 if (segments.size() < 3)
21 return false; // a ring has to have at least three segments
22 for(size_t i = 0 ; i < segments.size();++i) {
23 auto l = segments[i];
24 if(not l.isValid())
25 continue; // 0-length segments get skipped
26 for (size_t j = i+2; j< segments.size(); ++j){
27 auto r = segments[j];
28 if(not r.isValid())
29 continue; // 0-length segments get skipped
30 if (l.intersects(r) and not l.touches(r)){
31 return false; // if segments intersect, and the intersection is not an endpoint of both segments, the ring is not valid (->Self-Intersection)
32 }
33 }
34 if(not segments[i].touches(segments[(i+1)%segments.size()]))
35 return false; // adjacent segments have to touch each other (-> Closed Ring)
36 }
37 return true;
38}
39
47template<fishnet::math::Number T>
48constexpr static void verifyPolygonalRing(util::random_access_range_of<Segment<T>> auto const & segments) {
49 if (segments.size() < 3)
50 throw InvalidGeometryException("Ring has to contain at least three Segments");
51 for(size_t i = 0 ; i < segments.size();++i) {
52 auto l = segments[i];
53 if(not l.isValid()) continue;
54 for (size_t j = i+2; j< segments.size(); ++j){
55 auto r = segments[j];
56 if(not r.isValid()) continue;
57 if (l.intersects(r) and not l.touches(r))
58 throw InvalidGeometryException("Ring Segments intersect each other: \n"+l.toString()+" intersects "+r.toString());
59 }
60 if(not segments[i].touches(segments[(i+1)%segments.size()]))
61 throw InvalidGeometryException("Adjacent Segments of Ring do not touch at endpoints: \n"+segments[i].toString()+" does not touch "+segments[(i+1)%segments.size()].toString());
62 }
63}
64
65}
Exception class for geometry-related errors.
Definition InvalidGeometryException.hpp:10
Implementation of a segment.
Definition Segment.hpp:14
Definition CollectionConcepts.hpp:39
Definition BoundingBoxWrapper.hpp:5
static constexpr bool isValidPolygonalRing(util::random_access_range_of< Segment< T > > auto const &segments) noexcept
Decides whether a range of segments is a valid, closed polygonal ring.
Definition PolygonalRingVerification.hpp:19
static constexpr void verifyPolygonalRing(util::random_access_range_of< Segment< T > > auto const &segments)
Verify a range segments is a valid, closed polygonal ring.
Definition PolygonalRingVerification.hpp:48