GEOS  3.14.0dev
HotPixel.h
1 /**********************************************************************
2  *
3  * GEOS - Geometry Engine Open Source
4  * http://geos.osgeo.org
5  *
6  * Copyright (C) 2006 Refractions Research Inc.
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  * Last port: noding/snapround/HotPixel.java r320 (JTS-1.12)
16  *
17  **********************************************************************/
18 
19 #pragma once
20 
21 #include <geos/export.h>
22 
23 #include <geos/geom/Coordinate.h> // for composition
24 #include <geos/util/IllegalArgumentException.h>
25 #include <geos/util/math.h>
26 
27 #include <array>
28 
29 #ifdef _MSC_VER
30 #pragma warning(push)
31 #pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
32 #endif
33 
34 // Forward declarations
35 namespace geos {
36 namespace geom {
37 class Envelope;
38 }
39 namespace algorithm {
40 class LineIntersector;
41 }
42 namespace noding {
43 class NodedSegmentString;
44 }
45 }
46 
47 namespace geos {
48 namespace noding { // geos::noding
49 namespace snapround { // geos::noding::snapround
50 
60 class GEOS_DLL HotPixel {
61 
62 private:
63 
64  static constexpr double TOLERANCE = 0.5;
65 
66  static constexpr int UPPER_RIGHT = 0;
67  static constexpr int UPPER_LEFT = 1;
68  static constexpr int LOWER_LEFT = 2;
69  static constexpr int LOWER_RIGHT = 3;
70 
71  // Store all ordinates because we may use them in constructing a SegmentNode.
72  geom::CoordinateXYZM originalPt;
73  double scaleFactor;
74 
75  /* The scaled ordinates of the hot pixel point */
76  double hpx;
77  double hpy;
78 
79  /* Indicates if this hot pixel must be a node in the output. */
80  bool hpIsNode;
81 
82  double scaleRound(double val) const
83  {
84  // Use Java-compatible round implementation
85  return util::round(val * scaleFactor);
86  };
87 
88  double scale(double val) const
89  {
90  return val * scaleFactor;
91  };
92 
93  bool intersectsPixelClosure(const geom::Coordinate& p0,
94  const geom::Coordinate& p1) const;
95 
96  bool intersectsScaled(double p0x, double p0y, double p1x, double p1y) const;
97 
98  // Declare type as noncopyable
99  HotPixel(const HotPixel& other) = delete;
100  HotPixel& operator=(const HotPixel& rhs) = delete;
101 
102 public:
103 
107  double getWidth() const { return 1.0 / scaleFactor; };
108 
109  double getScaleFactor() const { return scaleFactor; };
110 
116  template<typename CoordType>
117  HotPixel(const CoordType& pt, double scaleFact)
118  : originalPt(pt)
119  , scaleFactor(scaleFact)
120  , hpx(pt.x)
121  , hpy(pt.y)
122  , hpIsNode(false)
123  {
124  if(scaleFactor <= 0.0) {
125  throw util::IllegalArgumentException("Scale factor must be non-zero");
126  }
127  if(scaleFactor != 1.0) {
128  hpx = scaleRound(pt.x);
129  hpy = scaleRound(pt.y);
130  }
131  }
132 
133  /*
134  * Gets the coordinate this hot pixel is based at.
135  *
136  * @return the coordinate of the pixel
137  */
138  const geom::CoordinateXYZM& getCoordinate() const;
139 
147  bool intersects(const geom::CoordinateXY& p0,
148  const geom::CoordinateXY& p1) const;
149 
156  bool intersects(const geom::CoordinateXY& p) const;
157 
158  bool isNode() const { return hpIsNode; };
159  void setToNode() { hpIsNode = true; };
160 
161  std::ostream& operator<< (std::ostream& os);
162 };
163 
164 } // namespace geos::noding::snapround
165 } // namespace geos::noding
166 } // namespace geos
167 
168 #ifdef _MSC_VER
169 #pragma warning(pop)
170 #endif
171 
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:217
Implements a "hot pixel" as used in the Snap Rounding algorithm.
Definition: HotPixel.h:60
bool intersects(const geom::CoordinateXY &p) const
HotPixel(const CoordType &pt, double scaleFact)
Definition: HotPixel.h:117
double getWidth() const
Definition: HotPixel.h:107
bool intersects(const geom::CoordinateXY &p0, const geom::CoordinateXY &p1) const
Indicates one or more illegal arguments.
Definition: IllegalArgumentException.h:33
double round(double val)
Definition: math.h:36
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25