Skip to content

Commit 14a2eed

Browse files
authored
Merge pull request #1333 from compas-dev/use-tolerance
Use tolerance
2 parents 95d1bcd + 978005c commit 14a2eed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+429
-471
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
* Fixed broken import in `copas.geometry.trimesh_smoothing_numpy`.
3030
* Changed `RhinoBrep.trimmed` to return single result or raise `BrepTrimmingError` instead of returning a list.
3131
* Changed order of imports according to `isort` and changed line length to `179`.
32+
* Changed use of `compas.geometry.allclose` to `compas.tolerance.TOL.is_allclose`.
33+
* Changed use of `compas.geometry.close` to `compas.tolerance.TOL.is_close`.
3234

3335
### Removed
3436

src/compas/geometry/_core/tangent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ def tangent_points_to_circle_xy(circle, point):
2222
2323
Examples
2424
--------
25-
>>> from compas.geometry import allclose
25+
>>> from compas.tolerance import TOL
2626
>>> circle = ((0, 0, 0), (0, 0, 1)), 1.0
2727
>>> point = (2, 4, 0)
2828
>>> t1, t2 = tangent_points_to_circle_xy(circle, point)
29-
>>> allclose(t1, [-0.772, 0.636, 0.000], 1e-3)
29+
>>> TOL.is_allclose(t1, [-0.772, 0.636, 0.000], atol=1e-3)
3030
True
31-
>>> allclose(t2, [0.972, -0.236, 0.000], 1e-3)
31+
>>> TOL.is_allclose(t2, [0.972, -0.236, 0.000], atol=1e-3)
3232
True
3333
3434
"""

src/compas/geometry/_core/transformations.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ def orthonormalize_axes(xaxis, yaxis):
6262
6363
Examples
6464
--------
65-
>>> from compas.geometry import allclose
65+
>>> from compas.tolerance import TOL
6666
>>> xaxis = [1, 4, 5]
6767
>>> yaxis = [1, 0, -2]
6868
>>> xaxis, yaxis = orthonormalize_axes(xaxis, yaxis)
69-
>>> allclose(xaxis, [0.1543, 0.6172, 0.7715], tol=0.001)
69+
>>> TOL.is_allclose(xaxis, [0.1543, 0.6172, 0.7715], atol=0.001)
7070
True
71-
>>> allclose(yaxis, [0.6929, 0.4891, -0.5298], tol=0.001)
71+
>>> TOL.is_allclose(yaxis, [0.6929, 0.4891, -0.5298], atol=0.001)
7272
True
7373
7474
"""

src/compas/geometry/curves/arc.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from compas.geometry import Frame
1111
from compas.geometry import Point
1212
from compas.geometry import Vector
13-
from compas.geometry import close
13+
from compas.tolerance import TOL
1414

1515
from .curve import Curve
1616

@@ -244,7 +244,7 @@ def circumference(self):
244244

245245
@property
246246
def is_circle(self):
247-
return close(abs(abs(self.angle) - PI2), 0.0)
247+
return TOL.is_close(abs(self.angle), PI2)
248248

249249
@property
250250
def is_closed(self):

src/compas/geometry/curves/polyline.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
from compas.geometry import Frame
66
from compas.geometry import Line
77
from compas.geometry import Point
8-
from compas.geometry import allclose
98
from compas.geometry import is_point_on_line
109
from compas.geometry import is_point_on_polyline
1110
from compas.geometry import transform_points
1211
from compas.itertools import pairwise
12+
from compas.tolerance import TOL
1313

1414
from .curve import Curve
1515

@@ -118,7 +118,7 @@ def __len__(self):
118118
def __eq__(self, other):
119119
if not hasattr(other, "__iter__") or not hasattr(other, "__len__") or len(self) != len(other):
120120
return False
121-
return allclose(self, other)
121+
return TOL.is_allclose(self, other)
122122

123123
# ==========================================================================
124124
# properties

