コード例 #1
0
ファイル: scale_axes.py プロジェクト: deffi/cadlib
    def __init__(self, x, y, z):
        x = number.convert(x, "x")
        y = number.convert(y, "y")
        z = number.convert(z, "z")

        if x == 0: warn("x is 0")
        if y == 0: warn("y is 0")
        if z == 0: warn("z is 0")

        # TODO property name (can also be two-dimensional)
        self._xyz = [x, y, z]
コード例 #2
0
    def __init__(self, base, cap, base_radius, cap_radius):
        super().__init__()

        self._base = Vector.convert(base, "base", required_length=3)
        self._cap = Vector.convert(cap, "cap", required_length=3)
        self._base_radius = number.convert(base_radius, "base_radius")
        self._cap_radius = number.convert(cap_radius, "cap_radius")

        # Warn if the cap is equal to the base (zero length) or both radii are
        # zero (zero thickness; note that it is allowed for *one* of the radii
        # to be zero).
        if self._base == self._cap: warn("length is 0")
        if self._base_radius == self._cap_radius == 0: warn("radius is 0")
コード例 #3
0
ファイル: generators.py プロジェクト: deffi/cadlib
def _get_radius(r, d):
    """Given either a radius or a diameter, determine the radius.

    Either r or d, but not both, must be given (non-None). Otherwise, an
    exception will be raised. The given value is also converted to a number.
    """
    if both(r, d):
        raise TypeError("radius and diameter cannot be specified together")
    elif r is not None:
        return number.convert(r, "radius")
    elif d is not None:
        return number.convert(d, "diameter") / 2
    else:
        raise TypeError("radius or diameter must be specified")
コード例 #4
0
    def __init__(self, x, y, z):
        super().__init__()

        x = number.convert(x, "x")
        y = number.convert(y, "y")
        z = number.convert(z, "z")

        if x == 0: warn("x size is 0")
        if y == 0: warn("y size is 0")
        if z == 0: warn("z size is 0")

        self._size = [x, y, z]

        #self.top_face = Anchor(self, [x/2, y/2, z])
        #setattr(self, "top_face", Anchor(self, [x/2, y/2, z]))
        self.add_anchor("top_face", [x/2, y/2, z])
コード例 #5
0
ファイル: rotate_axis_angle.py プロジェクト: deffi/cadlib
    def __init__(self, axis, angle=None):
        axis = Vector.convert(axis, "axis", required_length=3)
        if axis.is_zero:
            raise ValueError("axis may not be zero-length")

        self._axis = axis
        self._angle = number.convert(angle, "angle", default=self._axis.length)
コード例 #6
0
ファイル: sphere.py プロジェクト: deffi/cadlib
    def __init__(self, r):
        super().__init__()

        self._radius = number.convert(r, "radius")

        if self._radius == 0: warn("radius is 0")

        self.add_anchor("center", [0, 0, 0])
コード例 #7
0
    def __init__(self, axis, factor):
        axis = Vector.convert(axis, "axis", required_length=3)
        if axis.is_zero:
            raise ValueError("axis may not be zero-length")

        self._axis   = axis
        self._factor = number.convert(factor, "factor", default=self._axis.length)

        if self._factor == 0: warn("factor is 0")
コード例 #8
0
    def test_to_number_helper(self):
        self.assertEqual(number.convert(42, "dummy"), 42) # Int
        self.assertEqual(number.convert(4.2, "dummy"), 4.2) # Float

        # Default
        self.assertEqual(number.convert(1, "dummy", default=999), 1)
        self.assertEqual(number.convert(None, "dummy", default=999), 999) # Default value

        # Invalid values (a default does not help)
        with self.assertRaises(TypeError): number.convert("", "dummy", default=999)
        with self.assertRaises(TypeError): number.convert([], "dummy", default=999)
コード例 #9
0
    def direction_length(cls, direction, length, base_radius, cap_radius):
        direction = Vector.convert(direction, "direction", required_length=3)
        length = number.convert(length, "length")

        if direction.is_zero:
            raise ValueError("direction must be non-zero")

        base = Vector(0, 0, 0)
        cap = direction.normalized() * length
        return cls(base, cap, base_radius, cap_radius)
コード例 #10
0
    def __init__(self, normal, offset):
        super().__init__()

        normal = Vector.convert(normal, "normal", required_length=3)
        if normal.is_zero:
            raise ValueError("Normal vector is zero")

        offset = number.convert(offset, "offset")

        self._normal = normal
        self._offset = offset
コード例 #11
0
ファイル: generators.py プロジェクト: deffi/cadlib
def cube(size):
    """Generate a cube.

    The cube will have one corner at the origin, will be aligned with the
    axes, and extend in the positive axis directions.

    Signatures (convenience forms only):
      * cube(size)
    """

    size = number.convert(size, "size")
    return Cuboid(size, size, size)
コード例 #12
0
ファイル: rotate_xyz.py プロジェクト: deffi/cadlib
 def __init__(self, x, y, z):
     x = number.convert(x, "x")
     y = number.convert(y, "y")
     z = number.convert(z, "z")
     self._xyz = [x, y, z]
コード例 #13
0
ファイル: rotate_ypr.py プロジェクト: deffi/cadlib
 def __init__(self, yaw, pitch, roll):
     yaw   = number.convert(yaw, "yaw")
     pitch = number.convert(pitch, "pitch")
     roll  = number.convert(roll, "roll")
     self._ypr = [yaw, pitch, roll]
コード例 #14
0
    def __init__(self, factor):
        self._factor = number.convert(factor, "factor")

        if self._factor == 0: warn("factor is 0")