GEOS 3.14.0dev
Corner.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2021 Paul Ramsey <pramsey@cleverelephant.ca>
7 *
8 * This is free software; you can redistribute and/or modify it under
9 * the terms of the GNU Lesser General Public Licence as published
10 * by the Free Software Foundation.
11 * See the COPYING file for more information.
12 *
13 **********************************************************************/
14
15#pragma once
16
17#include <geos/geom/Envelope.h>
18#include <geos/simplify/LinkedLine.h>
19#include <geos/export.h>
20
21#include <vector>
22#include <memory>
23#include <queue>
24
25namespace geos {
26namespace simplify {
27class LinkedLine;
28}
29namespace geom {
30class Coordinate;
31class LineString;
32}
33}
34
35namespace geos {
36namespace coverage { // geos::coverage
37
38
39class Corner
40{
41 using Coordinate = geos::geom::Coordinate;
42 using Envelope = geos::geom::Envelope;
43 using LineString = geos::geom::LineString;
44 using LinkedLine = geos::simplify::LinkedLine;
45
46public:
47
48 Corner(const LinkedLine* edge, std::size_t i);
49
50 bool isVertex(std::size_t index) const;
51
52 inline std::size_t getIndex() const {
53 return m_index;
54 }
55
56 inline double getArea() const {
57 return m_area;
58 };
59
60 const Coordinate& prev() const;
61 const Coordinate& next() const;
62
63 Envelope envelope() const;
64
65 bool isVertex(const Coordinate& v) const;
66 bool isBaseline(const Coordinate& p0, const Coordinate& p1) const;
67 bool intersects(const Coordinate& v) const;
68 bool isRemoved() const;
69
70 const Coordinate& getCoordinate() {
71 return m_edge->getCoordinate(m_index);
72 }
73
74 std::unique_ptr<LineString> toLineString() const;
75
76 inline int compareTo(const Corner& rhs) const {
77 double area_lhs = getArea();
78 double area_rhs = rhs.getArea();
79
80 if (area_lhs == area_rhs) {
81 std::size_t index_lhs = getIndex();
82 std::size_t index_rhs = rhs.getIndex();
83 if (index_lhs == index_rhs) return 0;
84 else return index_lhs < index_rhs ? -1 : 1;
85 }
86 else
87 return area_lhs < area_rhs ? -1 : 1;
88 }
89
90 bool operator< (const Corner& rhs) const {
91 return compareTo(rhs) < 0;
92 };
93
94 bool operator> (const Corner& rhs) const {
95 return compareTo(rhs) > 0;
96 };
97
98 bool operator==(const Corner& rhs) const {
99 return compareTo(rhs) == 0;
100 };
101
102 struct Greater {
103 inline bool operator()(const Corner & a, const Corner & b) const {
104 return a.compareTo(b) > 0;
105 }
106 };
107
108 // Order using greater for compatibility with the Java PriorityQueue
109 // implementation, which returns the smallest item off the top of the
110 // queue
111 using PriorityQueue = std::priority_queue<Corner, std::vector<Corner>, Corner::Greater>;
112
113
114private:
115
116 // members
117 const LinkedLine* m_edge;
118 std::size_t m_index;
119 std::size_t m_prev;
120 std::size_t m_next;
121 double m_area;
122
123 // methods
124 static double area(const LinkedLine& edge, std::size_t index);
125
126}; // Corner
127
128
129
130GEOS_DLL std::ostream& operator<< (std::ostream& os, const Corner& c);
131
132
133} // geos::coverage
134} // geos
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition Envelope.h:59
Definition LineString.h:66
Basic namespace for all GEOS functionalities.
Definition geos.h:39