@@ -105,61 +105,54 @@ def test_corner_center():
105105
106106
107107def test_ellipse_vertices ():
108- center = (2 , 4 )
109- width = 30
110- height = 20
111- angle = 35
112- ellipse = Ellipse (xy = center , width = width , height = height , angle = angle )
108+ # expect 0 for 0 ellipse widht, height
109+ ellipse = Ellipse (xy = (0 , 0 ), width = 0 , height = 0 , angle = 0 )
113110 assert_almost_equal (
114111 ellipse .get_vertices (),
115- [
116- (- 10.287280664334878 , - 4.60364654526569 ),
117- (14.287280664334878 , 12.60364654526569 ),
118- ],
119- )
120- assert_almost_equal (
121- ellipse .get_co_vertices (),
122- [
123- (- 3.7357643635104605 , 12.191520442889917 ),
124- (7.7357643635104605 , - 4.191520442889917 ),
125- ],
126- )
127-
128- assert_almost_equal (
129- Ellipse (xy = (0 , 0 ), width = 0 , height = 0 , angle = 0 ).get_vertices (),
130112 [(0.0 , 0.0 ), (0.0 , 0.0 )],
131113 )
132114 assert_almost_equal (
133- Ellipse (xy = (0 , 0 ), width = 0 , height = 0 , angle = 0 ).get_co_vertices (),
134- [(0.0 , 0.0 ), (0.0 , 0.0 )],
135- )
136-
137- assert_almost_equal (
138- Ellipse (xy = (0 , 0 ), width = 1 , height = 0 , angle = 0 ).get_vertices (),
139- [(- 0.5 , 0.0 ), (0.5 , 0.0 )],
140- )
141- assert_almost_equal (
142- Ellipse (xy = (0 , 0 ), width = 1 , height = 0 , angle = 0 ).get_co_vertices (),
115+ ellipse .get_co_vertices (),
143116 [(0.0 , 0.0 ), (0.0 , 0.0 )],
144117 )
145118
119+ ellipse = Ellipse (xy = (0 , 0 ), width = 2 , height = 1 , angle = 30 )
146120 assert_almost_equal (
147- Ellipse ( xy = ( 0 , 0 ), width = 1 , height = 1 , angle = 0 ) .get_vertices (),
148- [( - 0.5 , 0.0 ), ( 0.5 , 0.0 )],
149- )
150- assert_almost_equal (
151- Ellipse ( xy = ( 0 , 0 ), width = 1 , height = 1 , angle = 0 ). get_co_vertices () ,
152- [( 0.0 , 0.5 ), ( 0.0 , - 0.5 )] ,
153- )
154-
155- assert_almost_equal (
156- Ellipse ( xy = ( 0 , 0 ), width = 1 , height = 0.5 , angle = 90 ). get_vertices ( ),
157- [( 0.0 , - 0.5 ), ( 0.0 , 0.5 ) ],
121+ ellipse .get_vertices (),
122+ [
123+ (
124+ ellipse . center [ 0 ] - ellipse . width / 4 * np . sqrt ( 3 ),
125+ ellipse . center [ 1 ] - ellipse . width / 4 ,
126+ ) ,
127+ (
128+ ellipse . center [ 0 ] + ellipse . width / 4 * np . sqrt ( 3 ),
129+ ellipse . center [ 1 ] + ellipse . width / 4 ,
130+ ),
131+ ],
158132 )
159133 assert_almost_equal (
160- Ellipse (xy = (0 , 0 ), width = 1 , height = 0.5 , angle = 90 ).get_co_vertices (),
161- [(- 0.25 , 0.0 ), (0.25 , 0.0 )],
134+ ellipse .get_co_vertices (),
135+ [
136+ (
137+ ellipse .center [0 ] - ellipse .height / 4 ,
138+ ellipse .center [1 ] + ellipse .height / 4 * np .sqrt (3 ),
139+ ),
140+ (
141+ ellipse .center [0 ] + ellipse .height / 4 ,
142+ ellipse .center [1 ] - ellipse .height / 4 * np .sqrt (3 ),
143+ ),
144+ ],
162145 )
146+ v1 , v2 = np .array (ellipse .get_vertices ())
147+ np .testing .assert_almost_equal ((v1 + v2 ) / 2 , ellipse .center )
148+ v1 , v2 = np .array (ellipse .get_co_vertices ())
149+ np .testing .assert_almost_equal ((v1 + v2 ) / 2 , ellipse .center )
150+
151+ ellipse = Ellipse (xy = (2.252 , - 10.859 ), width = 2.265 , height = 1.98 , angle = 68.78 )
152+ v1 , v2 = np .array (ellipse .get_vertices ())
153+ np .testing .assert_almost_equal ((v1 + v2 ) / 2 , ellipse .center )
154+ v1 , v2 = np .array (ellipse .get_co_vertices ())
155+ np .testing .assert_almost_equal ((v1 + v2 ) / 2 , ellipse .center )
163156
164157
165158def test_rotate_rect ():
0 commit comments