Esempio n. 1
0
    def diagonal(self):
        '''[summary]
		
		[description]
		'''

        return Line(
            Point(self.point.x, self.point.y),
            Point(self.point.x + self.width, self.point.y + self.height))
Esempio n. 2
0
	def test_points (self):
		r = Rectangle(Point(0,0), 1, 1)
		p = [
			Point(0,0),
			Point(1,0),
			Point(1,1),
			Point(0,1)
		]

		x = r.points()

		self.assertEqual(len(x), len(p))

		for i in range(len(x)):
			self.assertEqual(x[i],p[i])
Esempio n. 3
0
File: Line.py Progetto: csdm/OMotion
	def center (self):
		'''[summary]
		
		[description]
		''' 

		return Point((self.p0.x + self.p1.x)/2, (self.p0.y + self.p1.y)/2)
Esempio n. 4
0
    def fromCv(t):
        '''

		'''
        point, size, angle = t

        if not isinstance(point, tuple)             or \
           not len(point) == 2                      or \
           not isinstance(point[0], numbers.Number) or \
           not isinstance(point[1], numbers.Number)    :
            raise ValueError('Invalid Point parameter')

        if not isinstance(size, tuple)             or \
           not len(size) == 2                      or \
           not isinstance(size[0], numbers.Number) or \
           not isinstance(size[1], numbers.Number)    :
            raise ValueError('Invalid Size parameter')

        if not isinstance(angle, numbers.Number):
            raise ValueError('Invalid Angle Parameter')

        return RotatedRectangle(
            Point(point[0],
                  point[1]).polar(-(size[1] / 2),
                                  Converter.degrees2radians(angle - 90)).polar(
                                      size[0] / 2,
                                      Converter.degrees2radians(angle - 180)),
            size[0], size[1], Converter.degrees2radians(angle - 90))
Esempio n. 5
0
    def center(self):
        '''[summary]
		
		[description]
		'''

        return Point(self.point.x + self.width / 2,
                     self.point.y + self.height / 2)
Esempio n. 6
0
	def test_edges_2 (self):
		r = Rectangle(Point(0,0), 1, 1)
		l = [
			Line(Point(0, 0), Point(1, 0)),
			Line(Point(1, 1), Point(1, 0)),
			Line(Point(0, 1), Point(1, 1)),
			Line(Point(0, 0), Point(0, 1)),
		]

		x = r.edges()

		self.assertEqual(len(x), len(l))

		for i in range(len(x)):
			self.assertEqual(x[i], l[i])
Esempio n. 7
0
    def test_filter(self):

        f = RectAreaFilter(150, 950)

        r = [
            Rectangle(Point(0, 0), 10, 10),  #100  -- no
            Rectangle(Point(0, 0), 20, 20),  #400  -- yes
            Rectangle(Point(0, 0), 30, 30),  #900  -- yes
            Rectangle(Point(0, 0), 40, 40),  #1600 -- no
            Rectangle(Point(0, 0), 50, 50),  #2500 -- no
        ]

        s = ProxRectAnalizer.filter(r, [f])

        self.assertIn(Rectangle(Point(0, 0), 20, 20), s)
        self.assertIn(Rectangle(Point(0, 0), 30, 30), s)
Esempio n. 8
0
    def test_multiple_filter(self):

        f = RectAreaFilter(300, 500)
        g = RectAreaFilter(800, 950)

        r = [
            Rectangle(Point(0, 0), 10, 10),  #100  -- no
            Rectangle(Point(0, 0), 20, 20),  #400  -- yes (in f)
            Rectangle(Point(0, 0), 30, 30),  #900  -- yes (in g)
            Rectangle(Point(0, 0), 40, 40),  #1600 -- no
            Rectangle(Point(0, 0), 50, 50),  #2500 -- no
        ]

        s = ProxRectAnalizer.filter(r, [f, g])

        self.assertIn(Rectangle(Point(0, 0), 20, 20), s)
        self.assertIn(Rectangle(Point(0, 0), 30, 30), s)
Esempio n. 9
0
	def test_length (self):
		l = Line(Point(0,0), Point(0,1))

		self.assertEqual(l.length(), 1)
Esempio n. 10
0
 def test_inside_area_rect(self):
     # check rectangle of area 5x5 > 9, < 100
     # should return true
     r = Rectangle(Point(0, 0), 5, 5)  # area = 5 x 5 = 25
     self.assertTrue(self.f.toFilter(r))
Esempio n. 11
0
	def test_diagonal (self):
		r = Rectangle(Point(0,0), 10, 10)
		d = Line(Point(0,0), Point(10,10))
		self.assertEqual(r.diagonal(), d) 
Esempio n. 12
0
	def test_center (self):
		r = Rectangle(Point(0,0),10,10)
		p = Point(5,5)
		self.assertEqual(r.center(), p)
Esempio n. 13
0
 def test_lower_bound_area_rect(self):
     # check rectangle of area 3x3 = 9
     # should return true
     r = Rectangle(Point(0, 0), 3, 3)  # area = 3 x 3 = 9
     self.assertTrue(self.f.toFilter(r))
Esempio n. 14
0
 def test_upper_bound_area_rect(self):
     # check rectangle of area 10x10 = 100
     # should return true
     r = Rectangle(Point(0, 0), 10, 10)  # area = 10 x 10 = 100
     self.assertTrue(self.f.toFilter(r))
Esempio n. 15
0
 def test_upper_area_rect(self):
     # check rectangle of area 11x11 > 100
     # should return false
     r = Rectangle(Point(0, 0), 11, 11)  # area = 11 x 11 = 121
     self.assertFalse(self.f.toFilter(r))
Esempio n. 16
0
    def test_polar_coordinate_4(self):
        a = Point(1, 1)
        b = a.polar(1, math.pi / 2)
        c = Point(1, 2)

        self.assertEqual(b, c)
Esempio n. 17
0
    def test_polar_coordinate_3(self):
        a = Point(0, 0)
        b = a.polar(-1, 0)
        c = Point(-1, 0)

        self.assertEqual(b, c)
Esempio n. 18
0
    def test_polar_coordinate_2(self):
        a = Point(0, 0)
        b = a.polar(0, 0)

        self.assertEqual(a, b)
Esempio n. 19
0
 def test_invalid_coordinate(self):
     with self.assertRaises(ValueError):
         Point('foo', [1, 2, 34])
Esempio n. 20
0
 def test_valid_coordinate(self):
     Point(3, 4.4)
Esempio n. 21
0
 def polar(point, distance, angle):
     return Point(point.x + distance * math.cos(angle),
                  point.y + distance * math.sin(angle))
Esempio n. 22
0
 def test_lower_area_rect(self):
     # check rectangle of area 1x1 < 9
     # should return false
     r = Rectangle(Point(0, 0), 1, 1)  # area = 1 x 1 = 1
     self.assertFalse(self.f.toFilter(r))