Skip to content

Commit

Permalink
Rename to udBezier
Browse files Browse the repository at this point in the history
  • Loading branch information
wtholliday committed Jul 9, 2023
1 parent 1c74c05 commit d77d4d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions Sources/vger/sdf.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ inline float dot2(float2 v) {
return dot(v,v);
}

// Note: this distance isn't actually signed.
inline float sdBezier(float2 pos, float2 A, float2 B, float2 C )
/// Unsigned distance to quadratic bezier curve.
inline float udBezier(float2 pos, float2 A, float2 B, float2 C )
{
// Are the points collinear?
auto M = float2x2{C-A, B-A};
Expand Down Expand Up @@ -206,7 +206,7 @@ inline float sdBezierApprox(float2 p, float2 A, float2 B, float2 C) {
float2 v0 = normalize(B - A), v1 = normalize(C - A);
float det = v0.x * v1.y - v1.x * v0.y;
if(abs(det) < 0.01) {
return sdBezier(p, A, B, C);
return udBezier(p, A, B, C);
}

return length(get_distance_vector(A-p, B-p, C-p));
Expand Down Expand Up @@ -370,7 +370,7 @@ inline float sdPrim(const DEVICE vgerPrim& prim, const DEVICE float2* cvs, float
}

if(!skip) {
d = min(d, sdBezier(p, a, b, c));
d = min(d, udBezier(p, a, b, c));
}

if(lineTest(p, a, c)) {
Expand Down
4 changes: 2 additions & 2 deletions Tests/vgerTests/sdfTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ - (void) testBezierCollinear {
float2 b{1,0};
float2 c{2,0};

auto d = sdBezier(float2{1,1}, a, b, c);
auto d = udBezier(float2{1,1}, a, b, c);
XCTAssertEqualWithAccuracy(d, 1.0, 0.001);

d = sdBezier(float2{1,-1}, a, b, c);
d = udBezier(float2{1,-1}, a, b, c);
XCTAssertEqualWithAccuracy(d, 1.0, 0.001);
}

Expand Down

0 comments on commit d77d4d7

Please sign in to comment.