Example #1
0
def frustum(direction_or_base, length_or_cap, r=None, d=None):
    """Generate a frustum.

    For the forms with a direction, the base will be at the origin.

    Signatures (convenience forms only):
      * frustum (direction, length, radii)
      * frustum (direction, length, d = diameters)
      * frustum (base, cap, radii)
      * frustum (base, cap, d = diameters)
    """

    # Radius or diameter
    radii = _get_radii(r, d)

    # length_or_base must be a vector or a number
    if number.valid(length_or_cap):
        # Number - direction/length
        return Frustum.direction_length(direction_or_base, length_or_cap,
                                        *radii)

    elif Vector.valid_type(length_or_cap):
        # Vector type - base/cap
        return Frustum(direction_or_base, length_or_cap, *radii)

    else:
        raise TypeError(
            "Invalid call signature: length_or_cap must be a vector type or a number"
        )
Example #2
0
def cylinder(direction_or_base, length_or_cap, r=None, d=None):
    """Generate a cylinder.

    Signatures (convenience forms only):
      * cylinder(direction, length, radius)
      * cylinder(direction, length, d = diameter)
      * cylinder(base, cap, radius)
      * cylinder(base, cap, d = diameter)
    """

    # Radius or diameter
    radius = _get_radius(r, d)

    # length_or_base must be a vector or a number
    if number.valid(length_or_cap):
        # Number - direction/length
        return Frustum.direction_length(direction_or_base, length_or_cap,
                                        radius, radius)

    elif Vector.valid_type(length_or_cap):
        # Vector type - base/cap
        return Frustum(direction_or_base, length_or_cap, radius, radius)

    else:
        raise TypeError(
            "Invalid call signature: length_or_cap must be a vector type or a number"
        )
Example #3
0
def cone(direction_or_base, length_or_tip, r=None, d=None):
    """Generate a cone.

    For the forms with a direction, the base will be at the origin.

    Signatures (convenience forms only):
      * cone(direction, length, radius)
      * cone(direction, length, d = diameter)
      * cone(base, cap, radius)
      * cone(base, cap, d = diameter)
    """
    # TODO should use r = None, *, d = None? (not just here)

    # Radius or diameter
    radius = _get_radius(r, d)

    # length_or_base must be a vector or a number
    if number.valid(length_or_tip):
        # Number - direction/length
        return Frustum.direction_length(direction_or_base, length_or_tip,
                                        radius, 0)

    elif Vector.valid_type(length_or_tip):
        # Vector type - base/cap
        return Frustum(direction_or_base, length_or_tip, radius, 0)

    else:
        raise TypeError(
            "Invalid call signature: length_or_cap must be a vector type or a number"
        )
Example #4
0
    def test_direction_length(self):
        self.assertEqual(Frustum.direction_length(X, 5, 1, 2),
                         Frustum(origin, X * 5, 1, 2))
        self.assertEqual(Frustum.direction_length((1, 0, 0), 5, 1, 2),
                         Frustum(origin, X * 5, 1, 2))

        # Zero direction
        with self.assertRaises(ValueError):
            Frustum.direction_length(origin, 5, 1, 2)

        # Zero size
        with self.assertWarnsRegex(UserWarning, r'length is 0'):
            Frustum.direction_length(X, 0, 1, 2)