Skip to content

Commit

Permalink
add test for flat box
Browse files Browse the repository at this point in the history
  • Loading branch information
tomvanmele committed Jan 14, 2025
1 parent 40b0e2e commit 61ae095
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/compas/geometry/shapes/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from compas.geometry import Frame
from compas.geometry import Line
from compas.geometry import Point # noqa: F401
from compas.geometry import Transformation
from compas.geometry import Vector
from compas.geometry import centroid_points
Expand Down Expand Up @@ -478,7 +479,7 @@ def from_points(cls, points): # type: (...) -> Box
# Discretisation
# ==========================================================================

def compute_vertices(self): # type: () -> list[list[float]]
def compute_vertices(self): # type: () -> list[Point]
"""Compute the vertices of the discrete representation of the box."""
point = self.frame.point
xaxis = self.frame.xaxis
Expand Down
25 changes: 25 additions & 0 deletions tests/compas/geometry/test_bbox.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest
import os
import compas
from random import random
from compas.tolerance import TOL
from compas.geometry import Box
from compas.geometry import bounding_box
from compas.geometry import bounding_box_xy

Expand Down Expand Up @@ -146,3 +148,26 @@ def test_oriented_bounding_box_numpy_from_fixtures():
results = oriented_bounding_box_numpy(coords)
for result, expected_values in zip(results, expected):
assert TOL.is_allclose(result, expected_values)


def test_oriented_bounding_box_numpy_flat():
if compas.IPY:
return

from compas.geometry import oriented_bounding_box_numpy

points = [[10 * random(), 10 * random(), 0] for i in range(100)]
box = Box.from_bounding_box(oriented_bounding_box_numpy(points))

for point in points:
assert box.contains_point(point)

assert not box.contains_point([10 * random(), 10 * random(), 1])

points = [[10 * random(), 10 * random(), 10] for i in range(100)]
box = Box.from_bounding_box(oriented_bounding_box_numpy(points))

for point in points:
assert box.contains_point(point)

assert not box.contains_point([10 * random(), 10 * random(), 11])

0 comments on commit 61ae095

Please sign in to comment.