Skip to content

Commit

Permalink
Merge pull request #263 from ajhynes7/test_from_vectors
Browse files Browse the repository at this point in the history
Test `Plane.from_vectors`
  • Loading branch information
ajhynes7 committed Mar 19, 2021
2 parents c219fa7 + c27420c commit 0679fa9
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/property/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def triangles(draw, dim):
point_b = draw(arrays_fixed(dim))
point_c = draw(arrays_fixed(dim))

assume(not Points([point_a, point_b, point_c]).are_collinear(tol=0.1))
assume(not Points([point_a, point_b, point_c]).are_collinear(tol=1))

return Triangle(point_a, point_b, point_c)

Expand Down
2 changes: 1 addition & 1 deletion tests/property/test_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_project_point(lines_or_planes, data):
# should equal the distance to the line/plane.
distance_projection = vector_projection.norm()
distance_to_object = abs(line_or_plane.distance_point(array))
assert math.isclose(distance_to_object, distance_projection, rel_tol=1e-6)
assert math.isclose(distance_to_object, distance_projection, rel_tol=0.1)

# The distance of the projection should be the
# shortest distance from the point to the object.
Expand Down
41 changes: 41 additions & 0 deletions tests/unit/objects/test_plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,47 @@
from skspatial.objects import Points


@pytest.mark.parametrize(
("array_point", "array_a", "array_b", "plane_expected"),
[
([0, 0], [1, 0], [0, 1], Plane([0, 0, 0], [0, 0, 1])),
([1, 2], [1, 0], [0, 1], Plane([1, 2, 0], [0, 0, 1])),
([0, 0], [0, 1], [1, 0], Plane([0, 0, 0], [0, 0, -1])),
([0, 0], [2, 0], [0, 1], Plane([0, 0, 0], [0, 0, 2])),
([0, 0], [2, 0], [0, 2], Plane([0, 0, 0], [0, 0, 4])),
([1, 2, 3], [2, 0], [0, 2], Plane([1, 2, 3], [0, 0, 4])),
([-3, 2, 6], [1, 4, 6], [-1, 5, 8], Plane([-3, 2, 6], [2, -14, 9])),
],
)
def test_from_vectors(array_point, array_a, array_b, plane_expected):

plane = Plane.from_vectors(array_point, array_a, array_b)

assert plane.is_close(plane_expected)

# Also ensure that the vector is exactly as expected.
assert plane.vector.is_close(plane_expected.vector)


@pytest.mark.parametrize(
("array_point", "array_a", "array_b"),
[
([0, 0], [1, 0], [1, 0]),
([2, 3], [1, 0], [1, 0]),
([0, 0], [0, 1], [0, 1]),
([0, 0], [1, 1], [-1, -1]),
([0, 0], [5, 3], [-5, -3]),
([0, 0, 0], [1, 0, 0], [1, 0, 0]),
],
)
def test_from_vectors_failure(array_point, array_a, array_b):

message_expected = "The vectors must not be parallel."

with pytest.raises(ValueError, match=message_expected):
Plane.from_vectors(array_point, array_a, array_b)


@pytest.mark.parametrize(
("point_a", "point_b", "point_c", "plane_expected"),
[
Expand Down

0 comments on commit 0679fa9

Please sign in to comment.