Exemplo n.º 1
0
 def test_create_v2_wrong_length(self):
     """Test parameter v1 wrong length."""
     with self.assertRaisesRegexp(
             SdlSyntaxException,
             'Vector v2 has more or less than 3 dimensions'):
         self.sut = Box(Vector(1, 2, 3), Vector(4, 5, 6, 7),
                        ObjectModifier('foo'))
Exemplo n.º 2
0
def get_knob_inner_space(length=1, width=1, height=LG_BRICK_INNER_HEIGHT):
    """@Todo: DocString."""
    result = Union(
        Box(
            Vector(LGWW, LGWW, -LGCS),
            Vector(
                length * LGBW - LGWW,
                width * LGBW - LGWW,
                LG_PLATE_INNER_HEIGHT
            )
        )
    )

    for ks_x in range(0, length):
        for ks_y in range(0, width):
            result.append(
                Object(
                    LG_KNOB_INNER_SPACE,
                    Translate(
                        Vector(
                            (ks_x + 0.5) * LGBW,
                            (ks_y + 0.5) * LGBW,
                            height
                        )
                    )
                )
            )

    return result
Exemplo n.º 3
0
 def test_create_open_wrong_type(self):
     """Test creation with kwarg wrong type."""
     with self.assertRaisesRegexp(SdlSyntaxException,
                                  'Value of keyword open is not boolean'):
         self.sut = Cylinder(Vector(1, 2, 3),
                             Vector(5, 6, 7),
                             8,
                             ObjectModifier('foo'),
                             open='foo')
Exemplo n.º 4
0
 def test_create_non_existant_kw(self):
     """Test creation wrong kwarg."""
     with self.assertRaisesRegexp(SdlSyntaxException,
                                  'Invalid keyword: bar'):
         self.sut = Cylinder(Vector(1, 2, 3),
                             Vector(5, 6, 7),
                             8,
                             ObjectModifier('foo'),
                             bar=True)
Exemplo n.º 5
0
 def test_create_radius_wrong_type(self):
     """Test Param radius is not of type int or float."""
     with self.assertRaisesRegexp(
             SdlSyntaxException,
             'Param radius is not of type int or float'):
         self.sut = Cylinder(Vector(1, 2, 3),
                             Vector(5, 6, 7),
                             'foo',
                             ObjectModifier('foo'),
                             open=0.3)
Exemplo n.º 6
0
 def test_create_cpoint_wrong_length(self):
     """Test Cap point Vector has more or less than 3 dimensions."""
     with self.assertRaisesRegexp(
             SdlSyntaxException,
             'Cap point Vector has more or less than 3 dimensions'):
         self.sut = Cylinder(Vector(1, 2, 3),
                             Vector(5, 6, 7, 9),
                             8,
                             ObjectModifier('foo'),
                             open=0.3)
Exemplo n.º 7
0
    def test_creation_w_opt_and_kwarg(self):
        """Test creation and inheritance with option and kwarg."""
        self.sut = Cylinder(Vector(1, 2, 3),
                            Vector(5, 6, 7),
                            8,
                            ObjectModifier('foo'),
                            open=True)

        self.assertIsInstance(self.sut, Cylinder)
        self.assertIsInstance(self.sut, SceneItem)
Exemplo n.º 8
0
def _lego_logo_text_function(lclass):
    """@Todo: ApiDoc."""
    if LG_QUALITY > 2:
        return lclass(_letter_l(lclass), _letter_e(lclass), _letter_g(lclass),
                      _letter_o(lclass),
                      Scale(Vector(4.5 / 128, 4.5 / 128, 4.5 / 128)),
                      Rotate(y * 90), Rotate(x * -90), Scale(Vector(-1, 1, 1)),
                      Scale(Vector(1, 1, 1) * .08 * LG_KNOB_RADIUS * 2))
    else:
        return Object()
Exemplo n.º 9
0
 def test_create_obj_mod_wrong_type(self):
     """Test Only ObjectModifier objects may be passed as options."""
     with self.assertRaisesRegexp(
             SdlSyntaxException,
             'Only ObjectModifier objects may be passed as options'):
         self.sut = Cylinder(Vector(1, 2, 3),
                             Vector(5, 6, 7),
                             8,
                             'foo',
                             open=0.3)
