Skip to content

Commit 1688a82

Browse files
committed
Added unit test for cq.Vector.projectToLine()
1 parent e81228d commit 1688a82

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

tests/test_cad_objects.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ def testVectorEquals(self):
262262

263263
def testVectorProject(self):
264264
"""
265-
Test method to project vector to plane.
265+
Test line projection and plane projection methods of cq.Vector
266266
"""
267267
decimal_places = 9
268268

@@ -276,6 +276,22 @@ def testVectorProject(self):
276276
point.toTuple(), (59 / 7, 55 / 7, 51 / 7), decimal_places
277277
)
278278

279+
# test line projection
280+
vec = Vector(10, 10, 10)
281+
line = Vector(3, 4, 5)
282+
angle = vec.getAngle(line)
283+
284+
vecLineProjection = vec.projectToLine(line)
285+
286+
self.assertTupleAlmostEquals(
287+
vecLineProjection.normalized().toTuple(),
288+
line.normalized().toTuple(),
289+
decimal_places,
290+
)
291+
self.assertAlmostEqual(
292+
vec.Length * math.cos(angle), vecLineProjection.Length, decimal_places
293+
)
294+
279295
def testMatrixCreationAndAccess(self):
280296
def matrix_vals(m):
281297
return [[m[r, c] for c in range(4)] for r in range(4)]

0 commit comments

Comments
 (0)