def test_intersect_with_vertical_and_horizontal(): ray1 = (vec2(-10, 10), vec2(10, 10)) ray2 = (vec2(5, 0), vec2(5, 20)) point = intersection_line_line_2d(ray1, ray2) assert point.y == 10 assert point.x == 5 assert point.isclose(vec2(5.0, 10.0), abs_tol=1e-4)
def line_intersection(self, s1: int, e1: int, s2: int, e2: int) -> None: line1 = self.p1[s1], self.p1[e1] line2 = self.p2[s2], self.p2[e2] p = intersection_line_line_2d(line1, line2, virtual=False, abs_tol=self.abs_tol) if p is not None and not any( p.isclose(ip, abs_tol=self.abs_tol) for ip in self.intersections): self.intersections.append(p)
def get_center_of_arc(self) -> Vec2: center = intersection_line_line_2d( (self.leg1_start, self.leg1_end), (self.leg2_start, self.leg2_end), ) if center is None: logger.warning( f"Invalid colinear or parallel angle legs found in {self.dimension})" ) # This case can not be created by the GUI in BricsCAD, but DXF # files can contain any shit! # The interpolation of the end-points is an arbitrary choice and # maybe not the best choice! center = self.leg1_end.lerp(self.leg2_end) return center
def intersect(self, other: 'ConstructionLine', abs_tol: float = TOLERANCE) -> Optional['Vec2']: """ Returns the intersection point of to lines or ``None`` if they have no intersection point. Args: other: other :class:`ConstructionLine` abs_tol: tolerance for distance check """ return intersection_line_line_2d((self.start, self.end), (other.start, other.end), virtual=False, abs_tol=abs_tol)
def edge_intersection() -> Vec2: return intersection_line_line_2d((edge_start, edge_end), (clip_start, clip_end))
def test_issue_128(): line1 = (vec2(175.0, 5.0), vec2(175.0, 50.0)) line2 = (vec2(-10.1231, 30.1235), vec2(300.2344, 30.1235)) point = intersection_line_line_2d(line1, line2, virtual=False) assert point is not None assert point.isclose(vec2(175.0, 30.1235))
def test_intersect_coincident_lines(p2): line1 = (Vec2(0, 0), Vec2(p2)) point = intersection_line_line_2d(line1, line1, virtual=False) assert point is None
def test_intersect_real_colinear(): line1 = (vec2(0, 0), vec2(4, 4)) line2 = (vec2(2, 2), vec2(4, 0)) # intersection point, is endpoint of ray2 point = intersection_line_line_2d(line1, line2, virtual=False) assert point.isclose(vec2(2, 2))
def test_intersect_real(): line1 = (vec2(0, 0), vec2(4, 4)) line2 = (vec2(3, 2), vec2(5, 0)) point = intersection_line_line_2d(line1, line2, virtual=False) assert point is None
def test_intersect_normal_vertical(): ray = (vec2(10, 1), vec2(10, -7)) ortho = (vec2(0, 3), vec2(10, 3)) point = intersection_line_line_2d(ray, ortho) assert point.isclose(vec2(10, 3))
def test_intersect_parallel_horizontal(): ray3 = (vec2(11, 0), vec2(-11, 0)) ray4 = (vec2(0, 0), vec2(1, 0)) assert intersection_line_line_2d(ray3, ray4) is None
def test_intersect_parallel_vertical(): ray1 = (vec2(10, 1), vec2(10, -7)) ray2 = (vec2(12, -10), vec2(12, 7)) assert intersection_line_line_2d(ray1, ray2) is None
def testintersect_with_horizontal(): ray1 = (vec2(-10, 10), vec2(10, 10)) ray2 = (vec2(-10, 20), vec2(10, 0)) point = intersection_line_line_2d(ray1, ray2) assert point.y == 10 assert point.isclose(vec2(0.0, 10.0), abs_tol=1e-4)
def test_intersect_with_vertical(): ray1 = (vec2(10, 1), vec2(10, -7)) ray2 = (vec2(-10, 3), vec2(17, -7)) point = intersection_line_line_2d(ray1, ray2) assert point.x == 10 assert point.isclose(vec2(10.0, -4.4074), abs_tol=1e-4)
def test_intersect_virtual(): ray1 = (vec2(10, 1), vec2(20, 10)) ray2 = (vec2(17, -7), vec2(-10, 3)) point = intersection_line_line_2d(ray1, ray2) assert point.isclose(vec2(5.7434, -2.8309), abs_tol=1e-4)
def profile_intersection_line_line_xy(count=COUNT): for _ in range(count): intersection_line_line_2d(line1=(P1, P2), line2=(P3, P4))