diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ff200d4a3ba..d25fbad153cb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Updated minimum library version to `2.14.1` in Rhino8 GH components. * Changed name of YAK package from `bluejay` to `compas`. * Fixed broken `scaled()` method in `Sphere`, `Cylinder`, and `Capsule` classes by overriding to accept uniform scaling factor. +* Fixed bug in `compas.geometry.PlanarSurface`. ### Removed diff --git a/src/compas/geometry/surfaces/planar.py b/src/compas/geometry/surfaces/planar.py index 6e9e25f2fcad..4b6797444f0b 100644 --- a/src/compas/geometry/surfaces/planar.py +++ b/src/compas/geometry/surfaces/planar.py @@ -167,11 +167,10 @@ def point_at(self, u, v, world=True): A point on the sphere. """ - point = Point(u, v, 0) + point = Point(u * self.xsize, v * self.ysize, 0) if world: point.transform(self.transformation) return point - # return self.frame.point + self.frame.xaxis * u + self.frame.yaxis * v def normal_at(self, u=None, v=None, world=True): """Construct the normal at a point on the planar surface. diff --git a/tasks.py b/tasks.py index 5a9835ef6274..7286febdb086 100644 --- a/tasks.py +++ b/tasks.py @@ -7,7 +7,7 @@ from compas_invocations2 import style from compas_invocations2 import tests from compas_invocations2 import grasshopper -from invoke import Collection +from invoke.collection import Collection ns = Collection( docs.help, diff --git a/tests/compas/geometry/test_surfaces_plane.py b/tests/compas/geometry/test_surfaces_plane.py index d219bec4288e..1c852dd1d3c4 100644 --- a/tests/compas/geometry/test_surfaces_plane.py +++ b/tests/compas/geometry/test_surfaces_plane.py @@ -39,6 +39,32 @@ def test_plane(xsize, ysize): assert plane.frame == other.frame +@pytest.mark.parametrize( + "xsize,ysize", + [ + (0, 0), + (1, 0), + (0, 1), + (1, 1), + (10, 1), + (1, 10), + (2, 3), + (3, 2), + (random(), random()), + ], +) +def test_plane_size(xsize, ysize): + plane = PlanarSurface(xsize=xsize, ysize=ysize) + + assert plane.point_at(1, 0) == Point(xsize, 0, 0) + assert plane.point_at(0, 1) == Point(0, ysize, 0) + assert plane.point_at(1, 1) == Point(xsize, ysize, 0) + + assert plane.point_at(0.5, 0) == Point(0.5 * xsize, 0, 0) + assert plane.point_at(0, 0.5) == Point(0, 0.5 * ysize, 0) + assert plane.point_at(0.5, 0.5) == Point(0.5 * xsize, 0.5 * ysize, 0) + + @pytest.mark.parametrize( "frame", [ @@ -107,3 +133,37 @@ def test_plane_data(): # ============================================================================= # Other Methods # ============================================================================= + +# ============================================================================= +# Conversions +# ============================================================================= + + +@pytest.mark.parametrize( + "xsize,ysize", + [ + (0, 0), + (1, 0), + (0, 1), + (1, 1), + (10, 1), + (1, 10), + (2, 3), + (3, 2), + (random(), random()), + ], +) +def test_plane_conversion_to_mesh(xsize, ysize): + plane = PlanarSurface(xsize=xsize, ysize=ysize) + + area = plane.xsize * plane.ysize + + mesh = plane.to_mesh(1, 1) + assert mesh.number_of_vertices() == 4 + assert mesh.number_of_faces() == 1 + assert TOL.is_close(mesh.area(), area) + + mesh = plane.to_mesh(10, 10) + assert mesh.number_of_vertices() == 121 + assert mesh.number_of_faces() == 100 + assert TOL.is_close(mesh.area(), area)