Skip to content

Commit 9d8fc84

Browse files
committed
#16 Enable new stroke code
And fix rendering artifacts in testBasic
1 parent ff513bf commit 9d8fc84

2 files changed

Lines changed: 23 additions & 9 deletions

File tree

Sources/vger/sdf.h

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -505,18 +505,23 @@ inline float2 bezier(float2 A, float2 B, float2 C, float t) {
505505
return (1 - t) * (1 - t) * A + 2 * (1 - t) * t * B + t * t * C;
506506
}
507507

508-
inline bool lineTest(float2 p, float2 A, float2 B) {
509-
510-
int cs = (A.y < p.y) * 2 + (B.y < p.y);
511-
512-
if(cs == 0 or cs == 3) return false; // trivial reject
508+
inline bool side(float2 p, float2 A, float2 B) {
513509

514510
auto v = B - A;
515511

516512
// Intersect line with x axis.
517513
float t = (p.y-A.y)/v.y;
518514

519515
return (A.x + t*v.x) > p.x;
516+
}
517+
518+
inline bool lineTest(float2 p, float2 A, float2 B) {
519+
520+
int cs = (A.y < p.y) * 2 + (B.y < p.y);
521+
522+
if(cs == 0 or cs == 3) return false; // trivial reject
523+
524+
return side(p, A, B);
520525

521526
}
522527

@@ -530,8 +535,17 @@ inline bool bezierTest(float2 p, float2 A, float2 B, float2 C) {
530535
float s = (v2.x * v1.y - v1.x * v2.y) / det;
531536
float t = (v0.x * v2.y - v2.x * v0.y) / det;
532537

533-
if(s < 0 or t < 0 or (1-s-t) < 0) {
534-
return false; // outside triangle
538+
// Concave or convex?
539+
// Try to be consistent with lineTest so we don't
540+
// double-flip the inside/outside in edge cases.
541+
if (side(B, A, C)) {
542+
if(s <= 0 or t < 0 or (1-s-t) < 0) {
543+
return false; // outside triangle
544+
}
545+
} else {
546+
if(s < 0 or t < 0 or (1-s-t) < 0) {
547+
return false; // outside triangle
548+
}
535549
}
536550

537551
// Transform to canonical coordinte space.

Sources/vger/vger.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ void vgerStrokeBezier(vgerContext vg, vgerBezierSegment s, float width, vgerPain
250250

251251
if(!vg->checkPaint(paint)) return;
252252

253-
#if 0
253+
#if 1
254254
// Improve quality of beziers by rendering as fills.
255255

256256
// 90 degrees CCW
@@ -272,7 +272,7 @@ void vgerStrokeBezier(vgerContext vg, vgerBezierSegment s, float width, vgerPain
272272
vgerFill(vg, paint);
273273
#endif
274274

275-
#if 1
275+
#if 0
276276

277277
// Are the points degenerate?
278278
// This may not work in general because these are pre-transformed coordinates.

0 commit comments

Comments
 (0)