From f3b66d5447e2d0dfa404616cf500b4922b22c526 Mon Sep 17 00:00:00 2001 From: Tom Van Mele Date: Wed, 16 Sep 2020 16:14:09 +0200 Subject: [PATCH] geometry core cleanup --- src/compas/geometry/_core/__init__.py | 10 +- .../geometry/_core/{basic.py => _algebra.py} | 165 ------------------ .../_core/{average.py => centroids.py} | 0 src/compas/geometry/_core/distance.py | 1 + 4 files changed, 9 insertions(+), 167 deletions(-) rename src/compas/geometry/_core/{basic.py => _algebra.py} (87%) rename src/compas/geometry/_core/{average.py => centroids.py} (100%) diff --git a/src/compas/geometry/_core/__init__.py b/src/compas/geometry/_core/__init__.py index 1113f4b8011..e506b652605 100644 --- a/src/compas/geometry/_core/__init__.py +++ b/src/compas/geometry/_core/__init__.py @@ -2,15 +2,21 @@ from __future__ import absolute_import from __future__ import division -from .basic import * # noqa: F401 F403 +from ._algebra import * # noqa: F401 F403 + +# to be removed from .analytical import * # noqa: F401 F403 + from .distance import * # noqa: F401 F403 from .angles import * # noqa: F401 F403 -from .average import * # noqa: F401 F403 +from .centroids import * # noqa: F401 F403 from .normals import * # noqa: F401 F403 from .size import * # noqa: F401 F403 from .quaternions import * # noqa: F401 F403 + +# to be removed from .tangent import * # noqa: F401 F403 + from .kdtree import * # noqa: F401 F403 __all__ = [name for name in dir() if not name.startswith('_')] diff --git a/src/compas/geometry/_core/basic.py b/src/compas/geometry/_core/_algebra.py similarity index 87% rename from src/compas/geometry/_core/basic.py rename to src/compas/geometry/_core/_algebra.py index 953cb73337f..cf7c9db5464 100644 --- a/src/compas/geometry/_core/basic.py +++ b/src/compas/geometry/_core/_algebra.py @@ -4,7 +4,6 @@ from math import sqrt from math import fabs -from random import uniform __all__ = [ 'close', @@ -51,13 +50,8 @@ 'vector_component', 'vector_component_xy', - 'vector_from_points', - 'vector_from_points_xy', - 'plane_from_points', 'circle_from_points', 'circle_from_points_xy', - 'pointcloud', - 'pointcloud_xy' ] @@ -1276,81 +1270,6 @@ def orthonormalize_vectors(vectors): # ============================================================================== -def vector_from_points(a, b): - """Construct a vector from two points. - - Parameters - ---------- - a : sequence of float - XYZ coordinates of first point. - b : sequence of float - XYZ coordinates of second point. - - Returns - ------- - ab : sequence of float - The vector from ``a`` to ``b``. - - Examples - -------- - >>> - - """ - return b[0] - a[0], b[1] - a[1], b[2] - a[2] - - -def vector_from_points_xy(a, b): - """ - Create a vector based on a start point a and end point b in the XY-plane. - - Parameters - ---------- - a : sequence of float - XY(Z) coordinates of a 2D or 3D point (Z will be ignored). - b : sequence of float - XY(Z) coordinates of a 2D or 3D point (Z will be ignored). - - Returns - ------- - ab : tuple - Resulting 3D vector in the XY-plane (Z = 0.0). - - Notes - ----- - The result of this function is equal to ``subtract_vectors(b, a)`` - - """ - return b[0] - a[0], b[1] - a[1], 0.0 - - -def plane_from_points(a, b, c): - """Construct a plane from three points. - - Parameters - ---------- - a : sequence of float - XYZ coordinates. - b : sequence of float - XYZ coordinates. - c : sequence of float - XYZ coordinates. - - Returns - ------- - plane : tuple - Base point and normal vector (normalized). - - Examples - -------- - >>> - - """ - ab = subtract_vectors(b, a) - ac = subtract_vectors(c, a) - n = normalize_vector(cross_vectors(ab, ac)) - return a, n - - def circle_from_points(a, b, c): """Construct a circle from three points. @@ -1450,90 +1369,6 @@ def circle_from_points_xy(a, b, c): return [centerx, centery, 0.0], radius, [0, 0, 1] -def pointcloud(n, xbounds, ybounds=None, zbounds=None): - """Construct a point cloud. - - Parameters - ---------- - n : int - The number of points in the cloud. - xbounds : 2-tuple of float - The min/max values for the x-coordinates of the points in the cloud. - ybounds : 2-tuple of float, optional - The min/max values for the y-coordinates of the points in the cloud. - If ``None``, defaults to the value of the ``xbounds``. - zbounds : 2-tuple of float, optional - The min/max values for the z-coordinates of the points in the cloud. - If ``None``, defaults to the value of the ``xbounds``. - - Returns - ------- - list of list: - A list of points forming the cloud. - - Examples - -------- - >>> cloud = pointcloud(10, (0.0, 1.0)) - >>> all((0.0 < x < 1.0) and (0.0 < y < 1.0) and (0.0 < z < 1.0) for x, y, z in cloud) - True - - >>> cloud = pointcloud(10, (5.0, 10.0), (0.0, 1.0), (-2.0, 3.0)) - >>> all((5.0 < x < 10.0) and (0.0 < y < 1.0) and (-2.0 < z < 3.0) for x, y, z in cloud) - True - - """ - if ybounds is None: - ybounds = xbounds - if zbounds is None: - zbounds = xbounds - xmin, xmax = map(float, xbounds) - ymin, ymax = map(float, ybounds) - zmin, zmax = map(float, zbounds) - x = [uniform(xmin, xmax) for i in range(n)] - y = [uniform(ymin, ymax) for i in range(n)] - z = [uniform(zmin, zmax) for i in range(n)] - return list(map(list, zip(x, y, z))) - - -def pointcloud_xy(n, xbounds, ybounds=None): - """Construct a point cloud in the XY plane. - - Parameters - ---------- - n : int - The number of points in the cloud. - xbounds : 2-tuple of float - The min/max values for the x-coordinates of the points in the cloud. - ybounds : 2-tuple of float, optional - The min/max values for the y-coordinates of the points in the cloud. - If ``None``, defaults to the value of the ``xbounds``. - - Returns - ------- - list: - A list of points in the XY plane (Z = 0). - - Examples - -------- - >>> cloud = pointcloud_xy(10, (0.0, 1.0)) - >>> all((0.0 < x < 1.0) and (0.0 < y < 1.0) and z == 0.0 for x, y, z in cloud) - True - - >>> cloud = pointcloud_xy(10, (5.0, 10.0), (0.0, 1.0)) - >>> all((5.0 < x < 10.0) and (0.0 < y < 1.0) and z == 0.0 for x, y, z in cloud) - True - - """ - if ybounds is None: - ybounds = xbounds - xmin, xmax = map(float, xbounds) - ymin, ymax = map(float, ybounds) - x = [uniform(xmin, xmax) for i in range(n)] - y = [uniform(ymin, ymax) for i in range(n)] - z = [0.0 for i in range(n)] - return list(map(list, zip(x, y, z))) - - # ============================================================================== # Main # ============================================================================== diff --git a/src/compas/geometry/_core/average.py b/src/compas/geometry/_core/centroids.py similarity index 100% rename from src/compas/geometry/_core/average.py rename to src/compas/geometry/_core/centroids.py diff --git a/src/compas/geometry/_core/distance.py b/src/compas/geometry/_core/distance.py index 273c6735349..f3c3855c24d 100644 --- a/src/compas/geometry/_core/distance.py +++ b/src/compas/geometry/_core/distance.py @@ -36,6 +36,7 @@ 'distance_point_plane', 'distance_point_plane_signed', 'distance_line_line', + 'closest_point_in_cloud', 'closest_point_in_cloud_xy', 'closest_point_on_line',