diff --git a/CHANGELOG.md b/CHANGELOG.md index cfcc7733534..72bfae95425 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed * Fixed bug in `compas.geometry.curves.curve.Curve.reversed` by adding missing parenthesis. +* Fixed all doctests so we can run `invoke test --doctest`. ### Removed diff --git a/src/compas/colors/color.py b/src/compas/colors/color.py index 61f82d713f0..b80d51dad9d 100644 --- a/src/compas/colors/color.py +++ b/src/compas/colors/color.py @@ -98,7 +98,7 @@ class Color(Data): By default, this class will create a color with the RGB components in the range ``[0.0, 1.0]``. >>> Color(1, 0, 0) - Color(1.0, 0.0, 0.0, alpha=1.0) + Color(1, 0, 0, alpha=1.0) Attempting to create a color with components outside of the range ``[0.0, 1.0]`` will raise a ``ValueError``. diff --git a/src/compas/data/coercion.py b/src/compas/data/coercion.py index 90dc8a93448..80581dc17ef 100644 --- a/src/compas/data/coercion.py +++ b/src/compas/data/coercion.py @@ -20,12 +20,6 @@ def coerce_sequence_of_tuple(sequence): with each iterable item converted to a tuple, and non-iterable items wrapped in a tuple. - Examples - -------- - >>> items = coerce_sequence_of_tuple(["a", 1, (None,), [2.0, 3.0]]) - >>> is_sequence_of_tuple(items) - True - """ items = [] for item in sequence: @@ -53,12 +47,6 @@ def coerce_sequence_of_list(sequence): with each iterable item converted to a list, and non-iterable items wrapped in a list. - Examples - -------- - >>> items = coerce_sequence_of_list(["a", 1, (None,), [2.0, 3.0]]) - >>> is_sequence_of_list(items) - True - """ items = [] for item in sequence: diff --git a/src/compas/data/encoders.py b/src/compas/data/encoders.py index 7b1a1c64ebf..9d369debe6b 100644 --- a/src/compas/data/encoders.py +++ b/src/compas/data/encoders.py @@ -181,13 +181,14 @@ class DataDecoder(json.JSONDecoder): >>> import json >>> from compas.data import DataDecoder - >>> with open("point.json", "r") as f: - ... point = json.load(f, cls=DataDecoder) + >>> with open('point.json', 'r') as f: # doctest: +SKIP + ... point = json.load(f, cls=DataDecoder) # doctest: +SKIP + ... Implicit use case. >>> from compas.data import json_load - >>> point = json_load("point.json") + >>> point = json_load('point.json') # doctest: +SKIP """ diff --git a/src/compas/datastructures/assembly/part.py b/src/compas/datastructures/assembly/part.py index d47fa6eed85..c3fa4ca8fae 100644 --- a/src/compas/datastructures/assembly/part.py +++ b/src/compas/datastructures/assembly/part.py @@ -34,24 +34,27 @@ class GeometricFeature(Feature): Examples -------- - >>> def trim_brep_plane(brep, plane): - >>> # trim brep with plane, return trimmed brep + >>> from compas.geometry import Brep + >>> from compas.datastructures import Mesh >>> - >>> def trim_mesh_plane(mesh, plane): - >>> # trim mesh with plane, return trimmed mesh + >>> def trim_brep_plane(brep, plane): + ... pass + ... + >>> def trim_mesh_plane(mesh, plane): + ... pass + ... + >>> class TrimmingFeature(GeometricFeature): + ... OPERATIONS = {Brep: trim_brep_plane, Mesh: trim_mesh_plane} + ... def __init__(self, trimming_plane): + ... super(TrimmingFeature, self).__init__() + ... self._geometry = trimming_plane + ... def apply(self, part): + ... part_geometry = part.get_geometry(with_features=True) + ... type_ = Brep if isinstance(part_geometry, Brep) else Mesh + ... operation = OPERATIONS[type_] + ... return operation(part_geometry, self._geometry) + ... >>> - >>> class TrimmingFeature(GeometricFeature): - >>> OPERATIONS = {Brep: trim_brep_plane, Mesh: trim_mesh_plane} - >>> - >>> def __init__(self, trimming_plane): - >>> super(TrimmingFeature, self).__init__() - >>> self._geometry = trimming_plane - >>> - >>> def apply(self, part): - >>> part_geometry = part.get_geometry(with_features=True) - >>> type_ = Brep if isinstance(part_geometry, Brep) else Mesh - >>> operation = OPERATIONS[type_] - >>> return operation(part_geometry, self._geometry) """ @@ -81,18 +84,17 @@ class ParametricFeature(Feature): Examples -------- >>> class ExtensionFeature(ParametricFeature): - >>> def __init__(self, extend_by): - >>> super(ExtensionFeature, self).__init__() - >>> self.extend_by = extend_by - >>> - >>> def apply(self, part): - >>> part.length += self._extend_by - >>> - >>> def restore(self, part): - >>> part.length -= self._extend_by + ... def __init__(self, extend_by): + ... super(ExtensionFeature, self).__init__() + ... self.extend_by = extend_by + ... def apply(self, part): + ... part.length += self._extend_by + ... def restore(self, part): + ... part.length -= self._extend_by + ... def accumulate(self, other): + ... return BeamExtensionFeature(max(self.extend_by, other.extend_by)) + ... >>> - >>> def accumulate(self, other): - >>> return BeamExtensionFeature(max(self.extend_by, other.extend_by)) """ diff --git a/src/compas/datastructures/cell_network/cell_network.py b/src/compas/datastructures/cell_network/cell_network.py index 6e49e289e6d..5556beafb18 100644 --- a/src/compas/datastructures/cell_network/cell_network.py +++ b/src/compas/datastructures/cell_network/cell_network.py @@ -74,10 +74,17 @@ class CellNetwork(Datastructure): >>> vertices = [(0, 0, 0), (0, 1, 0), (1, 1, 0), (1, 0, 0), (0, 0, 1), (1, 0, 1), (1, 1, 1), (0, 1, 1)] >>> faces = [[0, 1, 2, 3], [0, 3, 5, 4], [3, 2, 6, 5], [2, 1, 7, 6], [1, 0, 4, 7], [4, 5, 6, 7]] >>> cells = [[0, 1, 2, 3, 4, 5]] - >>> [network.add_vertex(x=x, y=y, z=z) for x, y, z in vertices] - >>> [cell_network.add_face(fverts) for fverts in faces] - >>> [cell_network.add_cell(fkeys) for fkeys in cells] - >>> cell_network + >>> for x, y, z in vertices: + ... vertex = cell_network.add_vertex(x=x, y=y, z=z) + ... + >>> for face_vertices in faces: + ... face = cell_network.add_face(face_vertices) + ... + >>> for cell_faces in cells: + ... cell = cell_network.add_cell(cell_faces) + ... + >>> print(cell_network) + """ diff --git a/src/compas/datastructures/graph/graph.py b/src/compas/datastructures/graph/graph.py index 5fb7fc62763..a0fdad75c84 100644 --- a/src/compas/datastructures/graph/graph.py +++ b/src/compas/datastructures/graph/graph.py @@ -2366,7 +2366,7 @@ def complement(self): >>> from compas.datastructures import Graph >>> graph = Graph.from_obj(compas.get("lines.obj")) >>> complement = graph.complement() - >>> any(complement.has_edge(u, v, directed=False) for u, v in graph.edges()) + >>> any(complement.has_edge((u, v), directed=False) for u, v in graph.edges()) False """ @@ -2381,7 +2381,7 @@ def complement(self): for u, v in combinations(self.nodes(), 2): if not self.has_edge((u, v), directed=False): - graph.add_edge(u, v, attr_dict=self.edge_attributes((u, v))) + graph.add_edge(u, v) return graph diff --git a/src/compas/datastructures/mesh/duality.py b/src/compas/datastructures/mesh/duality.py index 16bf43c67d7..d1b17f85d27 100644 --- a/src/compas/datastructures/mesh/duality.py +++ b/src/compas/datastructures/mesh/duality.py @@ -37,7 +37,7 @@ def mesh_dual(mesh, cls=None, include_boundary=False): >>> mesh.delete_face(6) >>> mesh.delete_face(7) >>> mesh.quads_to_triangles() - >>> mesh = mesh.subdivide("corner") + >>> mesh = mesh.subdivided("corner") >>> dual = mesh.dual(include_boundary=True) """ @@ -78,7 +78,7 @@ def mesh_dual(mesh, cls=None, include_boundary=False): edge_vertex = {} for boundary in mesh.edges_on_boundaries(): for u, v in boundary: - x, y, z = mesh.edge_midpoint(u, v) + x, y, z = mesh.edge_midpoint((u, v)) edge_vertex[u, v] = edge_vertex[v, u] = dual.add_vertex(x=x, y=y, z=z) vertex_vertex = {} @@ -97,7 +97,7 @@ def mesh_dual(mesh, cls=None, include_boundary=False): nbrs = mesh.vertex_neighbors(vertex, ordered=True)[::-1] vertices.append(edge_vertex[vertex, nbrs[0]]) for nbr in nbrs[:-1]: - vertices.append(mesh.halfedge_face(vertex, nbr)) + vertices.append(mesh.halfedge_face((vertex, nbr))) vertices.append(edge_vertex[vertex, nbrs[-1]]) dual.add_face(vertices[::-1]) diff --git a/src/compas/datastructures/mesh/mesh.py b/src/compas/datastructures/mesh/mesh.py index c654d5095c8..885975ddfea 100644 --- a/src/compas/datastructures/mesh/mesh.py +++ b/src/compas/datastructures/mesh/mesh.py @@ -2855,6 +2855,9 @@ def remove_duplicate_vertices(self, precision=None): 36 >>> for x, y, z in mesh.vertices_attributes("xyz", keys=list(mesh.vertices())[:5]): ... mesh.add_vertex(x=x, y=y, z=z) + ... + 36 + 37 38 39 40 @@ -4791,9 +4794,9 @@ def transform_numpy(self, T): Examples -------- >>> from compas.datastructures import Mesh - >>> from compas.geometry import matrix_from_axis_and_angle_numpy + >>> from compas.geometry import matrix_from_axis_and_angle >>> mesh = Mesh.from_polyhedron(6) - >>> T = matrix_from_axis_and_angle_numpy([0, 0, 1], math.pi / 4) + >>> T = matrix_from_axis_and_angle([0, 0, 1], math.pi / 4) >>> mesh.transform_numpy(T) """ @@ -4906,9 +4909,9 @@ def face_matrix(self, rtype="array"): >>> type(F) - >>> from numpy import allclose + >>> from numpy import allclose, asarray >>> xyz = asarray(mesh.vertices_attributes('xyz')) - >>> F = mesh.face_matrix(mesh, rtype='csr') + >>> F = mesh.face_matrix(rtype='csr') >>> c1 = F.dot(xyz) / F.sum(axis=1) >>> c2 = [mesh.face_centroid(fkey) for fkey in mesh.faces()] >>> allclose(c1, c2) @@ -4963,10 +4966,11 @@ def laplacian_matrix(self, rtype="array"): -------- >>> from compas.datastructures import Mesh >>> mesh = Mesh.from_polyhedron(6) - >>> L = mesh.laplacian_matrix(mesh, rtype='array') + >>> L = mesh.laplacian_matrix(rtype='array') >>> type(L) + >>> from numpy import asarray >>> xyz = asarray(mesh.vertices_attributes('xyz')) >>> L = mesh.laplacian_matrix(mesh) >>> d = L.dot(xyz) @@ -5005,11 +5009,11 @@ def offset(self, distance=1.0): Examples -------- - >>> from compas.datastructures import Mesh, mesh_offset + >>> from compas.datastructures import Mesh >>> from compas.geometry import distance_point_point as dist >>> mesh = Mesh.from_vertices_and_faces([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], [[0, 1, 2, 3]]) - >>> mesh.offset() - + >>> mesh.offset() # doctest: +ELLIPSIS + """ offset = self.copy() @@ -5047,8 +5051,8 @@ def thickened(self, thickness=1.0, both=True): -------- >>> from compas.datastructures import Mesh >>> mesh = Mesh.from_vertices_and_faces([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], [[0, 1, 2, 3]]) - >>> mesh.thicken(mesh) - + >>> mesh.thickened() # doctest: +ELLIPSIS + """ if thickness <= 0: diff --git a/src/compas/datastructures/mesh/operations/merge.py b/src/compas/datastructures/mesh/operations/merge.py index 3a0f91cf55a..17dbc185564 100644 --- a/src/compas/datastructures/mesh/operations/merge.py +++ b/src/compas/datastructures/mesh/operations/merge.py @@ -21,7 +21,7 @@ def mesh_merge_faces(mesh, faces): -------- >>> from compas.datastructures import Mesh >>> mesh = Mesh.from_vertices_and_faces([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]], [[0, 1, 2, 3]]) - >>> mesh = mesh.subdivide(scheme="quad") + >>> mesh = mesh.subdivided(scheme='quad') >>> mesh_merge_faces(mesh, [1, 2]) 5 >>> mesh_merge_faces(mesh, [3, 5]) diff --git a/src/compas/datastructures/mesh/subdivision.py b/src/compas/datastructures/mesh/subdivision.py index 144052a1924..375c48eff78 100644 --- a/src/compas/datastructures/mesh/subdivision.py +++ b/src/compas/datastructures/mesh/subdivision.py @@ -313,7 +313,7 @@ def mesh_subdivide_catmullclark(mesh, k=1, fixed=None): >>> top = sorted(cage.faces(), key=lambda face: dot_vectors(cage.face_normal(face), [0, 0, 1]))[-1] >>> cage.edges_attribute("crease", 5, keys=list(cage.face_halfedges(top))) - >>> subd = cage.subdivide(k=4) + >>> subd = cage.subdivided(k=4) """ cls = type(mesh) diff --git a/src/compas/datastructures/tree/tree.py b/src/compas/datastructures/tree/tree.py index 524c35d28d0..458dfda9532 100644 --- a/src/compas/datastructures/tree/tree.py +++ b/src/compas/datastructures/tree/tree.py @@ -244,10 +244,10 @@ class Tree(Datastructure): >>> branch.add(leaf2) >>> print(tree) - |-- - |-- - |-- - |-- + └── + └── + ├── + └── """ diff --git a/src/compas/geometry/_core/_algebra.py b/src/compas/geometry/_core/_algebra.py index b8ecfb5176e..902bd29bf72 100644 --- a/src/compas/geometry/_core/_algebra.py +++ b/src/compas/geometry/_core/_algebra.py @@ -2768,12 +2768,6 @@ def close(value1, value2, tol=1e-05): It is more accurate to use a combination of absolute and relative tolerance. Therefor, use :func:`TOL.is_close` instead. - Examples - -------- - >>> close(1.0, 1.001) - False - >>> close(1.0, 1.001, tol=1e-2) - True """ return TOL.is_close(value1, value2, rtol=0.0, atol=tol) @@ -2815,13 +2809,5 @@ def allclose(l1, l2, tol=None): ---------- .. [1] https://docs.scipy.org/doc/numpy/reference/generated/numpy.allclose.html - Examples - -------- - >>> allclose([0.1, 0.2, 0.3, 0.4], [0.1, 0.20001, 0.3, 0.4]) - True - - >>> allclose([0.1, 0.2, 0.3, 0.4], [0.1, 0.20001, 0.3, 0.4], tol=1e-6) - False - """ return TOL.is_allclose(l1, l2, atol=tol) diff --git a/src/compas/geometry/_core/transformations.py b/src/compas/geometry/_core/transformations.py index e55cabc9fb3..0e0080e0ddb 100644 --- a/src/compas/geometry/_core/transformations.py +++ b/src/compas/geometry/_core/transformations.py @@ -287,8 +287,8 @@ def world_to_local_coordinates(frame, xyz): >>> from compas.geometry import Point, Frame >>> f = Frame([0, 1, 0], [3, 4, 1], [1, 5, 9]) >>> xyz = [Point(2, 3, 5)] - >>> Point(*world_to_local_coordinates(f, xyz)[0]) - Point(3.726, 4.088, 1.550) + >>> print(Point(*world_to_local_coordinates(f, xyz)[0])) + Point(x=3.726, y=4.088, z=1.550) """ from compas.geometry import Frame # noqa: F811 @@ -317,8 +317,8 @@ def local_to_world_coordinates(frame, xyz): >>> from compas.geometry import Point, Frame >>> f = Frame([0, 1, 0], [3, 4, 1], [1, 5, 9]) >>> xyz = [Point(3.726, 4.088, 1.550)] - >>> Point(*local_to_world_coordinates(f, xyz)[0]) - Point(2.000, 3.000, 5.000) + >>> print(Point(*local_to_world_coordinates(f, xyz)[0])) + Point(x=2.000, y=3.000, z=5.000) """ from compas.geometry import Frame # noqa: F811 @@ -347,10 +347,6 @@ def translate_points(points, vector): list[[float, float, float]] The translated points. - Examples - -------- - >>> - """ return [add_vectors(point, vector) for point in points] @@ -370,10 +366,6 @@ def translate_points_xy(points, vector): list[[float, float, float]] The translated points in the XY plane (Z=0). - Examples - -------- - >>> - """ return [add_vectors_xy(point, vector) for point in points] @@ -398,10 +390,6 @@ def scale_points(points, scale): list[[float, float, float]] The scaled points. - Examples - -------- - >>> - """ T = matrix_from_scale_factors([scale, scale, scale]) return transform_points(points, T) @@ -422,10 +410,6 @@ def scale_points_xy(points, scale): list[[float, float, float]] The scaled points in the XY plane (Z=0). - Examples - -------- - >>> - """ T = matrix_from_scale_factors([scale, scale, 0]) return transform_points(points, T) @@ -466,10 +450,6 @@ def rotate_points(points, angle, axis=None, origin=None): .. [1] Wikipedia. *Rotation matrix*. Available at: https://en.wikipedia.org/wiki/Rotation_matrix. - Examples - -------- - >>> - """ if axis is None: axis = [0.0, 0.0, 1.0] @@ -499,10 +479,6 @@ def rotate_points_xy(points, angle, origin=None): list[[float, float, 0.0]] The rotated points in the XY plane (Z=0). - Examples - -------- - >>> - """ if not origin: origin = [0.0, 0.0, 0.0] @@ -1104,8 +1080,8 @@ def orient_points(points, reference_plane, target_plane): >>> point = intersection_segment_segment_xy(ab, cd) >>> points = orient_points([point], tarplane, refplane) - >>> Point(*points[0]) - Point(0.577, 0.577, 0.577) + >>> print(Point(*points[0])) + Point(x=0.577, y=0.577, z=0.577) """ axis = cross_vectors(reference_plane[1], target_plane[1]) diff --git a/src/compas/geometry/booleans.py b/src/compas/geometry/booleans.py index 0e3d51aef59..5ed22c70402 100644 --- a/src/compas/geometry/booleans.py +++ b/src/compas/geometry/booleans.py @@ -45,7 +45,7 @@ def boolean_union_mesh_mesh(A, B): >>> box = Mesh.from_shape(box) >>> box.quads_to_triangles() - >>> sphere = Sphere([1, 1, 1], 1) + >>> sphere = Sphere(1, point=[1, 1, 1]) >>> sphere = Mesh.from_shape(sphere, u=30, v=30) >>> sphere.quads_to_triangles() diff --git a/src/compas/geometry/curves/bezier.py b/src/compas/geometry/curves/bezier.py index bf3d2e4f67f..edafd01b94c 100644 --- a/src/compas/geometry/curves/bezier.py +++ b/src/compas/geometry/curves/bezier.py @@ -74,7 +74,7 @@ def bernstein_polynomial(n, k, t): Examples -------- - >>> bernstein(3, 2, 0.5) + >>> bernstein_polynomial(3, 2, 0.5) 0.375 """ @@ -157,8 +157,8 @@ class Bezier(Curve): Note that the input control points are automatically converted to COMPAS points. - >>> curve.points - [Point(0.000, 0.000, 0.000), Point(0.500, 1.000, 0.000), Point(1.000, 0.000, 0.000)] + >>> print(curve.points) + [Point(x=0.000, y=0.000, z=0.000), Point(x=0.500, y=1.000, z=0.000), Point(x=1.000, y=0.000, z=0.000)] """ @@ -265,10 +265,10 @@ def point_at(self, t): Examples -------- >>> curve = Bezier([[0.0, 0.0, 0.0], [0.5, 1.0, 0.0], [1.0, 0.0, 0.0]]) - >>> curve.point_at(0.0) - Point(0.000, 0.000, 0.000) - >>> curve.point_at(1.0) - Point(1.000, 0.000, 0.000) + >>> print(curve.point_at(0.0)) + Point(x=0.000, y=0.000, z=0.000) + >>> print(curve.point_at(1.0)) + Point(x=1.000, y=0.000, z=0.000) """ n = self.degree @@ -298,8 +298,8 @@ def tangent_at(self, t): Examples -------- >>> curve = Bezier([[0.0, 0.0, 0.0], [0.5, 1.0, 0.0], [1.0, 0.0, 0.0]]) - >>> curve.tangent_at(0.5) - Vector(1.000, 0.000, 0.000) + >>> print(curve.tangent_at(0.5)) + Vector(x=1.000, y=0.000, z=0.000) """ n = self.degree @@ -329,8 +329,8 @@ def normal_at(self, t): Examples -------- >>> curve = Bezier([[0.0, 0.0, 0.0], [0.5, 1.0, 0.0], [1.0, 0.0, 0.0]]) - >>> curve.normal_at(0.5) - Vector(0.000, 0.000, 1.000) + >>> print(curve.normal_at(0.5)) + Vector(x=0.000, y=-1.000, z=0.000) """ tangent = self.tangent_at(t) diff --git a/src/compas/geometry/curves/hyperbola.py b/src/compas/geometry/curves/hyperbola.py index 54f6120f918..ef3c952a82f 100644 --- a/src/compas/geometry/curves/hyperbola.py +++ b/src/compas/geometry/curves/hyperbola.py @@ -99,19 +99,19 @@ class Hyperbola(Conic): Construct a hyperbola such that the Z axis of its frame aligns with a given line. - >>> from compas.geometry import Line, Frame, Hyperbola + >>> from compas.geometry import Line, Plane, Frame, Hyperbola >>> line = Line([0, 0, 0], [1, 1, 1]) >>> plane = Plane(line.end, line.direction) >>> hyperbola = Hyperbola(major=3, minor=2, frame=Frame.from_plane(plane)) Visualise the line, hyperbola, and frame of the hyperbola with the COMPAS viewer. - >>> from compas_viewer import Viewer # doctest: +SKIP - >>> viewer = Viewer() # doctest: +SKIP - >>> viewer.scene.add(line) # doctest: +SKIP + >>> from compas_viewer import Viewer # doctest: +SKIP + >>> viewer = Viewer() # doctest: +SKIP + >>> viewer.scene.add(line) # doctest: +SKIP >>> viewer.scene.add(hyperbola) # doctest: +SKIP >>> viewer.scene.add(hyperbola.frame) # doctest: +SKIP - >>> viewer.show() # doctest: +SKIP + >>> viewer.show() # doctest: +SKIP """ diff --git a/src/compas/geometry/curves/line.py b/src/compas/geometry/curves/line.py index ebbcf5c7b42..f715b47e0a1 100644 --- a/src/compas/geometry/curves/line.py +++ b/src/compas/geometry/curves/line.py @@ -55,16 +55,14 @@ class Line(Curve): Examples -------- >>> line = Line([0, 0, 0], [1, 1, 1]) - >>> line - Line(Point(0.000, 0.000, 0.000), Point(1.000, 1.000, 1.000)) - >>> line.start - Point(0.000, 0.000, 0.000) - >>> line.midpoint - Point(0.500, 0.500, 0.500) - >>> line.length == math.sqrt(line.dx**2 + line.dy**2 + line.dz**2) + >>> print(line.start) + Point(x=0.000, y=0.000, z=0.000) + >>> print(line.midpoint) + Point(x=0.500, y=0.500, z=0.500) + >>> line.length == line.vector.length True - >>> line.direction - Vector(0.577, 0.577, 0.577) + >>> print(line.direction) + Vector(x=0.577, y=0.577, z=0.577) """ @@ -222,8 +220,10 @@ def from_point_and_vector(cls, point, vector): -------- >>> from compas.geometry import Point, Vector >>> line = Line.from_point_and_vector(Point(0, 0, 0), Vector(1, 1, 1)) - >>> line - Line(Point(0.000, 0.000, 0.000), Point(1.000, 1.000, 1.000)) + >>> print(line.start) + Point(x=0.000, y=0.000, z=0.000) + >>> print(line.end) + Point(x=1.000, y=1.000, z=1.000) """ return cls(point, add_vectors(point, vector)) @@ -254,8 +254,10 @@ def from_point_direction_length(cls, point, direction, length): -------- >>> from compas.geometry import Point, Vector >>> line = Line.from_point_direction_length(Point(0, 0, 0), Vector(1, 1, 1), 1) - >>> line - Line(Point(0.000, 0.000, 0.000), Point(0.577, 0.577, 0.577)) + >>> print(line.start) + Point(x=0.000, y=0.000, z=0.000) + >>> print(line.end) + Point(x=0.577, y=0.577, z=0.577) """ direction = Vector(*direction) @@ -285,8 +287,8 @@ def transform(self, T): >>> line = Line([0.0, 0.0, 0.0], [1.0, 0.0, 0.0]) >>> R = Rotation.from_axis_and_angle([0.0, 0.0, 1.0], radians(90)) >>> line.transform(R) - >>> line.end - Point(0.000, 1.000, 0.000) + >>> print(line.end) + Point(x=0.000, y=1.000, z=0.000) """ self.point.transform(T) @@ -318,8 +320,8 @@ def point_at(self, t): Examples -------- >>> line = Line([0, 0, 0], [1, 1, 1]) - >>> line.point_at(0.5) - Point(0.500, 0.500, 0.500) + >>> print(line.point_at(0.5)) + Point(x=0.500, y=0.500, z=0.500) """ point = self.point + self.vector * t diff --git a/src/compas/geometry/curves/parabola.py b/src/compas/geometry/curves/parabola.py index 2935c7cda0e..94ada5576bb 100644 --- a/src/compas/geometry/curves/parabola.py +++ b/src/compas/geometry/curves/parabola.py @@ -65,7 +65,7 @@ class Parabola(Conic): Construct a parabola such that the Z axis of its frame aligns with a given line. - >>> from compas.geometry import Frame, Line, Parabola + >>> from compas.geometry import Frame, Line, Plane, Parabola >>> line = Line([0, 0, 0], [1, 1, 1]) >>> plane = Plane(line.end, line.direction) >>> frame = Frame.from_plane(plane) @@ -73,12 +73,12 @@ class Parabola(Conic): Visualize the parabola with the COMPAS viewer. - >>> from compas_viewer import Viewer # doctest: +SKIP - >>> viewer = Viewer() # doctest: +SKIP - >>> viewer.scene.add(line) # doctest: +SKIP - >>> viewer.scene.add(parabola) # doctest: +SKIP - >>> viewer.scene.add(parabola.frame) # doctest: +SKIP - >>> viewer.show() # doctest: +SKIP + >>> from compas_viewer import Viewer # doctest: +SKIP + >>> viewer = Viewer() # doctest: +SKIP + >>> viewer.scene.add(line) # doctest: +SKIP + >>> viewer.scene.add(parabola) # doctest: +SKIP + >>> viewer.scene.add(parabola.frame) # doctest: +SKIP + >>> viewer.show() # doctest: +SKIP """ diff --git a/src/compas/geometry/curves/polyline.py b/src/compas/geometry/curves/polyline.py index 366db032a8f..55c4069f063 100644 --- a/src/compas/geometry/curves/polyline.py +++ b/src/compas/geometry/curves/polyline.py @@ -245,8 +245,8 @@ def point_at(self, t, snap=False): Examples -------- >>> polyline = Polyline([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0]]) - >>> polyline.point(0.75) - Point(1.000, 0.500, 0.000) + >>> polyline.point_at(0.75) + Point(x=1.000, y=0.500, z=0.000) """ if t < 0 or t > 1: @@ -297,7 +297,7 @@ def parameter_at(self, point, tol=None): >>> from compas.geometry import Point >>> polyline = Polyline([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0]]) >>> polyline.parameter_at(Point(0.1, 0.0, 0.0)) - 0.5 + 0.05 """ if not is_point_on_polyline(point, self, tol): @@ -327,8 +327,8 @@ def tangent_at(self, t): Examples -------- >>> polyline = Polyline([[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0]]) - >>> polyline.tangent(0.75) - Vector(0.000, 1.000, 0.000) + >>> print(polyline.tangent_at(0.75)) + Vector(x=0.000, y=1.000, z=0.000) """ if t < 0 or t > 1: @@ -453,15 +453,14 @@ def divide(self, num_segments): Examples -------- >>> polyline = Polyline([(0, 0, 0), (1, 1, 0), (2, 3, 0), (4, 4, 0), (5, 2, 0)]) - >>> divided_polylines = polyline.divide(3) - >>> divided_polyline - [Point(0.000, 0.000, 0.000), Point(1.578, 2.157, 0.000), Point(3.578, 3.789, 0.000), Point(5.000, 2.000, 0.000)] + >>> len(polyline.divide(3)) + 4 """ segment_length = self.length / num_segments return self.divide_by_length(segment_length, False) - def divide_by_length(self, length, strict=True, tol=1e-06): + def divide_by_length(self, length, strict=True, tol=None): """Divide a polyline in segments of a given length. Parameters @@ -472,6 +471,7 @@ def divide_by_length(self, length, strict=True, tol=1e-06): If False, the remainder segment will be added even if it is smaller than the desired length tol : float, optional Floating point error tolerance. + Defaults to `TOL.absolute`. Returns ------- @@ -485,16 +485,16 @@ def divide_by_length(self, length, strict=True, tol=1e-06): Examples -------- >>> polyline = Polyline([(0, 0, 0), (1, 1, 0), (2, 3, 0), (4, 4, 0), (5, 2, 0)]) - >>> divided_polylines = polyline.divide_by_length(3) - >>> divided_polyline - [Point(0.000, 0.000, 0.000), Point(1.709, 2.418, 0.000), Point(4.051, 3.898, 0.000)] + >>> len(polyline.divide_by_length(3)) + 3 >>> polyline = Polyline([(0, 0, 0), (1, 1, 0), (2, 3, 0), (4, 4, 0), (5, 2, 0)]) - >>> divided_polylines = polyline.divide_by_length(3, strict=False) - >>> divided_polyline - [Point(0.000, 0.000, 0.000), Point(1.709, 2.418, 0.000), Point(4.051, 3.898, 0.000), Point(5.000, 2.000, 0.000)] + >>> len(polyline.divide_by_length(3, strict=False)) + 4 """ + tol = tol or TOL.absolute + num_pts = int(self.length / length) total_length = [0, 0] division_pts = [self.points[0]] @@ -545,19 +545,13 @@ def split_by_length(self, length, strict=True): -------- >>> from compas.geometry import Polyline >>> polyline = Polyline([(0, 0, 0), (1, 1, 0), (2, 3, 0), (4, 4, 0), (5, 2, 0)]) - >>> split_polylines = polyline.split_polyline_by_length(3) - >>> split_polylines - [Polyline([Point(0.000, 0.000, 0.000), Point(1.000, 1.000, 0.000), Point(1.709, 2.418, 0.000)]),\ - Polyline([Point(1.709, 2.418, 0.000), Point(2.000, 3.000, 0.000), Point(4.000, 4.000, 0.000),\ - Point(4.051, 3.898, 0.000)])] + >>> len(polyline.split_by_length(3)) + 2 >>> from compas.geometry import Polyline >>> polyline = Polyline([(0, 0, 0), (1, 1, 0), (2, 3, 0), (4, 4, 0), (5, 2, 0)]) - >>> split_polylines = polyline.split_polyline_by_length(3, strict=False) - >>> split_polylines - [Polyline([Point(0.000, 0.000, 0.000), Point(1.000, 1.000, 0.000), Point(1.709, 2.418, 0.000)]),\ - Polyline([Point(1.709, 2.418, 0.000), Point(2.000, 3.000, 0.000), Point(4.000, 4.000, 0.000),\ - Point(4.051, 3.898, 0.000)]), Polyline([Point(4.051, 3.898, 0.000), Point(5.000, 2.000, 0.000)])] + >>> len(polyline.split_by_length(3, strict=False)) + 3 """ if length <= 0: @@ -606,11 +600,10 @@ def split(self, num_segments): -------- >>> from compas.geometry import Polyline >>> polyline = Polyline([(0, 0, 0), (1, 1, 0), (2, 3, 0), (4, 4, 0), (5, 2, 0)]) - >>> split_polylines = polyline.split_polyline(3) - >>> split_polylines - [Polyline([Point(0.000, 0.000, 0.000), Point(1.000, 1.000, 0.000), Point(1.578, 2.157, 0.000)]),\ - Polyline([Point(1.578, 2.157, 0.000), Point(2.000, 3.000, 0.000), Point(3.578, 3.789, 0.000)]),\ - Polyline([Point(3.578, 3.789, 0.000), Point(4.000, 4.000, 0.000), Point(5.000, 2.000, 0.000)])] + >>> polylines = polyline.split(3) + >>> len(polylines) + 3 + """ if num_segments < 1: raise ValueError("Number of segments must be greater than or equal to 1.") diff --git a/src/compas/geometry/frame.py b/src/compas/geometry/frame.py index fb93ea4a30c..84eb0f0c7c5 100644 --- a/src/compas/geometry/frame.py +++ b/src/compas/geometry/frame.py @@ -220,12 +220,12 @@ def worldXY(cls): # type: () -> Frame Examples -------- >>> frame = Frame.worldXY() - >>> frame.point - Point(0.000, 0.000, 0.000) - >>> frame.xaxis - Vector(1.000, 0.000, 0.000) - >>> frame.yaxis - Vector(0.000, 1.000, 0.000) + >>> print(frame.point) + Point(x=0.000, y=0.000, z=0.000) + >>> print(frame.xaxis) + Vector(x=1.000, y=0.000, z=0.000) + >>> print(frame.yaxis) + Vector(x=0.000, y=1.000, z=0.000) """ return cls([0, 0, 0], [1, 0, 0], [0, 1, 0]) @@ -242,12 +242,12 @@ def worldZX(cls): # type: () -> Frame Examples -------- >>> frame = Frame.worldZX() - >>> frame.point - Point(0.000, 0.000, 0.000) - >>> frame.xaxis - Vector(0.000, 0.000, 1.000) - >>> frame.yaxis - Vector(1.000, 0.000, 0.000) + >>> print(frame.point) + Point(x=0.000, y=0.000, z=0.000) + >>> print(frame.xaxis) + Vector(x=0.000, y=0.000, z=1.000) + >>> print(frame.yaxis) + Vector(x=1.000, y=0.000, z=0.000) """ return cls([0, 0, 0], [0, 0, 1], [1, 0, 0]) @@ -264,12 +264,12 @@ def worldYZ(cls): # type: () -> Frame Examples -------- >>> frame = Frame.worldYZ() - >>> frame.point - Point(0.000, 0.000, 0.000) - >>> frame.xaxis - Vector(0.000, 1.000, 0.000) - >>> frame.yaxis - Vector(0.000, 0.000, 1.000) + >>> print(frame.point) + Point(x=0.000, y=0.000, z=0.000) + >>> print(frame.xaxis) + Vector(x=0.000, y=1.000, z=0.000) + >>> print(frame.yaxis) + Vector(x=0.000, y=0.000, z=1.000) """ return cls([0, 0, 0], [0, 1, 0], [0, 0, 1]) @@ -295,12 +295,12 @@ def from_points(cls, point, point_xaxis, point_xyplane): # type: (...) -> Frame Examples -------- >>> frame = Frame.from_points([0, 0, 0], [1, 0, 0], [0, 1, 0]) - >>> frame.point - Point(0.000, 0.000, 0.000) - >>> frame.xaxis - Vector(1.000, 0.000, 0.000) - >>> frame.yaxis - Vector(0.000, 1.000, 0.000) + >>> print(frame.point) + Point(x=0.000, y=0.000, z=0.000) + >>> print(frame.xaxis) + Vector(x=1.000, y=0.000, z=0.000) + >>> print(frame.yaxis) + Vector(x=0.000, y=1.000, z=0.000) """ xaxis = subtract_vectors(point_xaxis, point) @@ -383,11 +383,12 @@ def from_matrix(cls, matrix): # type: (...) -> Frame Examples -------- >>> from compas.geometry import matrix_from_euler_angles + >>> from compas.tolerance import TOL >>> ea1 = [0.5, 0.4, 0.8] >>> M = matrix_from_euler_angles(ea1) >>> f = Frame.from_matrix(M) >>> ea2 = f.euler_angles() - >>> allclose(ea1, ea2) + >>> TOL.is_allclose(ea1, ea2) True """ @@ -456,10 +457,11 @@ def from_quaternion(cls, quaternion, point=[0, 0, 0]): # type: (...) -> Frame Examples -------- + >>> from compas.tolerance import TOL >>> q1 = [0.945, -0.021, -0.125, 0.303] >>> f = Frame.from_quaternion(q1, point=[1.0, 1.0, 1.0]) >>> q2 = f.quaternion - >>> allclose(q1, q2) + >>> TOL.is_allclose(q1, q2, atol=1e-3) True """ @@ -486,10 +488,11 @@ def from_axis_angle_vector(cls, axis_angle_vector, point=[0, 0, 0]): # type: (. Examples -------- + >>> from compas.tolerance import TOL >>> aav1 = [-0.043, -0.254, 0.617] >>> f = Frame.from_axis_angle_vector(aav1, point=[0, 0, 0]) >>> aav2 = f.axis_angle_vector - >>> allclose(aav1, aav2) + >>> TOL.is_allclose(aav1, aav2, atol=1e-3) True """ @@ -520,10 +523,11 @@ def from_euler_angles(cls, euler_angles, static=True, axes="xyz", point=[0, 0, 0 Examples -------- + >>> from compas.tolerance import TOL >>> ea1 = 1.4, 0.5, 2.3 - >>> f = Frame.from_euler_angles(ea1, static=True, axes="xyz") - >>> ea2 = f.euler_angles(static=True, axes="xyz") - >>> allclose(ea1, ea2) + >>> f = Frame.from_euler_angles(ea1, static=True, axes='xyz') + >>> ea2 = f.euler_angles(static=True, axes='xyz') + >>> TOL.is_allclose(ea1, ea2) True """ @@ -550,9 +554,10 @@ def from_plane(cls, plane): # type: (...) -> Frame Examples -------- >>> from compas.geometry import Plane - >>> plane = Plane([0, 0, 0], [0, 0, 1]) + >>> from compas.tolerance import TOL + >>> plane = Plane([0,0,0], [0,0,1]) >>> frame = Frame.from_plane(plane) - >>> allclose(frame.normal, plane.normal) + >>> TOL.is_allclose(frame.normal, plane.normal) True """ @@ -607,10 +612,11 @@ def interpolate_frame(self, other, t): Examples -------- + >>> from compas.tolerance import TOL >>> frame1 = Frame(Point(0, 0, 0), Vector(1, 0, 0), Vector(0, 1, 0)) >>> frame2 = Frame(Point(1, 1, 1), Vector(0, 0, 1), Vector(0, 1, 0)) >>> start_frame = frame1.interpolate_frame(frame2, 0) - >>> allclose(start_frame.point, frame1.point) and allclose(start_frame.quaternion, frame1.quaternion) + >>> TOL.is_allclose(start_frame.point, frame1.point) and TOL.is_allclose(start_frame.quaternion, frame1.quaternion) True """ quat1 = Quaternion.from_frame(self) @@ -645,7 +651,7 @@ def interpolate_frames(self, other, steps): >>> frame2 = Frame(Point(1, 1, 1), Vector(0, 0, 1), Vector(0, 1, 0)) >>> steps = 5 >>> frames = frame1.interpolate_frames(frame2, steps) - >>> assert len(frames) == steps + >>> print(len(frames) == steps) True """ return [self.interpolate_frame(other, t) for t in linspace(0, 1, steps)] @@ -668,10 +674,11 @@ def euler_angles(self, static=True, axes="xyz"): Examples -------- + >>> from compas.tolerance import TOL >>> ea1 = 1.4, 0.5, 2.3 - >>> f = Frame.from_euler_angles(ea1, static=True, axes="xyz") - >>> ea2 = f.euler_angles(static=True, axes="xyz") - >>> allclose(ea1, ea2) + >>> f = Frame.from_euler_angles(ea1, static=True, axes='xyz') + >>> ea2 = f.euler_angles(static=True, axes='xyz') + >>> TOL.is_allclose(ea1, ea2) True """ @@ -699,10 +706,10 @@ def to_local_coordinates(self, obj_in_wcf): -------- >>> from compas.geometry import Point >>> frame = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15]) - >>> pw = Point(2, 2, 2) # point in wcf + >>> pw = Point(2, 2, 2) # point in wcf >>> pl = frame.to_local_coordinates(pw) # point in frame - >>> frame.to_world_coordinates(pl) - Point(2.000, 2.000, 2.000) + >>> print(frame.to_world_coordinates(pl)) + Point(x=2.000, y=2.000, z=2.000) """ T = Transformation.from_change_of_basis(Frame.worldXY(), self) @@ -731,10 +738,10 @@ def to_world_coordinates(self, obj_in_lcf): -------- >>> from compas.geometry import Point >>> frame = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15]) - >>> pl = Point(1.632, -0.090, 0.573) # point in frame - >>> pw = frame.to_world_coordinates(pl) # point in wcf - >>> frame.to_local_coordinates(pw) - Point(1.632, -0.090, 0.573) + >>> pl = Point(1.632, -0.090, 0.573) # point in frame + >>> pw = frame.to_world_coordinates(pl) # point in wcf + >>> print(frame.to_local_coordinates(pw)) + Point(x=1.632, y=-0.090, z=0.573) """ T = Transformation.from_change_of_basis(self, Frame.worldXY()) diff --git a/src/compas/geometry/intersection.py b/src/compas/geometry/intersection.py index 06aba837a4f..5ff2721a7b1 100644 --- a/src/compas/geometry/intersection.py +++ b/src/compas/geometry/intersection.py @@ -18,15 +18,15 @@ class Intersection(object): Examples -------- - >>> from compas.geometry import Line - >>> from compas.geometry import Intersection - >>> a = Line([0, 0, 0], [2, 0, 0]) - >>> b = Line([1, 0, 0], [1, 1, 0]) - >>> intersection = Intersection() - >>> intersection.line_line(a, b) - >>> intersection.number_of_intersections + >>> from compas.geometry import Line # doctest: +SKIP + >>> from compas.geometry import Intersection # doctest: +SKIP + >>> a = Line([0, 0, 0], [2, 0, 0]) # doctest: +SKIP + >>> b = Line([1, 0, 0], [1, 1, 0]) # doctest: +SKIP + >>> intersection = Intersection() # doctest: +SKIP + >>> intersection.line_line(a, b) # doctest: +SKIP + >>> intersection.number_of_intersections # doctest: +SKIP 1 - >>> intersection.points[0] + >>> intersection.points[0] # doctest: +SKIP Point(1.0, 0.0, z=0.0) """ diff --git a/src/compas/geometry/intersections.py b/src/compas/geometry/intersections.py index 25af7d3c794..851d80ddc58 100644 --- a/src/compas/geometry/intersections.py +++ b/src/compas/geometry/intersections.py @@ -493,8 +493,8 @@ def intersection_sphere_sphere(sphere1, sphere2): """ - center1, radius1 = sphere1.base, sphere1.radius - center2, radius2 = sphere2.base, sphere2.radius + center1, radius1 = sphere1 + center2, radius2 = sphere2 distance = distance_point_point(center1, center2) diff --git a/src/compas/geometry/offset.py b/src/compas/geometry/offset.py index 2924dea68e6..b41c093ca87 100644 --- a/src/compas/geometry/offset.py +++ b/src/compas/geometry/offset.py @@ -138,7 +138,7 @@ def offset_polygon(polygon, distance, tol=None): >>> polygon = Polygon([(0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)]) >>> offsetted_polygon = offset_polygon(polygon, 0.5) >>> offsetted_polygon - Polygon[[0.5, 0.5, 0.0], [0.5, 0.5, 0.0], [0.5, 0.5, 0.0], [0.5, 0.5, 0.0]] + [[0.5, 0.5, 0.0], [0.5, 0.5, 0.0], [0.5, 0.5, 0.0], [0.5, 0.5, 0.0]] """ normal = normal_polygon(polygon) diff --git a/src/compas/geometry/plane.py b/src/compas/geometry/plane.py index 2cebbafb943..3a05abc0f7f 100644 --- a/src/compas/geometry/plane.py +++ b/src/compas/geometry/plane.py @@ -39,10 +39,10 @@ class Plane(Geometry): Examples -------- >>> plane = Plane([0, 0, 0], [0, 0, 1]) - >>> plane.point - Point(0.000, 0.000, 0.000) - >>> plane.normal - Vector(0.000, 0.000, 1.000) + >>> print(plane.point) + Point(x=0.000, y=0.000, z=0.000) + >>> print(plane.normal) + Vector(x=0.000, y=0.000, z=1.000) """ @@ -164,10 +164,10 @@ def from_three_points(cls, a, b, c): # type: (...) -> Plane Examples -------- >>> plane = Plane.from_three_points([0.0, 0.0, 0.0], [2.0, 1.0, 0.0], [0.0, 3.0, 0.0]) - >>> plane.point - Point(0.000, 0.000, 0.000) - >>> plane.normal - Vector(0.000, 0.000, 1.000) + >>> print(plane.point) + Point(x=0.000, y=0.000, z=0.000) + >>> print(plane.normal) + Vector(x=0.000, y=0.000, z=1.000) """ a = Point(*a) @@ -198,10 +198,10 @@ def from_point_and_two_vectors(cls, point, u, v): # type: (...) -> Plane Examples -------- >>> plane = Plane.from_point_and_two_vectors([0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [0.0, 1.0, 0.0]) - >>> plane.point - Point(0.000, 0.000, 0.000) - >>> plane.normal - Vector(0.000, 0.000, 1.000) + >>> print(plane.point) + Point(x=0.000, y=0.000, z=0.000) + >>> print(plane.normal) + Vector(x=0.000, y=0.000, z=1.000) """ normal = Vector(*cross_vectors(u, v)) @@ -276,8 +276,11 @@ def from_frame(cls, frame): # type: (...) -> Plane -------- >>> from compas.geometry import Frame >>> frame = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15]) - >>> Plane.from_frame(frame) - Plane(Point(1.000, 1.000, 1.000), Vector(-0.299, -0.079, 0.951)) + >>> plane = Plane.from_frame(frame) + >>> print(plane.point) + Point(x=1.000, y=1.000, z=1.000) + >>> print(plane.normal) # doctest: +SKIP + Vector(x=-0.299, y=-0.079, z=0.951)) """ return cls(frame.point, frame.normal) @@ -306,10 +309,10 @@ def from_points(cls, points): # type: (...) -> Plane -------- >>> points = [[0.0, 0.0, 0.0], [2.0, 1.0, 0.0], [0.0, 3.0, 0.0]] >>> plane = Plane.from_points(points) - >>> plane.point - Point(0.000, 0.000, 0.000) - >>> plane.normal - Vector(0.000, 0.000, 1.000) + >>> print(plane.point) + Point(x=0.000, y=0.000, z=0.000) + >>> print(plane.normal) + Vector(x=0.000, y=0.000, z=1.000) """ if len(points) == 3: @@ -476,10 +479,12 @@ def closest_point(self, point): Examples -------- >>> plane = Plane.worldXY() - >>> plane.closest_point([1.0, 1.0, 1.0]) - Point(1.000, 1.000, 0.000) + >>> point = plane.closest_point([1.0, 1.0, 1.0]) + >>> print(point) + Point(x=1.000, y=1.000, z=0.000) """ + point = Point(*point) vector = self.point - point distance = self.normal.dot(vector) return point + self.normal.scaled(distance) @@ -503,8 +508,9 @@ def projected_point(self, point, direction=None): Examples -------- >>> plane = Plane.worldXY() - >>> plane.projected_point([1.0, 1.0, 1.0]) - Point(1.000, 1.000, 0.000) + >>> point = plane.projected_point([1.0, 1.0, 1.0]) + >>> print(point) + Point(x=1.000, y=1.000, z=0.000) """ if not direction: @@ -535,10 +541,12 @@ def mirrored_point(self, point): Examples -------- >>> plane = Plane.worldXY() - >>> plane.mirrored_point([1.0, 1.0, 1.0]) - Point(1.000, 1.000, -1.000) + >>> point = plane.mirrored_point([1.0, 1.0, 1.0]) + >>> print(point) + Point(x=1.000, y=1.000, z=-1.000) """ + point = Point(*point) vector = self.point - point distance = self.normal.dot(vector) return point + self.normal.scaled(2 * distance) @@ -561,10 +569,12 @@ def intersection_with_line(self, line, tol=None): Examples -------- + >>> from compas.geometry import Line >>> plane = Plane.worldXY() - >>> line = Line(Point(0, 0, 1), Vector(1, 1, 1)) - >>> plane.intersection_with_line(line) - Point(0.000, 0.000, 0.000) + >>> line = Line.from_point_and_vector(Point(0, 0, 1), Vector(1, 1, 1)) + >>> point = plane.intersection_with_line(line) + >>> print(point) + Point(x=-1.000, y=-1.000, z=0.000) """ # The line is parallel to the plane @@ -591,8 +601,7 @@ def intersection_with_plane(self, plane): -------- >>> plane1 = Plane.worldXY() >>> plane2 = Plane([1.0, 1.0, 1.0], [0.0, 0.0, 1.0]) - >>> plane1.intersection(plane2) - Line(Point(0.000, 0.000, 0.000), Vector(0.000, 0.000, 1.000)) + >>> line = plane1.intersection_with_plane(plane2) """ from compas.geometry import Line @@ -625,18 +634,24 @@ def intersections_with_curve(self, curve, tol=None): list of :class:`compas.geometry.Point` The intersection points. - Examples - -------- - >>> plane = Plane.worldXY() - >>> line = Line(Point(0, 0, 1), Vector(1, 1, 1)) - >>> plane.intersection_with_curve(line) - [Point(0.000, 0.000, 0.000)] - """ - pass + raise NotImplementedError def intersections_with_surface(self, surface): - pass + """Compute the intersection of a plane and a surface. + + Parameters + ---------- + surface : :class:`compas.geometry.Surface` + The surface. + + Returns + ------- + list of :class:`compas.geometry.Point` + The intersection points. + + """ + raise NotImplementedError def offset(self, distance): """Returns a new offset plane by a given distance. diff --git a/src/compas/geometry/point.py b/src/compas/geometry/point.py index c84d306223f..d22791024d4 100644 --- a/src/compas/geometry/point.py +++ b/src/compas/geometry/point.py @@ -78,27 +78,34 @@ class Point(Geometry): Point objects support basic arithmetic operations. - >>> p1 + p2 - Point(5.000, 7.000, 9.000) - >>> p1 * 2 - Point(2.000, 4.000, 6.000) - >>> p1**2 - Point(1.000, 4.000, 9.000) - >>> p1 - Point(1.000, 2.000, 3.000) + >>> result = p1 + p2 + >>> print(result) + Point(x=5.000, y=7.000, z=9.000) + + >>> result = p1 * 2 + >>> print(result) + Point(x=2.000, y=4.000, z=6.000) + + >>> result = p1 ** 2 + >>> print(result) + Point(x=1.000, y=4.000, z=9.000) + + >>> print(p1) + Point(x=1.000, y=2.000, z=3.000) Points and lists can be used interchangeably. - >>> p1 + [4, 5, 6] - Point(5.000, 7.000, 9.000) + >>> result = p1 + [4, 5, 6] + >>> print(result) + Point(x=5.000, y=7.000, z=9.000) Arithmetic operations can also be applied to modify a point object in-place. >>> p1 += p2 >>> p1 *= 2 >>> p1 **= 2 - >>> p1 - Point(100.000, 196.000, 324.000) + >>> print(p1) + Point(x=100.000, y=196.000, z=324.000) """ @@ -430,7 +437,7 @@ def on_line(self, line, tol=None): -------- >>> from compas.geometry import Line >>> line = Line(Point(1.0, 0.0, 0.0), Point(1.0, 1.0, 0.0)) - >>> point = line.point(1.5) + >>> point = line.point_at(1.5) >>> point.on_line(line) True @@ -458,7 +465,7 @@ def on_segment(self, segment, tol=None): -------- >>> from compas.geometry import Line >>> line = Line(Point(1.0, 0.0, 0.0), Point(1.0, 1.0, 0.0)) - >>> point = line.point(1.5) + >>> point = line.point_at(1.5) >>> point.on_segment(line) False @@ -483,7 +490,7 @@ def on_polyline(self, polyline): -------- >>> from compas.geometry import Polyline >>> poly = Polyline([Point(0.0, 0.0, 0.0), Point(1.0, 0.0, 0.0), Point(2.0, 0.0, 0.0)]) - >>> point = poly.point(0.5) + >>> point = poly.point_at(0.5) >>> point.on_polyline(poly) True @@ -604,7 +611,7 @@ def in_circle(self, circle): >>> from compas.geometry import Vector >>> from compas.geometry import Plane >>> from compas.geometry import Circle - >>> circle = Circle(Plane(Point(0.0, 0.0, 0.0), Vector(0.0, 0.0, 1.0)), 1.0) + >>> circle = Circle(1.0) >>> point = Point(0.5, 0.0, 0.0) >>> point.in_circle(circle) True diff --git a/src/compas/geometry/polygon.py b/src/compas/geometry/polygon.py index 893aa23d116..e7cf8e24580 100644 --- a/src/compas/geometry/polygon.py +++ b/src/compas/geometry/polygon.py @@ -75,8 +75,9 @@ class Polygon(Geometry): Examples -------- >>> polygon = Polygon([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]]) - >>> polygon.centroid - Point(0.500, 0.500, 0.000) + >>> point = polygon.centroid + >>> print(point) + Point(x=0.500, y=0.500, z=0.000) >>> polygon.area 1.0 @@ -362,8 +363,9 @@ def transform(self, T): >>> polygon = Polygon.from_sides_and_radius_xy(4, 1.0) >>> R = Rotation.from_axis_and_angle([0.0, 0.0, 1.0], radians(45)) >>> polygon.transform(R) - >>> polygon.points[0] - Point(-0.707, 0.707, 0.000) + >>> point = polygon.points[0] + >>> print(point) + Point(x=-0.707, y=0.707, z=0.000) """ for index, point in enumerate(transform_points(self.points, T)): diff --git a/src/compas/geometry/polyhedron.py b/src/compas/geometry/polyhedron.py index b1bd501af4e..62a14b0fe3b 100644 --- a/src/compas/geometry/polyhedron.py +++ b/src/compas/geometry/polyhedron.py @@ -491,7 +491,7 @@ def from_convex_hull(cls, points): -------- >>> from compas.geometry import Polyhedron >>> points = [[0, 0, 0], [1, 0, 0], [0, 1, 0]] - >>> p = Polyhedron.from_convex_hull(points) + >>> p = Polyhedron.from_convex_hull(points) # doctest: +SKIP """ from compas.geometry import convex_hull_numpy @@ -578,8 +578,8 @@ def boolean_union(self, other): Examples -------- >>> from compas.geometry import Box, Sphere - >>> A = Box(size=2).to_polyhedron() - >>> B = Sphere(point=[1, 1, 1], radius=1.0).to_polyhedron(u=16) + >>> A = Box(2).to_polyhedron(triangulated=True) + >>> B = Sphere(point=[1, 1, 1], radius=1.0).to_polyhedron(triangulated=True) >>> C = A.boolean_union(B) """ @@ -607,8 +607,8 @@ def boolean_difference(self, other): Examples -------- >>> from compas.geometry import Box, Sphere - >>> A = Box(size=2).to_polyhedron() - >>> B = Sphere(point=[1, 1, 1], radius=1.0).to_polyhedron(u=16) + >>> A = Box(2).to_polyhedron(triangulated=True) + >>> B = Sphere(point=[1, 1, 1], radius=1.0).to_polyhedron(triangulated=True) >>> C = A.boolean_difference(B) """ @@ -636,8 +636,8 @@ def boolean_intersection(self, other): Examples -------- >>> from compas.geometry import Box, Sphere - >>> A = Box(size=2).to_polyhedron() - >>> B = Sphere(point=[1, 1, 1], radius=1.0).to_polyhedron(u=16) + >>> A = Box(2).to_polyhedron(triangulated=True) + >>> B = Sphere(point=[1, 1, 1], radius=1.0).to_polyhedron(triangulated=True) >>> C = A.boolean_intersection(B) """ diff --git a/src/compas/geometry/rotation.py b/src/compas/geometry/rotation.py index e0f6526403c..f7505fba9ad 100644 --- a/src/compas/geometry/rotation.py +++ b/src/compas/geometry/rotation.py @@ -234,7 +234,7 @@ def from_quaternion(cls, quaternion): >>> q1 = [0.945, -0.021, -0.125, 0.303] >>> R = Rotation.from_quaternion(q1) >>> q2 = R.quaternion - >>> TOL.is_allclose(q1, q2) + >>> TOL.is_allclose(q1, q2, atol=1e-3) True """ @@ -262,7 +262,7 @@ def from_axis_angle_vector(cls, axis_angle_vector, point=[0, 0, 0]): >>> aav1 = [-0.043, -0.254, 0.617] >>> R = Rotation.from_axis_angle_vector(aav1) >>> aav2 = R.axis_angle_vector - >>> TOL.is_allclose(aav1, aav2) + >>> TOL.is_allclose(aav1, aav2, atol=1e-3) True """ diff --git a/src/compas/geometry/scale.py b/src/compas/geometry/scale.py index 815a8a3b0da..422c9ecdac9 100644 --- a/src/compas/geometry/scale.py +++ b/src/compas/geometry/scale.py @@ -52,9 +52,10 @@ class Scale(Transformation): >>> point = Point(2, 5, 0) >>> frame = Frame(point, (1, 0, 0), (0, 1, 0)) >>> points = [point, Point(2, 10, 0)] - >>> S = Scale.from_factors([2.0] * 3, frame) - >>> [p.transformed(S) for p in points] - [Point(2.000, 5.000, 0.000), Point(2.000, 15.000, 0.000)] + >>> S = Scale.from_factors([2.] * 3, frame) + >>> points = [p.transformed(S) for p in points] + >>> print(points) + [Point(x=2.000, y=5.000, z=0.000), Point(x=2.000, y=15.000, z=0.000)] """ @@ -87,9 +88,10 @@ def from_factors(cls, factors, frame=None): >>> point = Point(2, 5, 0) >>> frame = Frame(point, (1, 0, 0), (0, 1, 0)) >>> points = [point, Point(2, 10, 0)] - >>> S = Scale.from_factors([2.0] * 3, frame) - >>> [p.transformed(S) for p in points] - [Point(2.000, 5.000, 0.000), Point(2.000, 15.000, 0.000)] + >>> S = Scale.from_factors([2.] * 3, frame) + >>> points = [p.transformed(S) for p in points] + >>> print(points) + [Point(x=2.000, y=5.000, z=0.000), Point(x=2.000, y=15.000, z=0.000)] """ matrix = matrix_from_scale_factors(factors) diff --git a/src/compas/geometry/shapes/box.py b/src/compas/geometry/shapes/box.py index 75b38df01b7..f59ac32dee3 100644 --- a/src/compas/geometry/shapes/box.py +++ b/src/compas/geometry/shapes/box.py @@ -52,6 +52,8 @@ class Box(Shape): The box's frame. height : float, read-only The height of the box in Z direction. + points : list[:class:`compas.geometry.Point`] + The corner points of the box. volume : float, read-only The volume of the box. width : float, read-only @@ -269,6 +271,27 @@ def left(self): def top(self): return [4, 5, 6, 7] + @property + def points(self): + point = self.frame.point + xaxis = self.frame.xaxis + yaxis = self.frame.yaxis + zaxis = self.frame.zaxis + + dx = 0.5 * self.xsize + dy = 0.5 * self.ysize + dz = 0.5 * self.zsize + + a = point + xaxis * -dx + yaxis * -dy + zaxis * -dz + b = point + xaxis * -dx + yaxis * +dy + zaxis * -dz + c = point + xaxis * +dx + yaxis * +dy + zaxis * -dz + d = point + xaxis * +dx + yaxis * -dy + zaxis * -dz + e = a + zaxis * self.zsize + f = d + zaxis * self.zsize + g = c + zaxis * self.zsize + h = b + zaxis * self.zsize + return [a, b, c, d, e, f, g, h] + # ========================================================================== # Constructors # ========================================================================== @@ -662,7 +685,7 @@ def contains_points(self, points, tol=1e-6): Examples -------- >>> from compas.geometry import Point, Box - >>> box = Box(Frame.worldXY(), 2.0, 2.0, 2.0) + >>> box = Box(2.0, 2.0, 2.0) >>> points = [Point(0.0, 0.0, 0.0), Point(1.0, 1.0, 1.0)] >>> results = box.contains_points(points) >>> all(results) diff --git a/src/compas/geometry/shapes/capsule.py b/src/compas/geometry/shapes/capsule.py index fa63f0161c4..e6668e85234 100644 --- a/src/compas/geometry/shapes/capsule.py +++ b/src/compas/geometry/shapes/capsule.py @@ -69,9 +69,9 @@ class Capsule(Shape): Examples -------- >>> frame = Frame.worldXY() - >>> capsule = Capsule(frame=frame, radius=0.3, heigth=1.0) - >>> capsule = Capsule(radius=0.3, heigth=1.0) - >>> capsule = Capsule() + >>> capsule = Capsule(radius=0.3, height=1.0, frame=frame) + >>> capsule = Capsule(radius=0.3, height=1.0) + >>> capsule = Capsule(3.0, 1.0) """ @@ -204,7 +204,7 @@ def from_line_and_radius(cls, line, radius): # type: (...) -> Capsule Examples -------- - >>> line = Line(Point(0, 0, 0), Point(0, 0, 1)) + >>> line = Line([0, 0, 0], [0, 0, 1]) >>> capsule = Capsule.from_line_and_radius(line, 0.3) """ @@ -233,7 +233,7 @@ def from_circle_and_height(cls, circle, height): # type: (...) -> Capsule Examples -------- - >>> circle = Circle(Frame.worldXY(), 0.3) + >>> circle = Circle(0.3) >>> capsule = Capsule.from_circle_and_height(circle, 1.0) """ diff --git a/src/compas/geometry/shapes/cone.py b/src/compas/geometry/shapes/cone.py index e923495135a..6036df7eb3a 100644 --- a/src/compas/geometry/shapes/cone.py +++ b/src/compas/geometry/shapes/cone.py @@ -73,7 +73,7 @@ class Cone(Shape): >>> frame = Frame.worldXY() >>> cone = Cone(frame=frame, radius=0.3, height=1.0) >>> cone = Cone(radius=0.3, height=1.0) - >>> cone = Cone() + >>> cone = Cone(0.3, 1.0) """ @@ -196,7 +196,8 @@ def from_line_and_radius(cls, line, radius): # type: (...) -> Cone Examples -------- - >>> line = Line(Point(0, 0, 0), Point(0, 0, 1)) + >>> from compas.geometry import Line + >>> line = Line([0, 0, 0], [0, 0, 1]) >>> cone = Cone.from_line_and_radius(line, 0.3) """ @@ -225,7 +226,7 @@ def from_circle_and_height(cls, circle, height): # type: (...) -> Cone Examples -------- - >>> circle = Circle(Frame.worldXY(), 0.3) + >>> circle = Circle(0.3) >>> cone = Cone.from_circle_and_height(circle, 1.0) """ diff --git a/src/compas/geometry/shapes/cylinder.py b/src/compas/geometry/shapes/cylinder.py index 39170e0a410..d13e036591c 100644 --- a/src/compas/geometry/shapes/cylinder.py +++ b/src/compas/geometry/shapes/cylinder.py @@ -68,9 +68,9 @@ class Cylinder(Shape): Examples -------- >>> frame = Frame.worldXY() - >>> cylinder = Cylinder(frame=frame, radius=0.3, heigth=1.0) - >>> cylinder = Cylinder(radius=0.3, heigth=1.0) - >>> cylinder = Cylinder() + >>> cylinder = Cylinder(frame=frame, radius=0.3, height=1.0) + >>> cylinder = Cylinder(radius=0.3, height=1.0) + >>> cylinder = Cylinder(0.3, 1.0) """ diff --git a/src/compas/geometry/shapes/shape.py b/src/compas/geometry/shapes/shape.py index dd3cf35137e..c3e92389b6c 100644 --- a/src/compas/geometry/shapes/shape.py +++ b/src/compas/geometry/shapes/shape.py @@ -82,7 +82,7 @@ def frame(self): # type: () -> Frame return self._frame @frame.setter - def frame(self, frame): # type: (Frame) -> None + def frame(self, frame): # type: (Frame | None) -> None if not frame: self._frame = None else: @@ -167,7 +167,7 @@ def lines(self): # type: () -> list[Line] @property def polygons(self): # type: () -> list[Polygon] vertices = self.compute_vertices() - return [[Polygon([vertices[v] for v in face])] for face in self.faces] + return [Polygon([vertices[v] for v in face]) for face in self.faces] # ============================================================================= # Constructors @@ -225,7 +225,7 @@ def compute_triangles(self): # type: () -> list[tuple[int, int, int]] # ============================================================================= def to_vertices_and_faces(self, triangulated=False, u=None, v=None): - # type: (bool, int | None, int | None) -> tuple[list[list[float]], list[list[int]]] + # type: (bool, int | None, int | None) -> tuple[list[list[float]], list[list[int]] | list[tuple[int, int, int]]] """Convert the shape to a list of vertices and faces. Parameters diff --git a/src/compas/geometry/shapes/torus.py b/src/compas/geometry/shapes/torus.py index 05188f7f0cd..f251739d599 100644 --- a/src/compas/geometry/shapes/torus.py +++ b/src/compas/geometry/shapes/torus.py @@ -271,7 +271,7 @@ def transform(self, transformation): >>> from compas.geometry import Frame >>> from compas.geometry import Transformation >>> from compas.geometry import Torus - >>> torus = Torus(Frame.worldXY(), 5, 2) + >>> torus = Torus(5, 2) >>> frame = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15]) >>> T = Transformation.from_frame(frame) >>> torus.transform(T) diff --git a/src/compas/geometry/transformation.py b/src/compas/geometry/transformation.py index dd57474b05e..c6816b9efda 100644 --- a/src/compas/geometry/transformation.py +++ b/src/compas/geometry/transformation.py @@ -370,10 +370,9 @@ def from_change_of_basis(cls, frame_from, frame_to): >>> f2 = Frame([1, 1, 1], [0.68, 0.68, 0.27], [-0.67, 0.73, -0.15]) >>> T = Transformation.from_change_of_basis(f1, f2) >>> p_f1 = Point(1, 1, 1) # point in f1 - >>> p_f1.transformed(T) # point represented in f2 - Point(1.395, 0.955, 1.934) - >>> Frame.local_to_local_coordinates(f1, f2, p_f1) - Point(1.395, 0.955, 1.934) + >>> point = p_f1.transformed(T) # point represented in f2 + >>> print(point) + Point(x=1.395, y=0.955, z=1.934) """ T1 = cls.from_frame(frame_from) diff --git a/src/compas/geometry/vector.py b/src/compas/geometry/vector.py index 7ccf054431f..a3b9ea4d07e 100644 --- a/src/compas/geometry/vector.py +++ b/src/compas/geometry/vector.py @@ -43,26 +43,36 @@ class Vector(Geometry): -------- >>> u = Vector(1, 0, 0) >>> v = Vector(0, 1, 0) - >>> u - Vector(1.000, 0.000, 0.000) - >>> v - Vector(0.000, 1.000, 0.000) + >>> print(u) + Vector(x=1.000, y=0.000, z=0.000) + >>> print(v) + Vector(x=0.000, y=1.000, z=0.000) + >>> u.x 1.0 >>> u[0] 1.0 >>> u.length 1.0 - >>> u + v - Vector(1.000, 1.000, 0.000) - >>> u + [0.0, 1.0, 0.0] - Vector(1.000, 1.000, 0.000) - >>> u * 2 - Vector(2.000, 0.000, 0.000) + + >>> result = u + v + >>> print(result) + Vector(x=1.000, y=1.000, z=0.000) + + >>> result = u + [0.0, 1.0, 0.0] + >>> print(result) + Vector(x=1.000, y=1.000, z=0.000) + + >>> result = u * 2 + >>> print(result) + Vector(x=2.000, y=0.000, z=0.000) + >>> u.dot(v) 0.0 - >>> u.cross(v) - Vector(0.000, 0.000, 1.000) + + >>> w = u.cross(v) + >>> print(w) + Vector(x=0.000, y=0.000, z=1.000) """ @@ -289,8 +299,8 @@ def Xaxis(cls): Examples -------- - >>> Vector.Xaxis() - Vector(1.000, 0.000, 0.000) + >>> Vector.Xaxis() == [1, 0, 0] + True """ return cls(1.0, 0.0, 0.0) @@ -306,8 +316,8 @@ def Yaxis(cls): Examples -------- - >>> Vector.Yaxis() - Vector(0.000, 1.000, 0.000) + >>> Vector.Yaxis() == [0, 1, 0] + True """ return cls(0.0, 1.0, 0.0) @@ -323,8 +333,8 @@ def Zaxis(cls): Examples -------- - >>> Vector.Zaxis() - Vector(0.000, 0.000, 1.000) + >>> Vector.Zaxis() == [0, 0, 1] + True """ return cls(0.0, 0.0, 1.0) @@ -347,8 +357,9 @@ def from_start_end(cls, start, end): Examples -------- - >>> Vector.from_start_end([1.0, 0.0, 0.0], [1.0, 1.0, 0.0]) - Vector(0.000, 1.000, 0.000) + >>> vector = Vector.from_start_end([1.0, 0.0, 0.0], [1.0, 1.0, 0.0]) + >>> print(vector) + Vector(x=0.000, y=1.000, z=0.000) """ v = subtract_vectors(end, start) @@ -379,8 +390,8 @@ def transform_collection(collection, X): >>> vectors = [u] >>> Vector.transform_collection(vectors, R) >>> v = vectors[0] - >>> v - Vector(0.000, 1.000, 0.000) + >>> print(v) + Vector(x=0.000, y=1.000, z=0.000) >>> u is v True @@ -413,8 +424,8 @@ def transformed_collection(collection, X): >>> vectors = [u] >>> vectors = Vector.transformed_collection(vectors, R) >>> v = vectors[0] - >>> v - Vector(0.000, 1.000, 0.000) + >>> print(v) + Vector(x=0.000, y=1.000, z=0.000) >>> u is v False @@ -439,7 +450,8 @@ def length_vectors(vectors): Examples -------- - >>> Vector.length_vectors([[1.0, 0.0, 0.0], [2.0, 0.0, 0.0]]) + >>> result = Vector.length_vectors([[1.0, 0.0, 0.0], [2.0, 0.0, 0.0]]) + >>> print(result) [1.0, 2.0] """ @@ -461,8 +473,9 @@ def sum_vectors(vectors): Examples -------- - >>> Vector.sum_vectors([[1.0, 0.0, 0.0], [2.0, 0.0, 0.0]]) - Vector(3.000, 0.000, 0.000) + >>> result = Vector.sum_vectors([[1.0, 0.0, 0.0], [2.0, 0.0, 0.0]]) + >>> print(result) + Vector(x=3.000, y=0.000, z=0.000) """ return Vector(*[sum(axis) for axis in zip(*vectors)]) @@ -485,7 +498,8 @@ def dot_vectors(left, right): Examples -------- - >>> Vector.dot_vectors([[1.0, 0.0, 0.0], [2.0, 0.0, 0.0]], [[1.0, 0.0, 0.0], [2.0, 0.0, 0.0]]) + >>> result = Vector.dot_vectors([[1.0, 0.0, 0.0], [2.0, 0.0, 0.0]], [[1.0, 0.0, 0.0], [2.0, 0.0, 0.0]]) + >>> print(result) [1.0, 4.0] """ @@ -509,8 +523,9 @@ def cross_vectors(left, right): Examples -------- - >>> Vector.cross_vectors([[1.0, 0.0, 0.0], [2.0, 0.0, 0.0]], [[0.0, 1.0, 0.0], [0.0, 0.0, 2.0]]) - [Vector(0.000, 0.000, 1.000), Vector(0.000, -4.000, 0.000)] + >>> result = Vector.cross_vectors([[1.0, 0.0, 0.0], [2.0, 0.0, 0.0]], [[0.0, 1.0, 0.0], [0.0, 0.0, 2.0]]) + >>> print(result) + [Vector(x=0.000, y=0.000, z=1.000), Vector(x=0.000, y=-4.000, z=0.000)] """ # cross_vectors(u,v) from src\compas\geometry\_core\_algebra.py @@ -534,7 +549,8 @@ def angles_vectors(left, right): Examples -------- - >>> Vector.angles_vectors([[1.0, 0.0, 0.0], [2.0, 0.0, 0.0]], [[0.0, 1.0, 0.0], [0.0, 0.0, 2.0]]) + >>> result = Vector.angles_vectors([[1.0, 0.0, 0.0], [2.0, 0.0, 0.0]], [[0.0, 1.0, 0.0], [0.0, 0.0, 2.0]]) + >>> print(result) [(1.5707963267948966, 4.71238898038469), (1.5707963267948966, 4.71238898038469)] """ @@ -558,7 +574,8 @@ def angle_vectors(left, right): Examples -------- - >>> Vector.angle_vectors([[1.0, 0.0, 0.0], [2.0, 0.0, 0.0]], [[0.0, 1.0, 0.0], [0.0, 0.0, 2.0]]) + >>> result = Vector.angle_vectors([[1.0, 0.0, 0.0], [2.0, 0.0, 0.0]], [[0.0, 1.0, 0.0], [0.0, 0.0, 2.0]]) + >>> print(result) [1.5707963267948966, 1.5707963267948966] """ @@ -771,8 +788,9 @@ def cross(self, other): -------- >>> u = Vector(1.0, 0.0, 0.0) >>> v = Vector(0.0, 1.0, 0.0) - >>> u.cross(v) - Vector(0.000, 0.000, 1.000) + >>> w = u.cross(v) + >>> print(w) + Vector(x=0.000, y=0.000, z=1.000) """ return Vector(*cross_vectors(self, other)) @@ -886,8 +904,8 @@ def transform(self, T): >>> u = Vector(1.0, 0.0, 0.0) >>> R = Rotation.from_axis_and_angle([0.0, 0.0, 1.0], math.radians(90)) >>> u.transform(R) - >>> u - Vector(0.000, 1.000, 0.000) + >>> print(u) + Vector(x=0.000, y=1.000, z=0.000) """ point = transform_vectors([self], T)[0] @@ -914,8 +932,8 @@ def transformed(self, T): >>> u = Vector(1.0, 0.0, 0.0) >>> R = Rotation.from_axis_and_angle([0.0, 0.0, 1.0], math.radians(90)) >>> v = u.transformed(R) - >>> v - Vector(0.000, 1.000, 0.000) + >>> print(v) + Vector(x=0.000, y=1.000, z=0.000) """ vector = self.copy() diff --git a/src/compas/linalg.py b/src/compas/linalg.py index 299dc6c7ac8..3f0f6cd5356 100644 --- a/src/compas/linalg.py +++ b/src/compas/linalg.py @@ -169,8 +169,8 @@ def pivots(U, tol=None): Examples -------- >>> A = [[1, 0, 1, 3], [2, 3, 4, 7], [-1, -3, -3, -4]] - >>> n = rref_sympy(A) - >>> pivots(n) + >>> n = rref(A) + >>> pivots(n) # doctest: +SKIP [0, 1] """ @@ -207,8 +207,8 @@ def nonpivots(U, tol=None): Examples -------- >>> A = [[1, 0, 1, 3], [2, 3, 4, 7], [-1, -3, -3, -4]] - >>> n = rref_sympy(A) - >>> nonpivots(n) + >>> n = rref(A) + >>> nonpivots(n) # doctest: +SKIP [2, 3] """ diff --git a/src/compas/scene/scene.py b/src/compas/scene/scene.py index 472aa70ecad..f9b0861a2b6 100644 --- a/src/compas/scene/scene.py +++ b/src/compas/scene/scene.py @@ -33,8 +33,8 @@ class Scene(Tree): >>> from compas.geometry import Box >>> scene = Scene() >>> box = Box.from_width_height_depth(1, 1, 1) - >>> scene.add(box) - >>> scene.draw() + >>> boxobj = scene.add(box) + >>> scene.draw() # doctest: +SKIP """ diff --git a/src/compas/tolerance.py b/src/compas/tolerance.py index d5538fac5bc..fbcfd021892 100644 --- a/src/compas/tolerance.py +++ b/src/compas/tolerance.py @@ -529,16 +529,29 @@ def is_close(self, a, b, rtol=None, atol=None): Examples -------- >>> tol = Tolerance() - >>> tol.is_close(1.0, 1.000001) - True - >>> tol.is_close(1.0, 1.00001) - True - >>> tol.is_close(1.0, 1.0001) + + >>> tol.is_close(1.0, 1.0 + 1e-5) + False + >>> tol.is_close(1.0, 1.0 + 1e-6) True - >>> tol.is_close(1.0, 1.001) + + >>> tol.is_close(0.1, 0.1 + 1e-5) + False + >>> tol.is_close(0.1, 0.1 + 1e-6) + False + >>> tol.is_close(0.1, 0.1 + 1e-7) True - >>> tol.is_close(1.0, 1.01) + + >>> tol.is_close(0, 0 + 1e-5) False + >>> tol.is_close(0, 0 + 1e-6) + False + >>> tol.is_close(0, 0 + 1e-7) + False + >>> tol.is_close(0, 0 + 1e-8) + False + >>> tol.is_close(0, 0 + 1e-9) + True """ rtol = rtol or self.relative @@ -570,12 +583,14 @@ def is_allclose(self, A, B, rtol=None, atol=None): Examples -------- >>> tol = Tolerance() - >>> tol.is_allclose([0.0, 0.0], [1e-7, 1e-7]) - True - >>> tol.is_allclose([0.0, 0.0], [1e-6, 1e-6]) + >>> tol.is_allclose([1.0, 1.0], [1.0 + 1e-5, 1.0 + 1e-6]) + False + >>> tol.is_allclose([1.0, 1.0], [1.0 + 1e-6, 1.0 + 1e-6]) True - >>> tol.is_allclose([0.0, 0.0], [1e-6, 1e-5]) + >>> tol.is_allclose([0.0, 0.0], [0.0 + 1e-8, 0.0 + 1e-9]) False + >>> tol.is_allclose([0.0, 0.0], [0.0 + 1e-9, 0.0 + 1e-9]) + True """ rtol = rtol or self.relative @@ -602,9 +617,9 @@ def is_angle_zero(self, a, tol=None): Examples -------- >>> tol = Tolerance() - >>> tol.is_zero_angle(1e-07) + >>> tol.is_angle_zero(1e-07) True - >>> tol.is_zero_angle(1e-05) + >>> tol.is_angle_zero(1e-05) False """ diff --git a/src/compas/topology/combinatorics.py b/src/compas/topology/combinatorics.py index d010cb23d2b..dff34e6d422 100644 --- a/src/compas/topology/combinatorics.py +++ b/src/compas/topology/combinatorics.py @@ -47,7 +47,7 @@ def vertex_coloring(adjacency): >>> from compas.datastructures import Graph >>> graph = Graph.from_obj(compas.get("lines.obj")) >>> key_color = vertex_coloring(graph.adjacency) - >>> key = graph.get_any_node() + >>> key = graph.node_sample(size=1)[0] >>> color = key_color[key] >>> any(key_color[nbr] == color for nbr in graph.neighbors(key)) False