Skip to content

Commit

Permalink
Fix: Convert vectors to unit vectors in Cylinder.to_mesh()
Browse files Browse the repository at this point in the history
  • Loading branch information
ajhynes7 committed Jun 11, 2022
1 parent 9e6a3be commit 7697836
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/skspatial/objects/cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,8 @@ def to_mesh(self, n_along_axis: int = 100, n_angles: int = 30) -> Tuple[np.ndarr
# Two unit vectors that are mutually perpendicular
# and perpendicular to the cylinder axis.
# These are used to define the points on the cylinder surface.
u_1 = v_axis.cross(v_different_direction)
u_2 = v_axis.cross(u_1)
u_1 = v_axis.cross(v_different_direction).unit()
u_2 = v_axis.cross(u_1).unit()

# The cylinder surface ranges over t from 0 to length of axis,
# and over theta from 0 to 2 * pi.
Expand Down
13 changes: 12 additions & 1 deletion tests/unit/objects/test_cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,24 @@ def test_intersect_cylinder_line_with_caps_failure(cylinder, line):
@pytest.mark.parametrize(
("cylinder", "n_along_axis", "n_angles", "points_expected"),
[
(Cylinder([0, 0, 0], [0, 0, 1], 1), 1, 1, [[-1, 0, 0]]),
(
Cylinder([0, 0, 0], [0, 0, 1], 1),
1,
1,
[[-1, 0, 0]],
),
(
Cylinder([0, 0, 0], [0, 0, 1], 1),
3,
2,
[[-1, 0, 0], [-1, 0, 0.5], [-1, 0, 1]],
),
(
Cylinder([0, 0, 0], [0.707, 0.707, 0], 1),
1,
3,
[[-0.707, 0.707, 0], [0.707, -0.707, -0]],
),
],
)
def test_to_points(cylinder, n_along_axis, n_angles, points_expected):
Expand Down

0 comments on commit 7697836

Please sign in to comment.