Exemplo n.º 10
0
 def test_create_bpoint_wrong_length(self):
     """Test creation wrong length basepoint."""
     with self.assertRaisesRegexp(
             SdlSyntaxException,
             'Base point Vector has more or less than 3 dimensions'):
         self.sut = Cone(Vector(1, 2, 3, 9),
                         4,
                         Vector(5, 6, 7),
                         8,
                         ObjectModifier('foo'),
                         open=0.3)
Exemplo n.º 11
0
 def test_create_option_wrong_type(self):
     """Test creation wrong type option."""
     with self.assertRaisesRegexp(
             SdlSyntaxException,
             'Only ObjectModifier objects may be passed as options'):
         self.sut = Cone(Vector(1, 2, 3),
                         4,
                         Vector(5, 6, 7),
                         8,
                         Vector(1, 2),
                         open=0.3)
Exemplo n.º 12
0
 def test_create_crad_wrong_type(self):
     """Test creation wrong type capradius."""
     with self.assertRaisesRegexp(
             SdlSyntaxException,
             'Param cap radius is not of type int or float'):
         self.sut = Cone(Vector(1, 2, 3),
                         4,
                         Vector(5, 6, 7),
                         'foo',
                         ObjectModifier('foo'),
                         open=0.3)
Exemplo n.º 13
0
def lg_tech_knob_logo(knobclass=Union):
    """@Todo: ApiDoc."""
    scale = Scale(Vector(1, 1, 1))
    if LG_TEST > 0:
        scale = Scale(Vector(1, 1, 0.1))

    if LG_QUALITY > 3:
        return Union(
            Object(_lg_tech_knob_function(knobclass), scale),
            Object(
                LEGO_LOGO_TEXT,
                Scale(Vector(3 / 4, 3 / 4, 3 / 4)),
            ))

    return _lg_tech_knob_function(knobclass)
Exemplo n.º 14
0
 def test_create_vector_wrong_option(self):
     """Test Invalid option type Vector not in allowed opts."""
     with self.assertRaisesRegexp(
             SdlSyntaxException,
             r'Invalid option type Vector not in allowed opts\[.*]'):
         self.sut = HeightField('pov/tests/fixture/test.gif',
                                Vector(1, 2, 3, 4))
Exemplo n.º 15
0
def ch2rgb(hue):
    """
    Take Hue value as input, returns RGB vector.

    @Todo: Param Syntax checks
    """
    if not isinstance(hue, int):
        raise SdlSyntaxException('Parameter hue has to be of type int')

    hue %= 360
    if hue < 0:
        hue += 360
    if hue in range(120):
        red = (120 - hue) / 60
        green = (hue - 0) / 60
        blue = 0
    elif hue in range(120, 240):
        red = 0
        green = (240 - hue) / 60
        blue = (hue - 120) / 60
    elif hue in range(240, 360):
        red = (hue - 240) / 60
        green = 0
        blue = (360 - hue) / 60

    return Vector(min(red, 1), min(green, 1), min(blue, 1))
Exemplo n.º 16
0
 def test_create_non_existant_kw(self):
     """Test No such Keyword: bar."""
     with self.assertRaisesRegexp(SdlSyntaxException,
                                  'No such Keyword: bar'):
         self.sut = Sphere(Vector(5, 6, 7),
                           8,
                           ObjectModifier('foo'),
                           bar=True)
Exemplo n.º 17
0
def lg_tech_knob_logo_clear():
    """@Todo: ApiDoc."""
    if LG_QUALITY > 3:
        return Union(
            LG_TECH_KNOB_CLEAR,
            Object(LEGO_LOGO_TEXT, Scale(Vector(3 / 4, 3 / 4, 3 / 4))))
    else:
        return LG_TECH_KNOB_CLEAR
Exemplo n.º 18
0
 def map_arg(self, arg):
     """Map an argument list to an appropriate format."""
     if isinstance(arg, (tuple, list)):
         # if multiple-component, floating-point value, return a vector
         if len(arg) and hasattr(arg[0], "__float__"):
             return Vector(arg)
     # else return the same format as the input value
     return arg
