@@ -17,6 +17,10 @@ function shapeCorners(p5, shape, mode, x1, y1, x2, y2) {
17
17
// Don't use abs(), so we get negative values as well
18
18
let w = x2 - x1 ; // w
19
19
let h = y2 - y1 ; // h
20
+ // With mode CORNER, negative widths/heights result in mirrored/flipped shapes
21
+ // In this case, adjust position so the shape is in line with the other cases
22
+ if ( w < 0 ) { x += ( - w ) ; } // Move right
23
+ if ( h < 0 ) { y += ( - h ) ; } // Move down
20
24
x1 = x ; y1 = y ; x2 = w ; y2 = h ;
21
25
} else if ( mode === p5 . CENTER ) {
22
26
// Find center
@@ -56,14 +60,15 @@ function shapeCorners(p5, shape, mode, x1, y1, x2, y2) {
56
60
}
57
61
58
62
59
- /*
60
- Comprehensive test for rendering ellipse(), arc(), and rect()
61
- with the different ellipseMode() / rectMode() values: CORNERS, CORNER, CENTER, RADIUS.
62
- Each of the 3 shapes is tested with each of the 4 possible modes, resulting in 12 test.
63
- Each test renders the shape in 16 different coordinate configurations,
64
- testing combinations of positive and negative coordinate values.
65
- */
66
63
visualSuite ( 'Shape Modes' , function ( ...args ) {
64
+ /*
65
+ Comprehensive test for rendering ellipse(), arc(), and rect()
66
+ with the different ellipseMode() / rectMode() values: CORNERS, CORNER, CENTER, RADIUS.
67
+ Each of the 3 shapes is tested with each of the 4 possible modes, resulting in 12 tests.
68
+ Each test renders the shape in 16 different coordinate configurations,
69
+ testing combinations of positive and negative coordinate values.
70
+ */
71
+
67
72
// Shapes to test
68
73
const SHAPES = [ 'ellipse' , 'arc' , 'rect' ] ;
69
74
@@ -113,6 +118,55 @@ visualSuite('Shape Modes', function(...args) {
113
118
} ) ; // End of: visualTest
114
119
} // End of: MODES loop
115
120
116
- } ) ; // End of: Inner visualSuite
121
+ } ) ; // End of: visualSuite
117
122
} // End of: SHAPES loop
118
- } ) ; // End of: Outer visualSuite
123
+
124
+
125
+ /*
126
+ An extra test suite specific to shape mode CORNER and negative dimensions.
127
+ Negative width should result in the shape flipped horizontally (to the left).
128
+ Negative height should result in the shape flipped vertically (up).
129
+ */
130
+ visualSuite ( 'Negative dimensions' , function ( ) {
131
+ visualTest ( 'rect' , function ( p5 , screenshot ) {
132
+ p5 . createCanvas ( 50 , 50 ) ;
133
+ p5 . translate ( p5 . width / 2 , p5 . height / 2 ) ;
134
+ p5 . rectMode ( p5 . CORNER ) ;
135
+ p5 . rect ( 0 , 0 , 20 , 10 ) ;
136
+ p5 . fill ( 'red' ) ;
137
+ p5 . rect ( 0 , 0 , - 20 , 10 ) ;
138
+ p5 . fill ( 'green' ) ;
139
+ p5 . rect ( 0 , 0 , 20 , - 10 ) ;
140
+ p5 . fill ( 'blue' ) ;
141
+ p5 . rect ( 0 , 0 , - 20 , - 10 ) ;
142
+ screenshot ( ) ;
143
+ } ) ;
144
+ visualTest ( 'ellipse' , function ( p5 , screenshot ) {
145
+ p5 . createCanvas ( 50 , 50 ) ;
146
+ p5 . translate ( p5 . width / 2 , p5 . height / 2 ) ;
147
+ p5 . ellipseMode ( p5 . CORNER ) ;
148
+ p5 . ellipse ( 0 , 0 , 20 , 10 ) ;
149
+ p5 . fill ( 'red' ) ;
150
+ p5 . ellipse ( 0 , 0 , - 20 , 10 ) ;
151
+ p5 . fill ( 'green' ) ;
152
+ p5 . ellipse ( 0 , 0 , 20 , - 10 ) ;
153
+ p5 . fill ( 'blue' ) ;
154
+ p5 . ellipse ( 0 , 0 , - 20 , - 10 ) ;
155
+ screenshot ( ) ;
156
+ } ) ;
157
+ visualTest ( 'arc' , function ( p5 , screenshot ) {
158
+ p5 . createCanvas ( 50 , 50 ) ;
159
+ p5 . translate ( p5 . width / 2 , p5 . height / 2 ) ;
160
+ p5 . ellipseMode ( p5 . CORNER ) ;
161
+ p5 . arc ( 0 , 0 , 20 , 10 , 0 , p5 . PI + p5 . HALF_PI ) ;
162
+ p5 . fill ( 'red' ) ;
163
+ p5 . arc ( 0 , 0 , - 20 , 10 , 0 , p5 . PI + p5 . HALF_PI ) ;
164
+ p5 . fill ( 'green' ) ;
165
+ p5 . arc ( 0 , 0 , 20 , - 10 , 0 , p5 . PI + p5 . HALF_PI ) ;
166
+ p5 . fill ( 'blue' ) ;
167
+ p5 . arc ( 0 , 0 , - 20 , - 10 , 0 , p5 . PI + p5 . HALF_PI ) ;
168
+ screenshot ( ) ;
169
+ } ) ;
170
+ } ) ;
171
+
172
+ } ) ;
0 commit comments