PrecisionModel.h
/**********************************************************************
*
* GEOS - Geometry Engine Open Source
* http://geos.osgeo.org
*
* Copyright (C) 2011 Sandro Santilli <strk@kbt.io>
* Copyright (C) 2006 Refractions Research Inc.
*
* This is free software; you can redistribute and/or modify it under
* the terms of the GNU Lesser General Public Licence as published
* by the Free Software Foundation.
* See the COPYING file for more information.
*
**********************************************************************
*
* Last port: geom/PrecisionModel.java r378 (JTS-1.12)
*
**********************************************************************/
#pragma once
#include <geos/geom/Coordinate.h>
#include <geos/export.h>
#include <cassert>
#include <string>
// Forward declarations
namespace geos {
namespace io {
}
namespace geom {
class Coordinate;
}
}
namespace geos {
namespace geom { // geos::geom
class GEOS_DLL PrecisionModel {
public:
typedef enum {
FIXED,
FLOATING,
FLOATING_SINGLE
} Type;
PrecisionModel(void);
PrecisionModel(Type nModelType);
PrecisionModel(double newScale, double newOffsetX, double newOffsetY);
PrecisionModel(double newScale);
static const double maximumPreciseValue;
double makePrecise(double val) const;
void makePrecise(CoordinateXY& coord) const
{
// optimization for full precision
if(modelType == FLOATING) {
return;
}
coord.x = makePrecise(coord.x);
coord.y = makePrecise(coord.y);
};
void makePrecise(CoordinateXY* coord) const
{
assert(coord);
return makePrecise(*coord);
};
bool isFloating() const;
int getMaximumSignificantDigits() const;
Type getType() const
{
return modelType;
};
double getScale() const
{
assert(!(scale < 0));
return scale;
};
double getGridSize() const
{
if (isFloating())
return DoubleNotANumber;
if (gridSize != 0)
return gridSize;
return 1.0 / scale;
};
double getOffsetX() const;
double getOffsetY() const;
/*
* Sets ´internal` to the precise representation of `external`.
*
* @param external the original coordinate
* @param internal the coordinate whose values will be changed to the
* precise representation of <code>external</code>
* @deprecated use makePrecise instead
*/
//void toInternal(const Coordinate& external, Coordinate* internal) const;
/*
* Returns the precise representation of <code>external</code>.
*
*@param external the original coordinate
*@return
* the coordinate whose values will be changed to the precise
* representation of <code>external</code>
* @deprecated use makePrecise instead
*/
//Coordinate* toInternal(const Coordinate& external) const;
/*
* Returns the external representation of <code>internal</code>.
*
*@param internal the original coordinate
*@return the coordinate whose values will be changed to the
* external representation of <code>internal</code>
* @deprecated no longer needed, since internal representation is same as external representation
*/
//Coordinate* toExternal(const Coordinate& internal) const;
/*
* Sets <code>external</code> to the external representation of
* <code>internal</code>.
*
* @param internal the original coordinate
* @param external
* the coordinate whose values will be changed to the
* external representation of <code>internal</code>
* @deprecated no longer needed, since internal representation is same as external representation
*/
//void toExternal(const Coordinate& internal, Coordinate* external) const;
std::string toString() const;
int compareTo(const PrecisionModel* other) const;
private:
void setScale(double newScale);
// throw IllegalArgumentException
static double snapToInt(double val, double tolerance);
Type modelType;
double scale;
double gridSize = 0.0;
};
// Equality operator for PrecisionModel, deprecate it ?
//inline bool operator==(const PrecisionModel& a, const PrecisionModel& b);
} // namespace geos::geom
} // namespace geos
geos::geom::Coordinate
Coordinate is the lightweight class used to store coordinates.
Definition Coordinate.h:217
geos::geom::PrecisionModel::getGridSize
double getGridSize() const
Definition PrecisionModel.h:242
geos::geom::PrecisionModel::getOffsetY
double getOffsetY() const
geos::geom::PrecisionModel::compareTo
int compareTo(const PrecisionModel *other) const
Compares this PrecisionModel object with the specified object for order.
geos::geom::PrecisionModel::PrecisionModel
PrecisionModel(double newScale, double newOffsetX, double newOffsetY)
Creates a PrecisionModel with Fixed precision.
geos::geom::PrecisionModel::getScale
double getScale() const
Returns the multiplying factor used to obtain a precise coordinate.
Definition PrecisionModel.h:228
geos::geom::PrecisionModel::getMaximumSignificantDigits
int getMaximumSignificantDigits() const
Returns the maximum number of significant digits provided by this precision model.
geos::geom::PrecisionModel::getOffsetX
double getOffsetX() const
geos::geom::PrecisionModel::maximumPreciseValue
static const double maximumPreciseValue
Definition PrecisionModel.h:167
geos::geom::PrecisionModel::PrecisionModel
PrecisionModel(void)
Creates a PrecisionModel with a default precision of FLOATING.
geos::geom::PrecisionModel::Type
Type
The types of Precision Model which GEOS supports.
Definition PrecisionModel.h:92
geos::geom::PrecisionModel::FIXED
@ FIXED
Definition PrecisionModel.h:100
geos::geom::PrecisionModel::FLOATING
@ FLOATING
Definition PrecisionModel.h:107
geos::geom::PrecisionModel::FLOATING_SINGLE
@ FLOATING_SINGLE
Definition PrecisionModel.h:114
geos::geom::PrecisionModel::makePrecise
void makePrecise(CoordinateXY &coord) const
Rounds the given Coordinate to the PrecisionModel grid.
Definition PrecisionModel.h:182
geos::geom::PrecisionModel::PrecisionModel
PrecisionModel(double newScale)
Creates a PrecisionModel with Fixed precision.
geos::geom::PrecisionModel::PrecisionModel
PrecisionModel(Type nModelType)
geos::geom::PrecisionModel::makePrecise
double makePrecise(double val) const
Rounds a numeric value to the PrecisionModel grid.
geos::geom::PrecisionModel::isFloating
bool isFloating() const
geos::geom::PrecisionModel::getType
Type getType() const
Definition PrecisionModel.h:222
geos::geom
Definition Angle.h:26
geos::io
Contains the interfaces for converting JTS objects to and from other formats.
Definition Geometry.h:65
geos
Basic namespace for all GEOS functionalities.
Definition geos.h:38