GEOS 3.11.1
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/geom/Envelope.h> // for unique_ptr
25#include <geos/io/WKTWriter.h>
26#include <geos/util/math.h>
27
28#include <array>
29
30#ifdef _MSC_VER
31#pragma warning(push)
32#pragma warning(disable: 4251) // warning C4251: needs to have dll-interface to be used by clients of class
33#endif
34
35// Forward declarations
36namespace geos {
37namespace geom {
38class Envelope;
39}
40namespace algorithm {
41class LineIntersector;
42}
43namespace noding {
44class NodedSegmentString;
45}
46}
47
48namespace geos {
49namespace noding { // geos::noding
50namespace snapround { // geos::noding::snapround
51
61class GEOS_DLL HotPixel {
62
63private:
64
65 static constexpr double TOLERANCE = 0.5;
66
67 static constexpr int UPPER_RIGHT = 0;
68 static constexpr int UPPER_LEFT = 1;
69 static constexpr int LOWER_LEFT = 2;
70 static constexpr int LOWER_RIGHT = 3;
71
72 geom::Coordinate originalPt;
73 double scaleFactor;
74
75 /* Indicates if this hot pixel must be a node in the output. */
76 bool hpIsNode;
77
78 /* The scaled ordinates of the hot pixel point */
79 double hpx;
80 double hpy;
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
102public:
103
107 double getWidth() const { return 1.0 / scaleFactor; };
108
109 double getScaleFactor() const { return scaleFactor; };
110
117 HotPixel(const geom::Coordinate& pt, double scaleFactor);
118
119 /*
120 * Gets the coordinate this hot pixel is based at.
121 *
122 * @return the coordinate of the pixel
123 */
124 const geom::Coordinate& getCoordinate() const;
125
134 const geom::Coordinate& p1) const;
135
142 bool intersects(const geom::Coordinate& p) const;
143
144 bool isNode() const { return hpIsNode; };
145 void setToNode() { hpIsNode = true; };
146
147 std::ostream& operator<< (std::ostream& os);
148};
149
150} // namespace geos::noding::snapround
151} // namespace geos::noding
152} // namespace geos
153
154#ifdef _MSC_VER
155#pragma warning(pop)
156#endif
157
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
Implements a "hot pixel" as used in the Snap Rounding algorithm.
Definition: HotPixel.h:61
HotPixel(const geom::Coordinate &pt, double scaleFactor)
bool intersects(const geom::Coordinate &p0, const geom::Coordinate &p1) const
bool intersects(const geom::Coordinate &p) const
double getWidth() const
Definition: HotPixel.h:107
double round(double val)
Definition: math.h:36
Basic namespace for all GEOS functionalities.
Definition: geos.h:39