GEOS 3.15.0dev
PrecisionModel.h
1/**********************************************************************
2 *
3 * GEOS - Geometry Engine Open Source
4 * http://geos.osgeo.org
5 *
6 * Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
7 * Copyright (C) 2006 Refractions Research Inc.
8 *
9 * This is free software; you can redistribute and/or modify it under
10 * the terms of the GNU Lesser General Public Licence as published
11 * by the Free Software Foundation.
12 * See the COPYING file for more information.
13 *
14 **********************************************************************
15 *
16 * Last port: geom/PrecisionModel.java r378 (JTS-1.12)
17 *
18 **********************************************************************/
19
20#pragma once
21
22#include <geos/geom/Coordinate.h>
23#include <geos/export.h>
24
25#include <cassert>
26#include <string>
27
28// Forward declarations
29namespace geos {
30namespace io {
31}
32namespace geom {
33class Coordinate;
34}
35}
36
37namespace geos {
38namespace geom { // geos::geom
39
87class GEOS_DLL PrecisionModel {
88
89public:
90
92 typedef enum {
93
101
108
114 FLOATING_SINGLE
115
116 } Type;
117
120
127 PrecisionModel(Type nModelType);
128
144 PrecisionModel(double newScale, double newOffsetX, double newOffsetY);
145
159 PrecisionModel(double newScale);
160
167 static const double maximumPreciseValue;
168
179 double makePrecise(double val) const;
180
182 void makePrecise(CoordinateXY& coord) const
183 {
184 // optimization for full precision
185 if(modelType == FLOATING) {
186 return;
187 }
188
189 coord.x = makePrecise(coord.x);
190 coord.y = makePrecise(coord.y);
191 };
192
193 void makePrecise(CoordinateXY* coord) const
194 {
195 assert(coord);
196 return makePrecise(*coord);
197 };
198
204 bool isFloating() const;
205
217
222 Type getType() const
223 {
224 return modelType;
225 };
226
228 double getScale() const
229 {
230 assert(!(scale < 0));
231 return scale;
232 };
233
242 double getGridSize() const
243 {
244 if (isFloating())
245 return DoubleNotANumber;
246
247 if (gridSize != 0)
248 return gridSize;
249
250 return 1.0 / scale;
251 };
252
259 double getOffsetX() const;
260
267 double getOffsetY() const;
268
269 /*
270 * Sets ´internal` to the precise representation of `external`.
271 *
272 * @param external the original coordinate
273 * @param internal the coordinate whose values will be changed to the
274 * precise representation of <code>external</code>
275 * @deprecated use makePrecise instead
276 */
277 //void toInternal(const Coordinate& external, Coordinate* internal) const;
278
279 /*
280 * Returns the precise representation of <code>external</code>.
281 *
282 *@param external the original coordinate
283 *@return
284 * the coordinate whose values will be changed to the precise
285 * representation of <code>external</code>
286 * @deprecated use makePrecise instead
287 */
288 //Coordinate* toInternal(const Coordinate& external) const;
289
290 /*
291 * Returns the external representation of <code>internal</code>.
292 *
293 *@param internal the original coordinate
294 *@return the coordinate whose values will be changed to the
295 * external representation of <code>internal</code>
296 * @deprecated no longer needed, since internal representation is same as external representation
297 */
298 //Coordinate* toExternal(const Coordinate& internal) const;
299
300 /*
301 * Sets <code>external</code> to the external representation of
302 * <code>internal</code>.
303 *
304 * @param internal the original coordinate
305 * @param external
306 * the coordinate whose values will be changed to the
307 * external representation of <code>internal</code>
308 * @deprecated no longer needed, since internal representation is same as external representation
309 */
310 //void toExternal(const Coordinate& internal, Coordinate* external) const;
311
312 std::string toString() const;
313
333 int compareTo(const PrecisionModel* other) const;
334
335private:
336
344 void setScale(double newScale);
345 // throw IllegalArgumentException
346
350 static double snapToInt(double val, double tolerance);
351
352 Type modelType;
353
357 double scale;
358
364 double gridSize = 0.0;
365
366};
367
368// Equality operator for PrecisionModel, deprecate it ?
369//inline bool operator==(const PrecisionModel& a, const PrecisionModel& b);
370
371} // namespace geos::geom
372} // namespace geos
Specifies the precision model of the Coordinate in a Geometry.
Definition PrecisionModel.h:87
double getGridSize() const
Definition PrecisionModel.h:242
int compareTo(const PrecisionModel *other) const
Compares this PrecisionModel object with the specified object for order.
PrecisionModel(double newScale, double newOffsetX, double newOffsetY)
Creates a PrecisionModel with Fixed precision.
double getScale() const
Returns the multiplying factor used to obtain a precise coordinate.
Definition PrecisionModel.h:228
int getMaximumSignificantDigits() const
Returns the maximum number of significant digits provided by this precision model.
static const double maximumPreciseValue
Definition PrecisionModel.h:167
PrecisionModel(void)
Creates a PrecisionModel with a default precision of FLOATING.
Type
The types of Precision Model which GEOS supports.
Definition PrecisionModel.h:92
@ FIXED
Definition PrecisionModel.h:100
@ FLOATING
Definition PrecisionModel.h:107
void makePrecise(CoordinateXY &coord) const
Rounds the given Coordinate to the PrecisionModel grid.
Definition PrecisionModel.h:182
PrecisionModel(double newScale)
Creates a PrecisionModel with Fixed precision.
PrecisionModel(Type nModelType)
double makePrecise(double val) const
Rounds a numeric value to the PrecisionModel grid.
Type getType() const
Definition PrecisionModel.h:222
Basic namespace for all GEOS functionalities.
Definition geos.h:38