Skip to content

Commit 587ff27

Browse files
authored
Merge pull request #1485 from compas-dev/fix-planarsurface
Fix bug in planar surface
2 parents 8fc7828 + 8e3d044 commit 587ff27

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
* Updated minimum library version to `2.14.1` in Rhino8 GH components.
1818
* Changed name of YAK package from `bluejay` to `compas`.
1919
* Fixed broken `scaled()` method in `Sphere`, `Cylinder`, and `Capsule` classes by overriding to accept uniform scaling factor.
20+
* Fixed bug in `compas.geometry.PlanarSurface`.
2021

2122
### Removed
2223

src/compas/geometry/surfaces/planar.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,10 @@ def point_at(self, u, v, world=True):
167167
A point on the sphere.
168168
169169
"""
170-
point = Point(u, v, 0)
170+
point = Point(u * self.xsize, v * self.ysize, 0)
171171
if world:
172172
point.transform(self.transformation)
173173
return point
174-
# return self.frame.point + self.frame.xaxis * u + self.frame.yaxis * v
175174

176175
def normal_at(self, u=None, v=None, world=True):
177176
"""Construct the normal at a point on the planar surface.

tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from compas_invocations2 import style
88
from compas_invocations2 import tests
99
from compas_invocations2 import grasshopper
10-
from invoke import Collection
10+
from invoke.collection import Collection
1111

1212
ns = Collection(
1313
docs.help,

tests/compas/geometry/test_surfaces_plane.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,32 @@ def test_plane(xsize, ysize):
3939
assert plane.frame == other.frame
4040

4141

42+
@pytest.mark.parametrize(
43+
"xsize,ysize",
44+
[
45+
(0, 0),
46+
(1, 0),
47+
(0, 1),
48+
(1, 1),
49+
(10, 1),
50+
(1, 10),
51+
(2, 3),
52+
(3, 2),
53+
(random(), random()),
54+
],
55+
)
56+
def test_plane_size(xsize, ysize):
57+
plane = PlanarSurface(xsize=xsize, ysize=ysize)
58+
59+
assert plane.point_at(1, 0) == Point(xsize, 0, 0)
60+
assert plane.point_at(0, 1) == Point(0, ysize, 0)
61+
assert plane.point_at(1, 1) == Point(xsize, ysize, 0)
62+
63+
assert plane.point_at(0.5, 0) == Point(0.5 * xsize, 0, 0)
64+
assert plane.point_at(0, 0.5) == Point(0, 0.5 * ysize, 0)
65+
assert plane.point_at(0.5, 0.5) == Point(0.5 * xsize, 0.5 * ysize, 0)
66+
67+
4268
@pytest.mark.parametrize(
4369
"frame",
4470
[
@@ -107,3 +133,37 @@ def test_plane_data():
107133
# =============================================================================
108134
# Other Methods
109135
# =============================================================================
136+
137+
# =============================================================================
138+
# Conversions
139+
# =============================================================================
140+
141+
142+
@pytest.mark.parametrize(
143+
"xsize,ysize",
144+
[
145+
(0, 0),
146+
(1, 0),
147+
(0, 1),
148+
(1, 1),
149+
(10, 1),
150+
(1, 10),
151+
(2, 3),
152+
(3, 2),
153+
(random(), random()),
154+
],
155+
)
156+
def test_plane_conversion_to_mesh(xsize, ysize):
157+
plane = PlanarSurface(xsize=xsize, ysize=ysize)
158+
159+
area = plane.xsize * plane.ysize
160+
161+
mesh = plane.to_mesh(1, 1)
162+
assert mesh.number_of_vertices() == 4
163+
assert mesh.number_of_faces() == 1
164+
assert TOL.is_close(mesh.area(), area)
165+
166+
mesh = plane.to_mesh(10, 10)
167+
assert mesh.number_of_vertices() == 121
168+
assert mesh.number_of_faces() == 100
169+
assert TOL.is_close(mesh.area(), area)

0 commit comments

Comments
 (0)