Exemplo n.º 19
0
 def test_create_center_wrong_length(self):
     """Test Center point Vector has more or less than 3 dimensions."""
     with self.assertRaisesRegexp(
             SdlSyntaxException,
             'Center point Vector has more or less than 3 dimensions'):
         self.sut = Sphere(Vector(1, 2, 3, 9),
                           8,
                           ObjectModifier('foo'),
                           open=0.3)
Exemplo n.º 20
0
def _letter_o(lclass):
    """@Todo: ApiDoc."""
    return lclass(
        # Letter O
        Torus(18.45, 6, ClippedBy(Plane(Vector(40, 0, -9), 0)),
              Translate(Vector(-40, 0, 99))),
        Cylinder(Vector(-44.05, 0, 81), Vector(35.95, 0, 63), 6),
        Torus(18.45, 6, ClippedBy(Plane(Vector(-40, 0, 9), 0)),
              Translate(Vector(40, 0, 81))),
        Cylinder(Vector(44.05, 0, 99), Vector(-35.95, 0, 117), 6),
    )
Exemplo n.º 21
0
 def test_create_cappoint_wrong_type(self):
     """Test Parameter cappoint is not of type Vector."""
     with self.assertRaisesRegexp(
             SdlSyntaxException,
             'Parameter cappoint is not of type Vector'):
         self.sut = Cylinder(Vector(1, 2, 3),
                             'foo',
                             8,
                             ObjectModifier('foo'),
                             open=0.3)
Exemplo n.º 22
0
 def test_create_radius_wrong_type(self):
     """Test Value of Argument 1 is expected to be type."""
     with self.assertRaisesRegexp(
             SdlSyntaxException, ' '.join(
                 ('Value of Argument 1 is expected to be type',
                  '\\(\'float\', \'int\'\\) but got str'))):
         self.sut = Sphere(Vector(1, 2, 3),
                           'foo',
                           ObjectModifier('foo'),
                           open=0.3)
Exemplo n.º 23
0
 def test_create_bpoint_wrong_type(self):
     """Test creation wrong type basepoint."""
     with self.assertRaisesRegexp(
             SdlSyntaxException,
             'Parameter basepoint is not of type Vector'):
         self.sut = Cone('foo',
                         4,
                         Vector(5, 6, 7),
                         8,
                         ObjectModifier('foo'),
                         open=0.3)
Exemplo n.º 24
0
def get_knob_objects(length=1, width=1, height=LGBH):
    """@Todo: DocString."""
    result = Union()

    for knob_x in range(0, length):
        for knob_y in range(0, width):
            result.append(
                Object(
                    lg_knob(),
                    Rotate(Vector(0, 0, -90)),
                    Translate(
                        Vector(
                            (0.5 + knob_x) * LGBW,
                            (0.5 + knob_y) * LGBW,
                            height
                        )
                    ),
                )
            )

    return result
Exemplo n.º 25
0
def _letter_l(lclass):
    """@Todo: ApiDoc."""
    return lclass(
        # Letter L
        Sphere(Vector(-59, 0, -96), 6),
        Cylinder(Vector(-59, 0, -96), Vector(59, 0, -122), 6),
        Sphere(Vector(59, 0, -122), 6),
        Cylinder(Vector(59, 0, -122), Vector(59, 0, -84), 6),
        Sphere(Vector(59, 0, -84), 6),
    )
Exemplo n.º 26
0
    def test_create_with_options(self):
        """Test creation and inheritance."""
        self.sut = SceneItem('foo', [], [(1, 2, 3), SceneItem('bar')])

        self.assertEqual(type(self.sut.args), list)
        self.assertEqual(self.sut.args, [])

        self.assertEqual(type(self.sut.opts), list)
        self.assertEqual(self.sut.opts, [Vector(1, 2, 3), SceneItem('bar')])

        self.assertEqual(type(self.sut.kwargs), dict)
        self.assertEqual(self.sut.kwargs, {})
