-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7290 from martinleopold/ellipse-fix
Fix ellipseMode(CORNERS) and rectMode(CORNER)
- Loading branch information
Showing
33 changed files
with
202 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
Helper function that draws a shape using the specified shape mode | ||
p5 ............... The p5 Instance | ||
shape ............ The shape to draw. Either 'ellipse', 'arc', or 'rect' | ||
mode ............. The ellipseMode (for ellipse and arc), or rectMode (for rect) | ||
Either p5.CORNERS, p5.CORNER, p5.CENTER or p5.RADIUS | ||
x1, x2, x2, y2 ... Coordinates specifying the shape in CORNERS mode, | ||
i.e. (x1, y1) and (x2, y2) specify two opposite corners P1 and P2 | ||
*/ | ||
function shapeCorners(p5, shape, mode, x1, y1, x2, y2) { | ||
// Adjust coordinates for testing modes other than CORNERS | ||
if (mode === p5.CORNER) { | ||
// Find top left corner | ||
let x = p5.min(x1, x2); // x | ||
let y = p5.min(y1, y2); // y | ||
// Calculate width and height | ||
// Don't use abs(), so we get negative values as well | ||
let w = x2 - x1; // w | ||
let h = y2 - y1; // h | ||
x1 = x; y1 = y; x2 = w; y2 = h; | ||
} else if (mode === p5.CENTER) { | ||
// Find center | ||
let x = (x2 + x1) / 2; // x | ||
let y = (y2 + y1) / 2; // y | ||
// Calculate width and height | ||
// Don't use abs(), so we get negative values as well | ||
let w = x2 - x1; | ||
let h = y2 - y1; | ||
x1 = x; y1 = y; x2 = w; y2 = h; | ||
} else if (mode === p5.RADIUS) { | ||
// Find Center | ||
let x = (x2 + x1) / 2; // x | ||
let y = (y2 + y1) / 2; // y | ||
// Calculate radii | ||
// Don't use abs(), so we get negative values as well | ||
let r1 = (x2 - x1) / 2; // r1; | ||
let r2 = (y2 - y1) / 2; // r2 | ||
x1 = x; y1 = y; x2 = r1; y2 = r2; | ||
} | ||
|
||
if (shape === 'ellipse') { | ||
p5.ellipseMode(mode); | ||
p5.ellipse(x1, y1, x2, y2); | ||
} else if (shape === 'arc') { | ||
// Draw four arcs with gaps inbetween | ||
const GAP = p5.radians(20); | ||
p5.ellipseMode(mode); | ||
p5.arc(x1, y1, x2, y2, 0 + GAP, p5.HALF_PI - GAP); | ||
p5.arc(x1, y1, x2, y2, p5.HALF_PI + GAP, p5.PI - GAP); | ||
p5.arc(x1, y1, x2, y2, p5.PI + GAP, p5.PI + p5.HALF_PI - GAP); | ||
p5.arc(x1, y1, x2, y2, p5.PI + p5.HALF_PI + GAP, p5.TWO_PI - GAP); | ||
} else if (shape === 'rect') { | ||
p5.rectMode(mode); | ||
p5.rect(x1, y1, x2, y2); | ||
} | ||
} | ||
|
||
|
||
/* | ||
Comprehensive test for rendering ellipse(), arc(), and rect() | ||
with the different ellipseMode() / rectMode() values: CORNERS, CORNER, CENTER, RADIUS. | ||
Each of the 3 shapes is tested with each of the 4 possible modes, resulting in 12 test. | ||
Each test renders the shape in 16 different coordinate configurations, | ||
testing combinations of positive and negative coordinate values. | ||
*/ | ||
visualSuite('Shape Modes', function(...args) { | ||
// Shapes to test | ||
const SHAPES = [ 'ellipse', 'arc', 'rect' ]; | ||
|
||
// Modes to test (used with ellipseMode or rectMode, according to shape) | ||
const MODES = [ 'CORNERS', 'CORNER', 'CENTER', 'RADIUS' ]; | ||
|
||
for (let shape of SHAPES) { | ||
visualSuite(`Shape ${shape}`, function() { | ||
|
||
for (let mode of MODES) { | ||
visualTest(`Mode ${mode}`, function(p5, screenshot) { | ||
p5.createCanvas(60, 125); | ||
p5.translate(p5.width/2, p5.height/2); | ||
|
||
// Make the following calls to shapeCorners shorter | ||
// by omitting p5, shape and mode parameters | ||
function _shapeCorners(x1, y1, x2, y2) { | ||
shapeCorners(p5, shape, p5[mode], x1, y1, x2, y2); | ||
} | ||
|
||
// Quadrant I (Bottom Right) | ||
// P1 P2 | ||
_shapeCorners( 5, 5, 25, 15); // P1 Top Left, P2 Bottom Right | ||
_shapeCorners( 5, 20, 25, 30); // P1 Bottom Left, P2 Top Right | ||
_shapeCorners(25, 45, 5, 35); // P1 Bottom Right, P2 Top Left | ||
_shapeCorners(25, 50, 5, 60); // P1 Top Right, P2 Bottom Left | ||
|
||
// Quadrant II (Bottom Left) | ||
_shapeCorners(-25, 5, -5, 15); | ||
_shapeCorners(-25, 20, -5, 30); | ||
_shapeCorners( -5, 45, -25, 35); | ||
_shapeCorners( -5, 50, -25, 60); | ||
|
||
// Quadrant III (Top Left) | ||
_shapeCorners(-25, -60, -5, -50); | ||
_shapeCorners(-25, -35, -5, -45); | ||
_shapeCorners( -5, -20, -25, -30); | ||
_shapeCorners( -5, -15, -25, -5); | ||
|
||
// Quadrant IV (Top Right) | ||
_shapeCorners( 5, -60, 25, -50); | ||
_shapeCorners( 5, -35, 25, -45); | ||
_shapeCorners(25, -20, 5, -30); | ||
_shapeCorners(25, -15, 5, -5); | ||
|
||
screenshot(); | ||
}); // End of: visualTest | ||
} // End of: MODES loop | ||
|
||
}); // End of: Inner visualSuite | ||
} // End of: SHAPES loop | ||
}); // End of: Outer visualSuite |
Binary file added
BIN
+1.17 KB
test/unit/visual/screenshots/Shape Modes/Shape arc/Mode CENTER/000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
test/unit/visual/screenshots/Shape Modes/Shape arc/Mode CENTER/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"numScreenshots": 1 | ||
} |
Binary file added
BIN
+1.17 KB
test/unit/visual/screenshots/Shape Modes/Shape arc/Mode CORNER/000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
test/unit/visual/screenshots/Shape Modes/Shape arc/Mode CORNER/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"numScreenshots": 1 | ||
} |
Binary file added
BIN
+1.17 KB
test/unit/visual/screenshots/Shape Modes/Shape arc/Mode CORNERS/000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
test/unit/visual/screenshots/Shape Modes/Shape arc/Mode CORNERS/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"numScreenshots": 1 | ||
} |
Binary file added
BIN
+1.17 KB
test/unit/visual/screenshots/Shape Modes/Shape arc/Mode RADIUS/000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
test/unit/visual/screenshots/Shape Modes/Shape arc/Mode RADIUS/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"numScreenshots": 1 | ||
} |
Binary file added
BIN
+1.12 KB
test/unit/visual/screenshots/Shape Modes/Shape ellipse/Mode CENTER/000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
test/unit/visual/screenshots/Shape Modes/Shape ellipse/Mode CENTER/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"numScreenshots": 1 | ||
} |
Binary file added
BIN
+1.12 KB
test/unit/visual/screenshots/Shape Modes/Shape ellipse/Mode CORNER/000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
test/unit/visual/screenshots/Shape Modes/Shape ellipse/Mode CORNER/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"numScreenshots": 1 | ||
} |
Binary file added
BIN
+1.12 KB
test/unit/visual/screenshots/Shape Modes/Shape ellipse/Mode CORNERS/000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
test/unit/visual/screenshots/Shape Modes/Shape ellipse/Mode CORNERS/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"numScreenshots": 1 | ||
} |
Binary file added
BIN
+1.12 KB
test/unit/visual/screenshots/Shape Modes/Shape ellipse/Mode RADIUS/000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
test/unit/visual/screenshots/Shape Modes/Shape ellipse/Mode RADIUS/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"numScreenshots": 1 | ||
} |
Binary file added
BIN
+552 Bytes
test/unit/visual/screenshots/Shape Modes/Shape rect/Mode CENTER/000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
test/unit/visual/screenshots/Shape Modes/Shape rect/Mode CENTER/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"numScreenshots": 1 | ||
} |
Binary file added
BIN
+552 Bytes
test/unit/visual/screenshots/Shape Modes/Shape rect/Mode CORNER/000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
test/unit/visual/screenshots/Shape Modes/Shape rect/Mode CORNER/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"numScreenshots": 1 | ||
} |
Binary file added
BIN
+552 Bytes
test/unit/visual/screenshots/Shape Modes/Shape rect/Mode CORNERS/000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
test/unit/visual/screenshots/Shape Modes/Shape rect/Mode CORNERS/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"numScreenshots": 1 | ||
} |
Binary file added
BIN
+552 Bytes
test/unit/visual/screenshots/Shape Modes/Shape rect/Mode RADIUS/000.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions
3
test/unit/visual/screenshots/Shape Modes/Shape rect/Mode RADIUS/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"numScreenshots": 1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters