def test_rotate(): """Test the LineSegment3D rotate method.""" pt = Point3D(2, 2, 2) vec = Vector3D(0, 2, 0) seg = LineSegment3D(pt, vec) origin_1 = Point3D(0, 0, 0) axis_1 = Vector3D(1, 0, 0) test_1 = seg.rotate(axis_1, math.pi, origin_1) assert test_1.p.x == pytest.approx(2, rel=1e-3) assert test_1.p.y == pytest.approx(-2, rel=1e-3) assert test_1.p.z == pytest.approx(-2, rel=1e-3) assert test_1.v.x == pytest.approx(0, rel=1e-3) assert test_1.v.y == pytest.approx(-2, rel=1e-3) assert test_1.v.z == pytest.approx(0, rel=1e-3) test_2 = seg.rotate(axis_1, math.pi / 2, origin_1) assert test_2.p.x == pytest.approx(2, rel=1e-3) assert test_2.p.y == pytest.approx(-2, rel=1e-3) assert test_2.p.z == pytest.approx(2, rel=1e-3) assert test_2.v.x == pytest.approx(0, rel=1e-3) assert test_2.v.y == pytest.approx(0, rel=1e-3) assert test_2.v.z == pytest.approx(2, rel=1e-3)
def test_parallel_colinear(): """Test the is_parallel and is_colinear methods.""" pt_1 = Point3D(0, 0, 0) pt_2 = Point3D(0, 4, 0) pt_3 = Point3D(2, 0, 2) vec_1 = Vector3D(0, 2, 0) vec_2 = Vector3D(0, -2, 0) vec_3 = Vector3D(3, 3, 0) seg_1 = LineSegment3D(pt_1, vec_1) seg_2 = LineSegment3D(pt_2, vec_1) seg_3 = LineSegment3D(pt_1, vec_2) seg_4 = LineSegment3D(pt_3, vec_1) seg_5 = LineSegment3D(pt_3, vec_2) seg_6 = LineSegment3D(pt_1, vec_3) assert seg_1.is_colinear(seg_2, 0.0001, 0.0001) assert seg_1.is_colinear(seg_3, 0.0001, 0.0001) assert not seg_1.is_colinear(seg_4, 0.0001, 0.0001) assert seg_1.is_parallel(seg_4, 0.0001) assert seg_1.is_parallel(seg_5, 0.0001) assert not seg_1.is_parallel(seg_6, 0.0001)
def to_linesegment3d(line): """Ladybug LineSegment3D from Rhino LineCurve.""" return LineSegment3D.from_end_points(to_point3d(line.PointAtStart), to_point3d(line.PointAtEnd))
def test_extract_rectangle(): """Test the Face3D extract_rectangle method.""" pts_1 = [ Point3D(0, 0, 0), Point3D(0, 0, 2), Point3D(2, 0, 2), Point3D(2, 0, 0) ] pts_2 = [pt for pt in reversed(pts_1)] pts_3 = [ Point3D(0, 0, 0), Point3D(0, 0, 2), Point3D(2, 0, 2), Point3D(4, 0, 0) ] pts_4 = [ Point3D(-2, 0, 0), Point3D(0, 0, 2), Point3D(2, 0, 2), Point3D(4, 0, 0) ] pts_5 = [ Point3D(0, 0, 0), Point3D(-2, 0, 2), Point3D(4, 0, 2), Point3D(2, 0, 0) ] pts_6 = [ Point3D(0, 0, 0), Point3D(0, 0, 2), Point3D(1, 0, 3), Point3D(2, 0, 2), Point3D(2, 0, 0) ] pts_7 = [ Point3D(-2, 0, 0), Point3D(0, 0, 2), Point3D(2, 0, 2), Point3D(-1, 0, 0) ] plane = Plane(Vector3D(0, 1, 0)) face_1 = Face3D(pts_1, plane) face_2 = Face3D(pts_2, plane) face_3 = Face3D(pts_3, plane) face_4 = Face3D(pts_4, plane) face_5 = Face3D(pts_5, plane) face_6 = Face3D(pts_6, plane) face_7 = Face3D(pts_7, plane) f1_result = face_1.extract_rectangle(0.0001) assert f1_result[0] == LineSegment3D.from_end_points( Point3D(2, 0, 0), Point3D(0, 0, 0)) assert f1_result[1] == LineSegment3D.from_end_points( Point3D(2, 0, 2), Point3D(0, 0, 2)) assert len(f1_result[2]) == 0 f2_result = face_2.extract_rectangle(0.0001) assert f2_result[0] == LineSegment3D.from_end_points( Point3D(2, 0, 0), Point3D(0, 0, 0)) assert f2_result[1] == LineSegment3D.from_end_points( Point3D(2, 0, 2), Point3D(0, 0, 2)) assert len(f2_result[2]) == 0 f3_result = face_3.extract_rectangle(0.0001) assert f3_result[0] == LineSegment3D.from_end_points( Point3D(2, 0, 0), Point3D(0, 0, 0)) assert f3_result[1] == LineSegment3D.from_end_points( Point3D(2, 0, 2), Point3D(0, 0, 2)) assert len(f3_result[2]) == 1 f4_result = face_4.extract_rectangle(0.0001) assert f4_result[0] == LineSegment3D.from_end_points( Point3D(2, 0, 0), Point3D(0, 0, 0)) assert f4_result[1] == LineSegment3D.from_end_points( Point3D(2, 0, 2), Point3D(0, 0, 2)) assert len(f4_result[2]) == 2 f5_result = face_5.extract_rectangle(0.0001) assert f5_result[0] == LineSegment3D.from_end_points( Point3D(2, 0, 0), Point3D(0, 0, 0)) assert f5_result[1] == LineSegment3D.from_end_points( Point3D(2, 0, 2), Point3D(0, 0, 2)) assert len(f5_result[2]) == 2 f6_result = face_6.extract_rectangle(0.0001) assert f6_result[0] == LineSegment3D.from_end_points( Point3D(2, 0, 0), Point3D(0, 0, 0)) assert f6_result[1] == LineSegment3D.from_end_points( Point3D(2, 0, 2), Point3D(0, 0, 2)) assert len(f6_result[2]) == 1 f7_result = face_7.extract_rectangle(0.0001) assert f7_result is None
def test_join_segments_multiple_pline(): """Test the join_segments method with multiple polylines.""" pts = (Point3D(0, 0), Point3D(2, 0), Point3D(2, 2), Point3D(0, 2)) extra_pts = (Point3D(3, 3), Point3D(4, 3), Point3D(4, 4), Point3D(3, 4)) l_segs = (LineSegment3D.from_end_points(extra_pts[0], extra_pts[1]), LineSegment3D.from_end_points(pts[0], pts[1]), LineSegment3D.from_end_points(pts[1], pts[2]), LineSegment3D.from_end_points(pts[0], pts[3]), LineSegment3D.from_end_points(pts[3], pts[2])) p_lines = Polyline3D.join_segments(l_segs, 0.01) assert len(p_lines) == 2 l_segs = (LineSegment3D.from_end_points(extra_pts[0], extra_pts[1]), LineSegment3D.from_end_points(pts[0], pts[1]), LineSegment3D.from_end_points(pts[1], pts[2]), LineSegment3D.from_end_points(pts[0], pts[3]), LineSegment3D.from_end_points(pts[3], pts[2]), LineSegment3D.from_end_points(extra_pts[2], extra_pts[3]), LineSegment3D.from_end_points(extra_pts[1], extra_pts[2]), LineSegment3D.from_end_points(extra_pts[0], extra_pts[3])) p_lines = Polyline3D.join_segments(l_segs, 0.01) assert len(p_lines) == 2 for p_line in p_lines: assert isinstance(p_line, Polyline3D) assert len(p_line) == 5 assert p_line.is_closed(0.01)
def test_join_segments(): """Test the join_segments method.""" pts = (Point3D(0, 0), Point3D(2, 0), Point3D(2, 2), Point3D(0, 2)) l_segs = (LineSegment3D.from_end_points(pts[0], pts[1]), LineSegment3D.from_end_points(pts[1], pts[2]), LineSegment3D.from_end_points(pts[2], pts[3]), LineSegment3D.from_end_points(pts[3], pts[0])) p_lines = Polyline3D.join_segments(l_segs, 0.01) assert len(p_lines) == 1 assert isinstance(p_lines[0], Polyline3D) assert len(p_lines[0]) == 5 assert p_lines[0].is_closed(0.01) l_segs = (LineSegment3D.from_end_points(pts[0], pts[1]), LineSegment3D.from_end_points(pts[2], pts[3]), LineSegment3D.from_end_points(pts[1], pts[2]), LineSegment3D.from_end_points(pts[3], pts[0])) p_lines = Polyline3D.join_segments(l_segs, 0.01) assert len(p_lines) == 1 assert isinstance(p_lines[0], Polyline3D) assert len(p_lines[0]) == 5 assert p_lines[0].is_closed(0.01) l_segs = (LineSegment3D.from_end_points(pts[0], pts[1]), LineSegment3D.from_end_points(pts[1], pts[2]), LineSegment3D.from_end_points(pts[0], pts[3]), LineSegment3D.from_end_points(pts[3], pts[2])) p_lines = Polyline3D.join_segments(l_segs, 0.01) assert len(p_lines) == 1 assert isinstance(p_lines[0], Polyline3D) assert len(p_lines[0]) == 5 assert p_lines[0].is_closed(0.01)