Exemplo n.º 27
0
    def test_create_with_kwargs(self):
        """Test creation and inheritance."""
        self.sut = SceneItem('foo', [], [], {
            'bar': (1, 2, 3),
            'baz': SceneItem('bar')
        })

        self.assertEqual(type(self.sut.args), list)
        self.assertEqual(self.sut.args, [])

        self.assertEqual(type(self.sut.opts), list)
        self.assertEqual(self.sut.opts, [])

        self.assertEqual(type(self.sut.kwargs), dict)
        self.assertIn('bar', self.sut.kwargs)

        warn(str(Vector(1, 2, 3)))
        warn(str(self.sut.kwargs['bar']))

        self.assertEqual(Vector(1, 2, 3), self.sut.kwargs['bar'])
        self.assertIn('baz', self.sut.kwargs)

        self.assertEqual(SceneItem('bar'), self.sut.kwargs['baz'])
Exemplo n.º 28
0
    def __init__(self, *opts, **kwargs):
        """
        Create Color object.

        @Todo: add properties for all color components @see colors_ink.py
        @TODO: Syntax Checks
        """
        super(Color, self).__init__('color', [], opts, kwargs)

        if 'rgb' in self.kwargs:
            self.type = 'rgb'
            self.vector = self.kwargs['rgb']
        elif 'rgbt' in kwargs:
            self.type = 'rgbt'
            self.vector = self.kwargs['rgbt']
        elif 'rgbf' in kwargs:
            self.type = 'rgbf'
            self.vector = self.kwargs['rgbf']
        elif 'rgbft' in kwargs:
            self.type = 'rgbft'
            self.vector = self.kwargs['rgbft']
        else:
            # @todo: how to deal with separate color keywords
            self.type = 'rgbft'
            self.vector = Vector(0, 0, 0, 0, 0)

            if 'red' in kwargs:
                self.vector[0] = self.kwargs['red']
            if 'green' in kwargs:
                self.vector[1] = self.kwargs['green']
            if 'blue' in kwargs:
                self.vector[2] = self.kwargs['blue']
            if 'filter' in kwargs:
                self.vector[3] = self.kwargs['filter']
            if 'transmit' in kwargs:
                self.vector[4] = self.kwargs['transmit']

        self.red = self.vector[0]
        self.green = self.vector[1]
        self.blue = self.vector[2]
        self.filter = 0
        self.transmit = 0

        if len(self.vector) > 3:
            self.filter = self.vector[3]

        if len(self.vector) > 4:
            self.transmit = self.vector[4]
Exemplo n.º 29
0
def get_lg_cylinder(cylinderclass, height):
    """@Todo:ApiDoc."""
    return cylinderclass(
        Difference(
            Cylinder(Vector(0, 0, height + LG_E),
                     Vector(0, 0, (LG_CYLINDER_WALL_WIDTH / 2)),
                     LG_CYLINDER_RADIUS),
            Cylinder(Vector(0, 0, height + LG_CORNER_SPACE), Vector(0, 0, 0),
                     LG_KNOB_RADIUS)),
        Torus(LG_CYLINDER_RADIUS - LG_CYLINDER_WALL_WIDTH / 2,
              LG_CYLINDER_WALL_WIDTH / 2, Rotate(Vector(90, 0, 0)),
              Translate(Vector(0, 0, (LG_CYLINDER_WALL_WIDTH / 2)))))
Exemplo n.º 30
0
def get_cylinder(
        length=1,
        width=1,
        cclass=Union,
        height=LG_PLATE_INNER_HEIGHT
):
    """Return Plate Cylinder."""
    result = cclass()

    for cyl_x in range(1, length):
        for cyl_y in range(1, width):
            result.append(
                Object(
                    get_lg_cylinder(cclass, height),
                    Translate(Vector(cyl_x * LGBW, cyl_y * LGBW, 0))
                )
            )

    return result
Exemplo n.º 31
0
 def test_normalize(self):
     '''
         Test sut.normalize()
     '''
     SUT = Vector(1, 2, 2)
     self.assertEqual(SUT.normalize(), Vector(1.0 / 3, 2.0 / 3, 2.0 / 3))
Exemplo n.º 32
0
 def test_norm(self):
     '''
         Test sut.norm()
     '''
     SUT = Vector(1, 2, 2)
     self.assertEqual(SUT.norm(), 3)
Exemplo n.º 33
0
 def setUp(self):
     '''
         Set up fixture
     '''
     self.sut = Vector(1, 2, 3)
