@@ -17,10 +17,12 @@ 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
+ // With mode CORNER, rects with negative widths/heights result in mirrored/flipped rendering
21
+ // In this case, adjust position so the rect is in line with the other cases
22
+ if ( shape === 'rect' ) {
23
+ if ( w < 0 ) { x += ( - w ) ; } // Move right
24
+ if ( h < 0 ) { y += ( - h ) ; } // Move down
25
+ }
24
26
x1 = x ; y1 = y ; x2 = w ; y2 = h ;
25
27
} else if ( mode === p5 . CENTER ) {
26
28
// Find center
@@ -124,10 +126,11 @@ visualSuite('Shape Modes', function(...args) {
124
126
125
127
/*
126
128
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
+ For rect, negative widths/heights result in flipped rendering (horizontally/vertically)
130
+ For ellipse and arc, using negative widths/heights has no effect (the absolute value is used)
129
131
*/
130
132
visualSuite ( 'Negative dimensions' , function ( ) {
133
+ // Negative widths/height result in flipped rects.
131
134
visualTest ( 'rect' , function ( p5 , screenshot ) {
132
135
p5 . createCanvas ( 50 , 50 ) ;
133
136
p5 . translate ( p5 . width / 2 , p5 . height / 2 ) ;
@@ -141,6 +144,8 @@ visualSuite('Shape Modes', function(...args) {
141
144
p5 . rect ( 0 , 0 , - 20 , - 10 ) ;
142
145
screenshot ( ) ;
143
146
} ) ;
147
+ // Since negative widths/heights are used with their absolute value,
148
+ // ellipses are drawn on top of each other, blue one last
144
149
visualTest ( 'ellipse' , function ( p5 , screenshot ) {
145
150
p5 . createCanvas ( 50 , 50 ) ;
146
151
p5 . translate ( p5 . width / 2 , p5 . height / 2 ) ;
@@ -154,6 +159,8 @@ visualSuite('Shape Modes', function(...args) {
154
159
p5 . ellipse ( 0 , 0 , - 20 , - 10 ) ;
155
160
screenshot ( ) ;
156
161
} ) ;
162
+ // Since negative widths/heights are used with their absolute value,
163
+ // arcs are drawn on top of each other, blue one last.
157
164
visualTest ( 'arc' , function ( p5 , screenshot ) {
158
165
p5 . createCanvas ( 50 , 50 ) ;
159
166
p5 . translate ( p5 . width / 2 , p5 . height / 2 ) ;
0 commit comments