How to use the ezdxf.math.Vec2 function in ezdxf

To help you get started, we’ve selected a few ezdxf examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mozman / ezdxf / tests / test_07_render / test_707_trace.py View on Github external
def test_two_angled_faces():
    t = LinearTrace()
    t.add_station((0, 0), 1, 0.5)
    t.add_station((2, 0), 1, 1)
    t.add_station((4, 2), 1, 1)
    face1, face2 = list(t.faces())
    assert face1[0].isclose(Vec2(0, +0.5))
    assert face1[1].isclose(Vec2(0, -0.5))
    assert face1[2].isclose(Vec2(2.5224077499274835, -0.18469903125906456))
    assert face1[3].isclose(Vec2(1.5936828611675133, 0.3007896423540608))
    assert face2[2].isclose(Vec2(4.353553390593274, 1.6464466094067263))
    assert face2[3].isclose(Vec2(3.646446609406726, 2.353553390593274))
github mozman / ezdxf / tests / test_06_math / test_646_offset_vertices_2d.py View on Github external
def test_closed_triangle_inside():
    vertices = [(0, 0), (5, 0), (2.5, 5)]
    result = list(offset_vertices_2d(vertices, 1, closed=True))
    assert result[0].isclose(Vec2((1.618, 1)), abs_tol=PRECISION)
    assert result[1].isclose(Vec2((3.382, 1)), abs_tol=PRECISION)
    assert result[2].isclose(Vec2((2.5, 2.7639)), abs_tol=PRECISION)
github mozman / ezdxf / tests / test_07_render / test_707_trace.py View on Github external
def test_two_straight_faces():
    t = LinearTrace()
    t.add_station((0, 0), 1, 1)
    t.add_station((2, 0), 1, 1)
    t.add_station((4, 0), 1, 1)
    face1, face2 = list(t.faces())
    assert face1[0].isclose(Vec2(0, +0.5))
    assert face1[1].isclose(Vec2(0, -0.5))
    assert face1[2].isclose(Vec2(2, -0.5))
    assert face1[3].isclose(Vec2(2, +0.5))
    assert face2[0].isclose(Vec2(2, +0.5))
    assert face2[1].isclose(Vec2(2, -0.5))
    assert face2[2].isclose(Vec2(4, -0.5))
    assert face2[3].isclose(Vec2(4, +0.5))
github mozman / ezdxf / tests / test_07_render / test_707_trace.py View on Github external
def test_two_angled_faces():
    t = LinearTrace()
    t.add_station((0, 0), 1, 0.5)
    t.add_station((2, 0), 1, 1)
    t.add_station((4, 2), 1, 1)
    face1, face2 = list(t.faces())
    assert face1[0].isclose(Vec2(0, +0.5))
    assert face1[1].isclose(Vec2(0, -0.5))
    assert face1[2].isclose(Vec2(2.5224077499274835, -0.18469903125906456))
    assert face1[3].isclose(Vec2(1.5936828611675133, 0.3007896423540608))
    assert face2[2].isclose(Vec2(4.353553390593274, 1.6464466094067263))
    assert face2[3].isclose(Vec2(3.646446609406726, 2.353553390593274))
github mozman / ezdxf / tests / test_06_math / test_630_bezier4p.py View on Github external
def test_accepts_2d_points():
    curve = Bezier4P(DEFPOINTS2D)
    for index, chk in enumerate(Vec2.generate(POINTS2D)):
        assert curve.point(index * .1).isclose(chk)
github mozman / ezdxf / src / ezdxf / render / dim_radius.py View on Github external
def add_horiz_ext_line_user(self, start: 'Vertex') -> None:
        """ Add horizontal extension line from start for user defined locations. """
        attribs = self.dim_line_attributes()
        self.add_line(start, self.user_location, dxfattribs=attribs)
        if self.vertical_placement == 0:
            hdist = self.arrow_size
        else:
            hdist = self.dim_text_width
        if self.user_location.x <= self.point_on_circle.x:
            hdist = -hdist
        end = self.user_location + Vec2((hdist, 0))
        self.add_line(self.user_location, end, dxfattribs=attribs)
github mozman / ezdxf / src / ezdxf / render / arrows.py View on Github external
def connection_point(arrow_name: str, insert: 'Vertex', scale: float = 1, rotation: float = 0) -> Vec2:
    insert = Vec2(insert)
    if arrow_name in _Arrows.ORIGIN_ZERO:
        return insert
    else:
        return insert - Vec2.from_deg_angle(rotation, scale)
github mozman / ezdxf / src / ezdxf / render / dim_radius.py View on Github external
def get_default_text_location(self) -> Vec2:
        """ Returns default text midpoint based on `self.text_valign` and `self.text_outside` """
        if self.text_outside and self.text_outside_horizontal:
            hdist = self.dim_text_width / 2.
            if self.vertical_placement == 0:  # shift text horizontal if vertical centered
                hdist += self.arrow_size
            angle = self.dim_line_angle % 360.  # normalize 0 .. 360
            if 90 < angle <= 270:
                hdist = -hdist
            return self.outside_default_defpoint + Vec2((hdist, self.text_vertical_distance()))

        text_direction = Vec2.from_deg_angle(self.text_rotation)
        vertical_direction = text_direction.orthogonal(ccw=True)
        vertical_distance = self.text_vertical_distance()
        if self.text_inside:
            hdist = (self.radius - self.arrow_size) / 2
            text_midpoint = self.center + (self.dim_line_vec * hdist)
        else:
            hdist = self.dim_text_width / 2. + self.arrow_size + self.text_gap
            text_midpoint = self.point_on_circle + (self.dim_line_vec * hdist)
        return text_midpoint + (vertical_direction * vertical_distance)
github mozman / ezdxf / src / ezdxf / render / dim_base.py View on Github external
def location_override(self, location: 'Vertex', leader=False, relative=False) -> None:
        """
        Set user defined dimension text location. ezdxf defines a user defined location per definition as 'outside'.

        Args:
            location: text midpoint
            leader: use leader or not (movement rules)
            relative: is location absolute (in UCS) or relative to dimension line center.

        """
        self.dim_style.set_location(location, leader, relative)
        self.user_location = Vec2(location)
        self.text_movement_rule = 1 if leader else 2
        self.relative_user_location = relative
        self.text_outside = True