GEOS  3.13.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
29 namespace geos {
30 namespace io {
31 class Unload;
32 }
33 namespace geom {
34 class Coordinate;
35 }
36 }
37 
38 namespace geos {
39 namespace geom { // geos::geom
40 
88 class GEOS_DLL PrecisionModel {
89  friend class io::Unload;
90 
91 public:
92 
94  typedef enum {
95 
103 
110 
116  FLOATING_SINGLE
117 
118  } Type;
119 
122 
129  PrecisionModel(Type nModelType);
130 
146  PrecisionModel(double newScale, double newOffsetX, double newOffsetY);
147 
161  PrecisionModel(double newScale);
162 
169  static const double maximumPreciseValue;
170 
181  double makePrecise(double val) const;
182 
184  void makePrecise(CoordinateXY& coord) const
185  {
186  // optimization for full precision
187  if(modelType == FLOATING) {
188  return;
189  }
190 
191  coord.x = makePrecise(coord.x);
192  coord.y = makePrecise(coord.y);
193  };
194 
195  void makePrecise(CoordinateXY* coord) const
196  {
197  assert(coord);
198  return makePrecise(*coord);
199  };
200 
206  bool isFloating() const;
207 
219 
224  Type getType() const
225  {
226  return modelType;
227  };
228 
230  double getScale() const
231  {
232  assert(!(scale < 0));
233  return scale;
234  };
235 
244  double getGridSize() const
245  {
246  if (isFloating())
247  return DoubleNotANumber;
248 
249  if (gridSize != 0)
250  return gridSize;
251 
252  return 1.0 / scale;
253  };
254 
261  double getOffsetX() const;
262 
269  double getOffsetY() const;
270 
271  /*
272  * Sets ´internal` to the precise representation of `external`.
273  *
274  * @param external the original coordinate
275  * @param internal the coordinate whose values will be changed to the
276  * precise representation of <code>external</code>
277  * @deprecated use makePrecise instead
278  */
279  //void toInternal(const Coordinate& external, Coordinate* internal) const;
280 
281  /*
282  * Returns the precise representation of <code>external</code>.
283  *
284  *@param external the original coordinate
285  *@return
286  * the coordinate whose values will be changed to the precise
287  * representation of <code>external</code>
288  * @deprecated use makePrecise instead
289  */
290  //Coordinate* toInternal(const Coordinate& external) const;
291 
292  /*
293  * Returns the external representation of <code>internal</code>.
294  *
295  *@param internal the original coordinate
296  *@return the coordinate whose values will be changed to the
297  * external representation of <code>internal</code>
298  * @deprecated no longer needed, since internal representation is same as external representation
299  */
300  //Coordinate* toExternal(const Coordinate& internal) const;
301 
302  /*
303  * Sets <code>external</code> to the external representation of
304  * <code>internal</code>.
305  *
306  * @param internal the original coordinate
307  * @param external
308  * the coordinate whose values will be changed to the
309  * external representation of <code>internal</code>
310  * @deprecated no longer needed, since internal representation is same as external representation
311  */
312  //void toExternal(const Coordinate& internal, Coordinate* external) const;
313 
314  std::string toString() const;
315 
335  int compareTo(const PrecisionModel* other) const;
336 
337 private:
338 
346  void setScale(double newScale);
347  // throw IllegalArgumentException
348 
352  static double snapToInt(double val, double tolerance);
353 
354  Type modelType;
355 
359  double scale;
360 
366  double gridSize = 0.0;
367 
368 };
369 
370 // Equality operator for PrecisionModel, deprecate it ?
371 //inline bool operator==(const PrecisionModel& a, const PrecisionModel& b);
372 
373 } // namespace geos::geom
374 } // namespace geos
Specifies the precision model of the Coordinate in a Geometry.
Definition: PrecisionModel.h:88
double getGridSize() const
Definition: PrecisionModel.h:244
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:230
int getMaximumSignificantDigits() const
Returns the maximum number of significant digits provided by this precision model.
static const double maximumPreciseValue
Definition: PrecisionModel.h:169
PrecisionModel(void)
Creates a PrecisionModel with a default precision of FLOATING.
Type
The types of Precision Model which GEOS supports.
Definition: PrecisionModel.h:94
@ FIXED
Definition: PrecisionModel.h:102
@ FLOATING
Definition: PrecisionModel.h:109
void makePrecise(CoordinateXY &coord) const
Rounds the given Coordinate to the PrecisionModel grid.
Definition: PrecisionModel.h:184
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:224
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25