GEOS  3.13.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 
25 namespace geos {
26 namespace simplify {
27 class LinkedLine;
28 }
29 namespace geom {
30 class Coordinate;
31 class LineString;
32 }
33 }
34 
35 
39 using geos::simplify::LinkedLine;
40 
41 
42 namespace geos {
43 namespace coverage { // geos::coverage
44 
45 
46 class Corner
47 {
48 
49 public:
50 
51  Corner(const LinkedLine* edge, std::size_t i);
52 
53  bool isVertex(std::size_t index) const;
54 
55  inline std::size_t getIndex() const {
56  return m_index;
57  }
58 
59  inline double getArea() const {
60  return m_area;
61  };
62 
63  const Coordinate& prev() const;
64  const Coordinate& next() const;
65 
66  Envelope envelope() const;
67 
68  bool isVertex(const Coordinate& v) const;
69  bool isBaseline(const Coordinate& p0, const Coordinate& p1) const;
70  bool intersects(const Coordinate& v) const;
71  bool isRemoved() const;
72 
73  const Coordinate& getCoordinate() {
74  return m_edge->getCoordinate(m_index);
75  }
76 
77  std::unique_ptr<LineString> toLineString() const;
78 
79  inline int compareTo(const Corner& rhs) const {
80  double area_lhs = getArea();
81  double area_rhs = rhs.getArea();
82 
83  if (area_lhs == area_rhs) {
84  std::size_t index_lhs = getIndex();
85  std::size_t index_rhs = rhs.getIndex();
86  if (index_lhs == index_rhs) return 0;
87  else return index_lhs < index_rhs ? -1 : 1;
88  }
89  else
90  return area_lhs < area_rhs ? -1 : 1;
91  }
92 
93  bool operator< (const Corner& rhs) const {
94  return compareTo(rhs) < 0;
95  };
96 
97  bool operator> (const Corner& rhs) const {
98  return compareTo(rhs) > 0;
99  };
100 
101  bool operator==(const Corner& rhs) const {
102  return compareTo(rhs) == 0;
103  };
104 
105  struct Greater {
106  inline bool operator()(const Corner & a, const Corner & b) const {
107  return a.compareTo(b) > 0;
108  }
109  };
110 
111  // Order using greater for compatibility with the Java PriorityQueue
112  // implementation, which returns the smallest item off the top of the
113  // queue
114  using PriorityQueue = std::priority_queue<Corner, std::vector<Corner>, Corner::Greater>;
115 
116 
117 private:
118 
119  // members
120  const LinkedLine* m_edge;
121  std::size_t m_index;
122  std::size_t m_prev;
123  std::size_t m_next;
124  double m_area;
125 
126  // methods
127  static double area(const LinkedLine& edge, std::size_t index);
128 
129 }; // Corner
130 
131 
132 
133 GEOS_DLL std::ostream& operator<< (std::ostream& os, const Corner& c);
134 
135 
136 } // geos::coverage
137 } // geos
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:216
An Envelope defines a rectangulare region of the 2D coordinate plane.
Definition: Envelope.h:58
Definition: LineString.h:65
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25