def test_pitch_0_height_0(view, generate):
    func_name: str = sys._getframe().f_code.co_name
    inc = 0.1
    radius = 1
    height = 0
    h = Helix(radius=radius, pitch=0, height=height)
    f = h.helix()
    points = generate_points(f, h.first_t, h.last_t, inc)
    doit(
        func_name,
        points,
        h.first_t,
        h.last_t,
        inc,
        viewable=view,
        generate=generate,
    )

    # A "circle" centered around the origin
    origin = (0, 0, 0)
    center = (0, 0, height)
    assert center == origin
    assert all([(pt[Z] == height) and isclose(dist_3d(center, pt),
                                              radius,
                                              rel_tol=relative_tol,
                                              abs_tol=absolute_tol)
                for pt in points])
def test_pitch_0_vo_1(view, generate):
    func_name: str = sys._getframe().f_code.co_name
    inc = 0.1
    radius = 1
    vo = 1
    h = Helix(radius=radius, pitch=0, height=0)
    f = h.helix(HelixLocation(vert_offset=vo))
    points = generate_points(f, h.first_t, h.last_t, inc)
    doit(
        func_name,
        points,
        h.first_t,
        h.last_t,
        inc,
        viewable=view,
        generate=generate,
    )

    # A "circle" centered around the horz_offset
    center = (0, 0, vo)
    assert all([(pt[Z] == vo) and isclose(dist_3d(center, pt),
                                          radius,
                                          rel_tol=relative_tol,
                                          abs_tol=absolute_tol)
                for pt in points])
def test_radius_0_io_0pt1(view, generate):
    func_name: str = sys._getframe().f_code.co_name
    inc = 0.1
    inset = 0.1
    h = Helix(
        radius=0,
        pitch=1,
        height=1,
        inset_offset=inset,
    )
    f = h.helix()
    points = generate_points(f, h.first_t, h.last_t, inc)
    doit(
        func_name,
        points,
        h.first_t,
        h.last_t,
        inc,
        viewable=view,
        generate=generate,
    )

    # A vertical line starting at 0.1 ending at 0.9
    first_pt = (0, 0, inset)
    last_pt = (0, 0, 1 - inset)
    assert points[0] == first_pt
    assert points[-1] == last_pt
    assert all([(pt[0], pt[1], 0) == (0, 0, 0) and (pt >= first_pt)
                and (pt <= last_pt) for pt in points])
def test_radius_0_ft_0_lt_0_io_neg_0pt1(view, generate):
    func_name: str = sys._getframe().f_code.co_name
    first_t = 0
    last_t = 0
    inc = 0.1
    inset = -0.1
    h = Helix(radius=0,
              pitch=1,
              height=1,
              inset_offset=inset,
              first_t=first_t,
              last_t=last_t)
    f = h.helix()
    points = generate_points(f, h.first_t, h.last_t, inc)
    doit(
        func_name,
        points,
        first_t,
        last_t,
        inc,
        viewable=view,
        generate=generate,
    )

    # A point at origin (0, 0, inset)
    assert len(points) == 1
    assert points[0] == (0, 0, inset)
def test_helix_backwards(view, generate):
    func_name: str = sys._getframe().f_code.co_name
    inc = 0.1
    radius = 1
    pitch = 1
    height = 1
    h = Helix(radius=radius, pitch=pitch, height=height)
    f = h.helix()
    points = generate_points(f, h.first_t, h.last_t, inc)
    doit(
        func_name,
        points,
        h.first_t,
        h.last_t,
        inc,
        viewable=view,
        generate=generate,
    )

    # Validate the swapping of first_t and last_t creates the same helix
    h.first_t, h.last_t = h.last_t, h.first_t
    f = h.helix()
    # Generate the points, since we're starting at last_t we must use -inc
    # otherwise we'll only generate the last point
    points_backwards = generate_points(f, h.first_t, h.last_t, -inc)
    assert isclose_points(points, points_backwards)
def test_helix(view, generate):
    func_name: str = sys._getframe().f_code.co_name
    inc = 0.1
    radius = 1
    pitch = 1
    height = 1
    h = Helix(radius=radius, pitch=pitch, height=height)
    f = h.helix()
    points = generate_points(f, h.first_t, h.last_t, inc)
    doit(
        func_name,
        points,
        h.first_t,
        h.last_t,
        inc,
        viewable=view,
        generate=generate,
    )

    # A "helix" with all points equidistant from z-axis by the raidus
    assert all([
        isclose(
            dist_3d((0, 0, pt[Z]), pt),
            radius,
            rel_tol=relative_tol,
            abs_tol=absolute_tol,
        ) for pt in points
    ])