Exemplo n.º 34
0
 def test_createWithVector(self):
     '''
         Test creation and inheritance
     '''
     self.sut = Vector(Vector(1, 2, 3))
     self.assertIsInstance(self.sut, Vector)
Exemplo n.º 35
0
class VectorTestCase(unittest.TestCase):
    '''
        Tests for Vector class
    '''
    def setUp(self):
        '''
            Set up fixture
        '''
        self.sut = Vector(1, 2, 3)

    def test_create(self):
        '''
            Test creation and inheritance
        '''
        self.assertIsInstance(self.sut, Vector)

    def test_createWithVector(self):
        '''
            Test creation and inheritance
        '''
        self.sut = Vector(Vector(1, 2, 3))
        self.assertIsInstance(self.sut, Vector)

    def test_repr(self):
        '''
            Test magic method
        '''
        self.assertEqual(repr(self.sut), "Vector(1, 2, 3)")

    def test_equals(self):
        '''
            Test magic method
        '''
        self.assertEqual(self.sut, Vector(1, 2, 3))

    def test_equalsNoVector(self):
        '''
            Test magic method
        '''
        self.assertNotEqual(self.sut, SceneItem('bar'))

    def test_setattr(self):
        '''
            Test magic method
        '''
        self.sut[1] = 4
        self.assertEqual(self.sut, Vector(1, 4, 3))

    def test_getattr(self):
        '''
            Test magic method
        '''
        self.assertEqual(self.sut[1], 2)

    def test_mul(self):
        '''
            Test magic method
        '''
        self.assertEqual(self.sut * 2, Vector(2, 4, 6))

    def test_rmul(self):
        '''
            Test magic method
        '''
        self.assertEqual(2 * self.sut, Vector(2, 4, 6))

    def test_div(self):
        '''
            Test magic method
        '''
        self.assertEqual(Vector(2, 4, 6) / 2, Vector(1, 2, 3))

    def test_add(self):
        '''
            Test magic method
        '''
        self.assertEqual(self.sut + self.sut, Vector(2, 4, 6))

    def test_sub(self):
        '''
            Test magic method
        '''
        self.assertEqual(Vector(2, 4, 6) - self.sut, self.sut)

    def test_neg(self):
        '''
            Test magic method
        '''
        self.assertEqual(-self.sut, Vector(-1, -2, -3))

    def test_norm(self):
        '''
            Test sut.norm()
        '''
        SUT = Vector(1, 2, 2)
        self.assertEqual(SUT.norm(), 3)

    def test_normalize(self):
        '''
            Test sut.normalize()
        '''
        SUT = Vector(1, 2, 2)
        self.assertEqual(SUT.normalize(), Vector(1.0 / 3, 2.0 / 3, 2.0 / 3))

    def test_dot(self):
        '''
            Test sut.dot()
        '''
        self.assertEqual(self.sut.dot(self.sut), 14)

    def test_mul_wrong_type(self):
        '''
            Test magic method
        '''
        with self.assertRaisesRegexp(
            SdlSyntaxException,
            'Parameter not of type float or int'
        ):
            self.sut * 'foo'

    def test_rmul__WrongType(self):
        '''
            Test magic method
        '''
        with self.assertRaisesRegexp(
            SdlSyntaxException, 'Parameter not of type float or int'
        ):
            'foo' * self.sut

    def test_div__WrongType(self):
        '''
            Test magic method
        '''
        with self.assertRaisesRegexp(
            SdlSyntaxException, 'Parameter not of type float or int'
        ):
            self.sut / 'foo'

    def test_add__WrongType(self):
        '''
            Test magic method
        '''
        with self.assertRaisesRegexp(
            SdlSyntaxException, 'Parameter not of type Vector'
        ):
            self.sut + 'foo'

    def test_sub__WrongType(self):
        '''
            Test magic method
        '''
        with self.assertRaisesRegexp(
            SdlSyntaxException,
            'Parameter not of type Vector'
        ):
            self.sut - 'foo'

    def test_dotWrongType(self):
        '''
            Test sut.dot()
        '''
        with self.assertRaisesRegexp(
            SdlSyntaxException, 'Parameter not of type Vector'
        ):
            self.sut.dot('foo')