Skip to content

Commit 91d18c4

Browse files
committed
added MAX_POINT_ACCURACY constant to cap number of segments used when
drawing an ellipse
1 parent 7f867db commit 91d18c4

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -504,15 +504,17 @@ public class PGraphicsOpenGL extends PGraphics {
504504
/** Used in round point and ellipse tessellation. The
505505
* number of subdivisions per round point or ellipse is
506506
* calculated with the following formula:
507-
* n = max(N, (TWO_PI * size / F))
507+
* n = min(M, max(N, (TWO_PI * size / F)))
508508
* where size is a measure of the dimensions of the circle
509509
* when projected on screen coordinates. F just sets the
510510
* minimum number of subdivisions, while a smaller F
511511
* would allow to have more detailed circles.
512512
* N = MIN_POINT_ACCURACY
513+
* M = MAX_POINT_ACCURACY
513514
* F = POINT_ACCURACY_FACTOR
514515
*/
515516
final static protected int MIN_POINT_ACCURACY = 20;
517+
final static protected int MAX_POINT_ACCURACY = 200;
516518
final static protected float POINT_ACCURACY_FACTOR = 10.0f;
517519

518520
/** Used in quad point tessellation. */
@@ -2684,8 +2686,8 @@ void rawPoints() {
26842686
int perim;
26852687
if (0 < size) { // round point
26862688
weight = +size / 0.5f;
2687-
perim = PApplet.max(MIN_POINT_ACCURACY,
2688-
(int) (TWO_PI * weight / POINT_ACCURACY_FACTOR)) + 1;
2689+
perim = PApplet.min(MAX_POINT_ACCURACY, PApplet.max(MIN_POINT_ACCURACY,
2690+
(int) (TWO_PI * weight / POINT_ACCURACY_FACTOR))) + 1;
26892691
} else { // Square point
26902692
weight = -size / 0.5f;
26912693
perim = 5;
@@ -8811,9 +8813,9 @@ void addEllipse(float a, float b, float c, float d,
88118813
float sy2 = pgCurrent.screenY(x + w, y + h);
88128814

88138815
int accuracy =
8814-
PApplet.max(MIN_POINT_ACCURACY,
8816+
PApplet.min(MAX_POINT_ACCURACY, PApplet.max(MIN_POINT_ACCURACY,
88158817
(int) (TWO_PI * PApplet.dist(sx1, sy1, sx2, sy2) /
8816-
POINT_ACCURACY_FACTOR));
8818+
POINT_ACCURACY_FACTOR)));
88178819
float inc = (float) SINCOS_LENGTH / accuracy;
88188820

88198821
if (fill) {
@@ -10647,9 +10649,9 @@ void tessellateRoundPoints() {
1064710649
// The number of triangles of each fan depends on the
1064810650
// stroke weight of the point.
1064910651
int nPtVert =
10650-
PApplet.max(MIN_POINT_ACCURACY,
10652+
PApplet.min(MAX_POINT_ACCURACY, PApplet.max(MIN_POINT_ACCURACY,
1065110653
(int) (TWO_PI * strokeWeight /
10652-
POINT_ACCURACY_FACTOR)) + 1;
10654+
POINT_ACCURACY_FACTOR))) + 1;
1065310655
if (PGL.MAX_VERTEX_INDEX1 <= nPtVert) {
1065410656
throw new RuntimeException("Error in point tessellation.");
1065510657
}

core/src/processing/opengl/PShapeOpenGL.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4552,9 +4552,10 @@ protected void rawPoints(PGraphicsOpenGL g) {
45524552
int perim;
45534553
if (0 < size) { // round point
45544554
weight = +size / 0.5f;
4555-
perim = PApplet.max(PGraphicsOpenGL.MIN_POINT_ACCURACY,
4555+
perim = PApplet.min(PGraphicsOpenGL.MAX_POINT_ACCURACY,
4556+
PApplet.max(PGraphicsOpenGL.MIN_POINT_ACCURACY,
45564557
(int) (TWO_PI * weight /
4557-
PGraphicsOpenGL.POINT_ACCURACY_FACTOR)) + 1;
4558+
PGraphicsOpenGL.POINT_ACCURACY_FACTOR))) + 1;
45584559
} else { // Square point
45594560
weight = -size / 0.5f;
45604561
perim = 5;

0 commit comments

Comments
 (0)