src/compas/geometry/intersections.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,15 +609,15 @@ def intersection_sphere_line(sphere, line):
609609
610610
Examples
611611
--------
612-
>>> from compas.geometry import allclose
612+
>>> from compas.tolerance import TOL
613613
614614
>>> sphere = (3.0, 7.0, 4.0), 10.0
615615
>>> line = (1.0, 0, 0.5), (2.0, 1.0, 0.5)
616616
>>> x1, x2 = intersection_sphere_line(sphere, line)
617617
618-
>>> allclose(x1, [11.634, 10.634, 0.500], 1e-3)
618+
>>> TOL.is_allclose(x1, [11.634, 10.634, 0.500], atol=1e-3)
619619
True
620-
>>> allclose(x2, [-0.634, -1.634, 0.50], 1e-3)
620+
>>> TOL.is_allclose(x2, [-0.634, -1.634, 0.50], atol=1e-3)
621621
True
622622
623623
"""

src/compas/geometry/polygon.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
from compas.geometry import Plane
1111
from compas.geometry import Point
1212
from compas.geometry import Transformation
13-
from compas.geometry import allclose
1413
from compas.geometry import area_polygon
1514
from compas.geometry import bounding_box
1615
from compas.geometry import centroid_polygon
@@ -19,6 +18,7 @@
1918
from compas.geometry import is_polygon_convex
2019
from compas.geometry import transform_points
2120
from compas.itertools import pairwise
21+
from compas.tolerance import TOL
2222

2323

2424
class Polygon(Geometry):
@@ -119,7 +119,7 @@ def __iter__(self):
119119
def __eq__(self, other):
120120
if not hasattr(other, "__iter__") or not hasattr(other, "__len__") or len(self) != len(other):
121121
return False
122-
return allclose(self, other)
122+
return TOL.is_allclose(self, other)
123123

124124
# ==========================================================================
125125
# Properties

src/compas/geometry/projection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212
"""
1313

1414
from compas.geometry import Transformation
15-
from compas.geometry import allclose
1615
from compas.geometry import decompose_matrix
1716
from compas.geometry import matrix_from_orthogonal_projection
1817
from compas.geometry import matrix_from_parallel_projection
1918
from compas.geometry import matrix_from_perspective_entries
2019
from compas.geometry import matrix_from_perspective_projection
20+
from compas.tolerance import TOL
2121
from compas.utilities import flatten
2222

2323

@@ -47,7 +47,7 @@ class Projection(Transformation):
4747
def __init__(self, matrix=None, check=False, name=None):
4848
if matrix and check:
4949
_, _, _, _, perspective = decompose_matrix(matrix)
50-
if not allclose(flatten(matrix), flatten(matrix_from_perspective_entries(perspective))):
50+
if not TOL.is_allclose(flatten(matrix), flatten(matrix_from_perspective_entries(perspective))):
5151
raise ValueError("This is not a proper projection matrix.")
5252
super(Projection, self).__init__(matrix=matrix, name=name)
5353

src/compas/geometry/quaternion.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,12 @@ def from_frame(cls, frame):
292292
293293
Examples
294294
--------
295-
>>> from compas.geometry import allclose
295+
>>> from compas.tolerance import TOL
296296
>>> from compas.geometry import Frame
297297
>>> q = [1., -2., 3., -4.]
298298
>>> F = Frame.from_quaternion(q)
299299
>>> Q = Quaternion.from_frame(F)
300-
>>> allclose(Q.canonized(), quaternion_canonize(quaternion_unitize(q)))
300+
>>> TOL.is_allclose(Q.canonized(), quaternion_canonize(quaternion_unitize(q)))
301301
True
302302
303303
"""

src/compas/geometry/reflection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
"""
1313

1414
from compas.geometry import Transformation
15-
from compas.geometry import allclose
1615
from compas.geometry import cross_vectors
1716
from compas.geometry import decompose_matrix
1817
from compas.geometry import dot_vectors
1918
from compas.geometry import identity_matrix
2019
from compas.geometry import matrix_from_perspective_entries
2120
from compas.geometry import normalize_vector
21+
from compas.tolerance import TOL
2222
from compas.utilities import flatten
2323

2424

@@ -50,7 +50,7 @@ class Reflection(Transformation):
5050
def __init__(self, matrix=None, check=False, name=None):
5151
if matrix and check:
5252
_, _, _, _, perspective = decompose_matrix(matrix)
53-
if not allclose(flatten(matrix), flatten(matrix_from_perspective_entries(perspective))):
53+
if not TOL.is_allclose(flatten(matrix), flatten(matrix_from_perspective_entries(perspective))):
5454
raise ValueError("This is not a proper reflection matrix.")
5555
super(Reflection, self).__init__(matrix=matrix, name=name)
5656

0 commit comments

Comments
 (0)