예제 #7
0
def helical_triangle(
    radius: float = 1,
    pitch: float = 2,
    height: float = 4,
    num_points: int = 100,
    tri_height: float = 0.2,
    tri_width: float = 0.2,
) -> Tuple[
    List[Tuple[float, float, float]],
    List[Tuple[float, float, float]],
    List[Tuple[float, float, float]],
]:

    # Create three helixes that taper to a point

    # Create the base Helix
    h: Helix = Helix(
        radius=radius, pitch=pitch, height=height, taper_out_rpos=0.1, taper_in_rpos=0.9
    )

    # The Upper points, horz_offset defaults to 0
    fU = h.helix(HelixLocation(vert_offset=tri_height / 2))
    points_fU = list(map(fU, linspace(h.first_t, h.last_t, num=100, dtype=float)))

    # The Lower points, again horz_offset defaults to 0
    fL = h.helix(HelixLocation(vert_offset=-tri_height / 2))
    points_fL = list(map(fL, linspace(h.first_t, h.last_t, num=100, dtype=float)))

    # The Middle point, change vert_offset to 0
    fM = h.helix(HelixLocation(horz_offset=tri_width))
    points_fM = list(map(fM, linspace(h.first_t, h.last_t, num=100, dtype=float)))

    return (points_fU, points_fM, points_fL)
def test_helix_torp_0pt1_tirp_0pt9_ho_0pt2(view, generate):
    func_name: str = sys._getframe().f_code.co_name
    inc = 0.05
    radius = 1
    pitch = 1
    height = 1
    torp = 0.1
    tirp = 0.9
    ho = 0.2
    h = Helix(
        radius=radius,
        pitch=pitch,
        height=height,
        taper_out_rpos=torp,
        taper_in_rpos=tirp,
    )
    f = h.helix(HelixLocation(horz_offset=ho))
    points = generate_points(f, h.first_t, h.last_t, inc)
    doit(
        func_name,
        points,
        h.first_t,
        h.last_t,
        inc,
        viewable=view,
        generate=generate,
    )

    # A "helix" with a convergence factor of 0.1. The distance from the center line
    # to the first and last points should be the radius.
    assert isclose_tuple((0, radius, 0), points[0])
    assert isclose_tuple((0, radius, height), points[-1])

    # The distance to the second point and the penultimate point are > radius
    assert dist_3d(points[1], (0, 0, points[1][Z])) > radius
    assert dist_3d(points[-2], (0, 0, points[-2][Z])) > radius

    # All other points should be equal to radius + ho
    assert all([
        isclose(
            dist_3d((0, 0, pt[Z]), pt),
            radius + ho,
            rel_tol=relative_tol,
            abs_tol=absolute_tol,
        ) for pt in points[2:-2]
    ])
def test_radius_0_height_0(view, generate):
    func_name: str = sys._getframe().f_code.co_name
    inc = 0.1
    h = Helix(radius=0, pitch=1, height=0)
    f = h.helix()
    points = generate_points(f, h.first_t, h.last_t, inc)
    doit(
        func_name,
        points,
        h.first_t,
        h.last_t,
        inc,
        viewable=view,
        generate=generate,
    )

    # All points at origin (0, 0, 0)
    assert all([(pt == (0, 0, 0)) for pt in points])
def test_radius_0_ft_0_lt_0(view, generate):
    func_name: str = sys._getframe().f_code.co_name
    inc = 0.1
    h = Helix(radius=0, pitch=1, height=1, first_t=0, last_t=0)
    f = h.helix()
    points = generate_points(f, h.first_t, h.last_t, inc)
    doit(
        func_name,
        points,
        h.first_t,
        h.last_t,
        inc,
        viewable=view,
        generate=generate,
    )

    # A point at origin
    assert len(points) == 1
    assert points[0] == (0, 0, 0)
def test_radius_0_ft_neg_1_lt_pos_1(view, generate):
    func_name: str = sys._getframe().f_code.co_name
    inc = 0.1
    h = Helix(radius=0, pitch=1, height=1, first_t=-1, last_t=1)
    f = h.helix()
    points = generate_points(f, h.first_t, h.last_t, inc)
    doit(
        func_name,
        points,
        h.first_t,
        h.last_t,
        inc,
        viewable=view,
        generate=generate,
    )
    # A vertical line starting at 0 ending at 1
    first_pt = (0, 0, 0)
    last_pt = (0, 0, 1)
    assert points[0] == first_pt
    assert points[-1] == last_pt
    assert all([(pt[0], pt[1], 0) == (0, 0, 0) and (pt >= first_pt)
                and (pt <= last_pt) for pt in points])
def test_helix_trp_validity(view, generate):
    radius = 1
    pitch = 1
    height = 1

    h = Helix(
        radius=radius,
        pitch=pitch,
        height=height,
    )

    h.taper_out_rpos = -0.1
    h.taper_in_rpos = 0.9
    with pytest.raises(ValueError):
        h.helix()

    h.taper_out_rpos = 1.00000000000001
    h.taper_in_rpos = 0.9
    with pytest.raises(ValueError):
        h.helix()

    h.taper_out_rpos = 0.1
    h.taper_in_rpos = -0.00000001
    with pytest.raises(ValueError):
        h.helix()

    h.taper_out_rpos = 0.1
    h.taper_in_rpos = 1.00000001
    with pytest.raises(ValueError):
        h.helix()

    h.taper_out_rpos = 0
    h.taper_in_rpos = 0.9
    h.helix()

    h.taper_out_rpos = 0.9
    h.taper_in_rpos = 1
    h.helix()

    h.taper_out_rpos = 0.1
    h.taper_in_rpos = 0.7
    h.helix()

    h.taper_out_rpos = 0.7
    h.taper_in_rpos = 0.8
    h.helix()

    h.taper_out_rpos = 0.1
    h.taper_in_rpos = 0.9
    h.helix()