geom2d.const

Floating point comparison functions and miscellaneous constants.

For a discussion about floating point comparison see:

http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/

The default value of EPSILON should be fine for most applications but if it is to be changed it should be set once (and only once) with a call to set_epsilon() before using the geom2d API.

EPSILON (and related) should not be referenced by module globals at import time due to this possible mutability.

geom2d.const.EPSILON: float = 1e-08

Tolerance value used for floating point comparisons.

The maximum numeric distance between two floating point numbers for them to be considered equal.

geom2d.const.EPSILON2: float = 1.0000000000000001e-16

Handy for comparing distance**2 to avoid sqrt().

geom2d.const.EPSILON_MINUS: float = 9.999999777955395e-09

Tolerence/epsilon minus a tiny bit (system float epsilon).

Useful for testing float comparisons… But possibly not much else.

geom2d.const.EPSILON_PRECISION: int = 8

Number of significant digits after decimal point.

geom2d.const.HASH_SIZE = 2305843009213693951

Hash constants for hashing integers and vectors/points.

geom2d.const.MAX_XY: float = 92233720368.54776

Maximum reasonable floating point coordinate value.

Numbers in this range will still work with coordinate hashing, float comparisons, and integer conversions.

geom2d.const.REPSILON: float = 100000000

Reciprocal epsilon for int coordinate conversions, etc.

geom2d.const.TAU: float = 6.283185307179586

Commonly used constant 2 * pi.

geom2d.const.angle_eq(a: float, b: float, tolerance: float | None = None) bool

Special case of float_eq where angles close to +-PI are considered equal.

geom2d.const.float_eq(a: float, b: float, tolerance: float | None = None) bool

Compare floats.

This is slightly faster than float_eq1 and does not scale tolerance for small numbers (< 1.0).

geom2d.const.float_eq1(a: float, b: float, tolerance: float | None = None) bool

Compare floats.

The two float are considered equal if the difference between them is less than a normalized tolerance value.

geom2d.const.float_eq2(a: float, b: float, tolerance: float | None = None) bool

Compare floats.

This simpler and faster version works ok for small/reasonable values. It fails for larger numbers where floating point gaps are significant.

geom2d.const.float_eq3(a: float, b: float, tolerance: float | None = None) bool

Compare floats.

This is slightly faster than float_eq1 and does not scale tolerance for small numbers (< 1.0).

geom2d.const.float_round(value: float) float

Round the value to a rounding precision corresponding to EPSILON.

geom2d.const.is_zero(value: float) bool

Determine if the float value is essentially zero.

geom2d.const.set_epsilon(value: float) float

Set the nominal tolerance for float comparisons.

This updates the global constants:

Returns:

Previous value of EPSILON