def add_line(self, start: 'Vertex', end: 'Vertex', dxfattribs: dict = None, remove_hidden_lines=False) -> None: """ Add a LINE entity to the dimension BLOCK. Removes parts of the line hidden by dimension text if `remove_hidden_lines` is True. Args: start: start point of line end: end point of line dxfattribs: additional or overridden DXF attributes remove_hidden_lines: removes parts of the line hidden by dimension text if True """ def add_line_to_block(start, end): self.block.add_line(to_ocs(start).vec2, to_ocs(end).vec2, dxfattribs=dxfattribs) def order(a: Vec2, b: Vec2) -> Tuple[Vec2, Vec2]: if (start - a).magnitude < (start - b).magnitude: return a, b else: return b, a to_ocs = self.ucs.to_ocs attribs = self.default_attributes() if dxfattribs: attribs.update(dxfattribs) text_box = self.text_box if remove_hidden_lines and (text_box is not None): start_inside = int(text_box.is_inside(start)) end_inside = int(text_box.is_inside(end)) inside = start_inside + end_inside if inside == 2: # start and end inside text_box return # do not draw line elif inside == 1: # one point inside text_box or on a border line intersection_points = text_box.intersect( ConstructionLine(start, end)) if len(intersection_points) == 1: # one point inside one point outside -> one intersection point p1 = intersection_points[0] else: # second point on a text box border line p1, _ = order(*intersection_points) p2 = start if end_inside else end add_line_to_block(p1, p2) return else: intersection_points = text_box.intersect( ConstructionLine(start, end)) if len(intersection_points) == 2: # sort intersection points by distance to start point p1, p2 = order(intersection_points[0], intersection_points[1]) # line[start-p1] - gap - line[p2-end] add_line_to_block(start, p1) add_line_to_block(p2, end) return # else: fall trough add_line_to_block(start, end)