Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plane.line_xsections: Clarify the desired behavior in a degenerate case #63

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions polliwog/plane/plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def _line_segment_xsection(self, a, b):
def line_xsections(self, pts, rays):
k = vg.shape.check(locals(), "pts", (-1, 3))
vg.shape.check(locals(), "rays", (k, 3))

denoms = np.dot(rays, self.normal)
denom_is_zero = denoms == 0
denoms[denom_is_zero] = np.nan
Expand Down
20 changes: 20 additions & 0 deletions polliwog/plane/test_plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,26 @@ def test_line_plane_intersections():
np.testing.assert_array_equal(is_intersecting, [False, False, True, True])


def test_line_plane_intersections_coplanar_input():
# TODO Intersecting the x-z plane with a line that lies in the x-z plane
# returns non-intersecting. Is this desirable?

# x-z plane
normal = np.array([0.0, 1.0, 0.0])
sample = np.array([0.0, 0.0, 0.0])

plane = Plane(sample, normal)

# A line that lies in the x-z plane.
pts = np.array([[1.0, 0.0, -1.0]])
rays = np.array([[1.0, 0.0, 2.0]])

expected = np.array([[np.nan, np.nan, np.nan]])
intersections, is_intersecting = plane.line_xsections(pts, rays)
np.testing.assert_array_equal(intersections, expected)
np.testing.assert_array_equal(is_intersecting, [False])
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's really worth adding this test, as it basically duplicates behavior from the previous test. If the decision is that this behavior is kept, I can add some comments to the method and the previous test, instead.



def test_line_segment_plane_intersection():
# x-z plane
normal = np.array([0.0, 1.0, 0.0])
Expand Down