def test_new(self): RGBColor() RGBColor(1, 2, 3) # Should integer-cast RGBColor(10, 20.5, 30.3) # Will overflow, but otherwise valid RGBColor(400, 400, 400)
def test_color(self): for ct in self.ctypeS: print(ct) l = Landmark(ctype=ct) # default nose.tools.assert_equal(l.color, RGBColor()) c = RGBColor(0, 0, 0) l.color = c nose.tools.assert_equal(l.color, c) c = RGBColor(12, 240, 120) l.color = c nose.tools.assert_equal(l.color, c)
def color(self, c): self._call_cfunc( 'vital_feature_{}_set_color'.format(self._tchar), [self.C_TYPE_PTR, RGBColor.c_ptr_type()], None, self, c )
def color(self): cptr = self._call_cfunc( "vital_feature_color", [self.C_TYPE_PTR], RGBColor.c_ptr_type(), self ) return RGBColor(from_cptr=cptr)
def color(self, c): if self._datatype is None: raise VitalNoTypeInfoException("Type info required but not present") self._call_cfunc( 'vital_feature_{}_set_color'.format(self._tchar), [self.C_TYPE_PTR, RGBColor.c_ptr_type()], [self, c], )
def test_numpy_interaction(self): c = RGBColor(1, 2, 3) # Slicing numpy.testing.assert_almost_equal(c[:2], (1, 2)) numpy.testing.assert_almost_equal(c[1:], (2, 3)) # functions numpy.testing.assert_almost_equal(c[:] + 1, [2, 3, 4]) numpy.testing.assert_almost_equal( numpy.array([1, 2, 3]) + c, [2, 4, 6] )
def test_getitem_access_IndexError(self): c = RGBColor(10, 20, 30) nose.tools.assert_raises( IndexError, c.__getitem__, 4 ) # This apparently currently yields a numpy warning that this will raise # an error in the future, which it already does. So I'm not sure what # the point of the warning is exactly. nose.tools.assert_raises( IndexError, c.__getitem__, 'something random' )
def _new(self, loc, mag, scale, angle, rgb_color): loc = EigenArray.from_iterable(loc, target_ctype=self._datatype, target_shape=(2, 1)) if rgb_color is None: rgb_color = RGBColor() # noinspection PyProtectedMember return self._call_cfunc( 'vital_feature_{}_new'.format(self._tchar), [ EigenArray.c_ptr_type(2, 1, self._datatype), self._datatype, self._datatype, self._datatype, RGBColor.c_ptr_type() ], self.C_TYPE_PTR, loc, mag, scale, angle, rgb_color )
def test_equal(self): for ct in self.C_TYPES: print(ct) l = Landmark(c_type=ct) l2 = Landmark(c_type=ct) nose.tools.assert_equal(l, l2) l = Landmark([1, 1, 1], 42.2, c_type=ct) l2 = Landmark([1, 1, 1], 42.2, c_type=ct) nose.tools.assert_equal(l, l2) norm = [0, 0.5, 0.5] covar = Covariance(3, init_scalar_or_matrix=3) color = RGBColor(2, 1, 5) obs = 43 l.normal = l2.normal = norm l.covariance = l2.covariance = covar l.color = l2.color = color l.observations = l2.observations = obs nose.tools.assert_equal(l, l2)
def test_g(self): nose.tools.assert_equal(RGBColor().g, 255) nose.tools.assert_equal(RGBColor(g=0).g, 0) nose.tools.assert_equal(RGBColor(g=44.4).g, 44) nose.tools.assert_equal(RGBColor(g=400).g, 400 - 256)
def test_r(self): nose.tools.assert_equal(RGBColor().r, 255) nose.tools.assert_equal(RGBColor(r=0).r, 0) nose.tools.assert_equal(RGBColor(r=44.4).r, 44) nose.tools.assert_equal(RGBColor(r=400).r, 400 - 256)
def color(self, c): self._call_cfunc( 'vital_landmark_{}_set_color'.format(self._tchar), [self.C_TYPE_PTR, RGBColor.c_ptr_type()], [self, c], exception_map={1: VitalDynamicCastException})