Tolerance

class compas.tolerance.Tolerance[source]

Bases: Data

Tolerance settings for geometric operations.

Parameters:
unit{“M”, “MM”}, optional

The unit of the tolerance settings.

namestr, optional

The name of the tolerance settings.

Attributes:
unit{“M”, “MM”}

The unit of the tolerance settings.

absolutefloat

The absolute tolerance.

relativefloat

The relative tolerance.

angularfloat

The angular tolerance.

approximationfloat

The tolerance used in approximation processes.

precisionint

The precision used when converting numbers to strings. Positive numbers correspond to the number of digits after the decimal point. Negative numbers correspond to the number of digits before the decimal point. Zero corresponds to integer precision. Therefore, the higher the number the higher the precision.

lineardeflectionfloat

The maximum distance between a curve or surface and its polygonal approximation.

Notes

The absolute tolerance is used to determine when a number is small enough to be considered zero. The relative tolerance determines the allowable deviation between two values for the values to be considered equal. The relative tolerance is defined as a fraction of one of the two values. This value is called the “true value”. By convention, the second value is considered the “true value” by the comparison functions of this class.

The compas.tolerance.Tolerance class is implemented using a “singleton” pattern and can therefore have only 1 (one) instance per context. Usage of compas.tolerance.TOL outside of compas internals is therefore deprecated.

Examples

>>> tol = Tolerance()
>>> tol.unit
'M'
>>> tol.absolute
1e-09
>>> tol.relative
1e-06
>>> tol.angular
1e-06

Methods

compare

Compare two values.

format_number

Format a number as a string.

geometric_key

Compute the geometric key of a point.

geometric_key_xy

Compute the geometric key of a point in the XY plane.

is_allclose

Check if two lists of values are element-wise close enough to be considered equal.

is_angle_zero

Check if an angle is close enough to zero to be considered zero.

is_angles_close

Check if two angles are close enough to be considered equal.

is_between

Check if a value is between two other values.

is_close

Check if two values are close enough to be considered equal.

is_negative

Check if a value can be considered a strictly negative number.

is_positive

Check if a value can be considered a strictly positive number.

is_zero

Check if a value is close enough to zero to be considered zero.

precision_from_tolerance

Compute the precision from a given tolerance.

reset

Reset all precision settings to their default values.

tolerance

Compute the tolerance for a comparison.

update_from_dict

Update the tolerance singleton from the key-value pairs found in a dict.

Inherited Methods

ToString

Converts the instance to a string.

copy

Make an independent copy of the data object.

from_json

Construct an object of this type from a JSON file.

from_jsonstring

Construct an object of this type from a JSON string.

sha256

Compute a hash of the data for comparison during version control using the sha256 algorithm.

to_json

Convert an object to its native data representation and save it to a JSON file.

to_jsonstring

Convert an object to its native data representation and save it to a JSON string.

validate_data

Validate the data against the object's data schema.