GEOS  3.11.0beta2
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 
90 class GEOS_DLL PrecisionModel {
91  friend class io::Unload;
92 
93 public:
94 
96  typedef enum {
97 
105 
112 
118  FLOATING_SINGLE
119 
120  } Type;
121 
124 
131  PrecisionModel(Type nModelType);
132 
148  PrecisionModel(double newScale, double newOffsetX, double newOffsetY);
149 
163  PrecisionModel(double newScale);
164 
171  static const double maximumPreciseValue;
172 
183  double makePrecise(double val) const;
184 
186  void makePrecise(Coordinate& coord) const
187  {
188  // optimization for full precision
189  if(modelType == FLOATING) {
190  return;
191  }
192 
193  coord.x = makePrecise(coord.x);
194  coord.y = makePrecise(coord.y);
195  };
196 
197  void makePrecise(Coordinate* coord) const
198  {
199  assert(coord);
200  return makePrecise(*coord);
201  };
202 
208  bool isFloating() const;
209 
221 
226  Type getType() const
227  {
228  return modelType;
229  };
230 
232  double getScale() const
233  {
234  assert(!(scale < 0));
235  return scale;
236  };
237 
246  double getGridSize() const
247  {
248  if (isFloating())
249  return DoubleNotANumber;
250 
251  if (gridSize != 0)
252  return gridSize;
253 
254  return 1.0 / scale;
255  };
256 
263  double getOffsetX() const;
264 
271  double getOffsetY() const;
272 
273  /*
274  * Sets ´internal` to the precise representation of `external`.
275  *
276  * @param external the original coordinate
277  * @param internal the coordinate whose values will be changed to the
278  * precise representation of <code>external</code>
279  * @deprecated use makePrecise instead
280  */
281  //void toInternal(const Coordinate& external, Coordinate* internal) const;
282 
283  /*
284  * Returns the precise representation of <code>external</code>.
285  *
286  *@param external the original coordinate
287  *@return
288  * the coordinate whose values will be changed to the precise
289  * representation of <code>external</code>
290  * @deprecated use makePrecise instead
291  */
292  //Coordinate* toInternal(const Coordinate& external) const;
293 
294  /*
295  * Returns the external representation of <code>internal</code>.
296  *
297  *@param internal the original coordinate
298  *@return the coordinate whose values will be changed to the
299  * external representation of <code>internal</code>
300  * @deprecated no longer needed, since internal representation is same as external representation
301  */
302  //Coordinate* toExternal(const Coordinate& internal) const;
303 
304  /*
305  * Sets <code>external</code> to the external representation of
306  * <code>internal</code>.
307  *
308  * @param internal the original coordinate
309  * @param external
310  * the coordinate whose values will be changed to the
311  * external representation of <code>internal</code>
312  * @deprecated no longer needed, since internal representation is same as external representation
313  */
314  //void toExternal(const Coordinate& internal, Coordinate* external) const;
315 
316  std::string toString() const;
317 
337  int compareTo(const PrecisionModel* other) const;
338 
339 private:
340 
348  void setScale(double newScale);
349  // throw IllegalArgumentException
350 
351  Type modelType;
352 
356  double scale;
357 
363  double gridSize = 0.0;
364 
365 };
366 
367 // Equality operator for PrecisionModel, deprecate it ?
368 //inline bool operator==(const PrecisionModel& a, const PrecisionModel& b);
369 
370 } // namespace geos::geom
371 } // namespace geos
Coordinate is the lightweight class used to store coordinates.
Definition: Coordinate.h:58
double y
y-coordinate
Definition: Coordinate.h:81
double x
x-coordinate
Definition: Coordinate.h:78
Specifies the precision model of the Coordinate in a Geometry.
Definition: PrecisionModel.h:90
double getGridSize() const
Definition: PrecisionModel.h:246
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:232
int getMaximumSignificantDigits() const
Returns the maximum number of significant digits provided by this precision model.
static const double maximumPreciseValue
Definition: PrecisionModel.h:171
void makePrecise(Coordinate &coord) const
Rounds the given Coordinate to the PrecisionModel grid.
Definition: PrecisionModel.h:186
PrecisionModel(void)
Creates a PrecisionModel with a default precision of FLOATING.
Type
The types of Precision Model which GEOS supports.
Definition: PrecisionModel.h:96
@ FIXED
Definition: PrecisionModel.h:104
@ FLOATING
Definition: PrecisionModel.h:111
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:226
Basic namespace for all GEOS functionalities.
Definition: Angle.h:25