@@ -17,10 +17,12 @@ function shapeCorners(p5, shape, mode, x1, y1, x2, y2) {
1717 // Don't use abs(), so we get negative values as well
1818 let w = x2 - x1 ; // w
1919 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+ }
2426 x1 = x ; y1 = y ; x2 = w ; y2 = h ;
2527 } else if ( mode === p5 . CENTER ) {
2628 // Find center
@@ -124,10 +126,11 @@ visualSuite('Shape Modes', function(...args) {
124126
125127 /*
126128 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)
129131 */
130132 visualSuite ( 'Negative dimensions' , function ( ) {
133+ // Negative widths/height result in flipped rects.
131134 visualTest ( 'rect' , function ( p5 , screenshot ) {
132135 p5 . createCanvas ( 50 , 50 ) ;
133136 p5 . translate ( p5 . width / 2 , p5 . height / 2 ) ;
@@ -141,6 +144,8 @@ visualSuite('Shape Modes', function(...args) {
141144 p5 . rect ( 0 , 0 , - 20 , - 10 ) ;
142145 screenshot ( ) ;
143146 } ) ;
147+ // Since negative widths/heights are used with their absolute value,
148+ // ellipses are drawn on top of each other, blue one last
144149 visualTest ( 'ellipse' , function ( p5 , screenshot ) {
145150 p5 . createCanvas ( 50 , 50 ) ;
146151 p5 . translate ( p5 . width / 2 , p5 . height / 2 ) ;
@@ -154,6 +159,8 @@ visualSuite('Shape Modes', function(...args) {
154159 p5 . ellipse ( 0 , 0 , - 20 , - 10 ) ;
155160 screenshot ( ) ;
156161 } ) ;
162+ // Since negative widths/heights are used with their absolute value,
163+ // arcs are drawn on top of each other, blue one last.
157164 visualTest ( 'arc' , function ( p5 , screenshot ) {
158165 p5 . createCanvas ( 50 , 50 ) ;
159166 p5 . translate ( p5 . width / 2 , p5 . height / 2 ) ;
0 commit comments