< prev index next >
modules/javafx.graphics/src/main/java/com/sun/marlin/Curve.java
Print this page
*** 54,88 ****
void set(float x1, float y1,
float x2, float y2,
float x3, float y3,
float x4, float y4)
{
! ax = 3f * (x2 - x3) + x4 - x1;
! ay = 3f * (y2 - y3) + y4 - y1;
! bx = 3f * (x1 - 2f * x2 + x3);
! by = 3f * (y1 - 2f * y2 + y3);
! cx = 3f * (x2 - x1);
! cy = 3f * (y2 - y1);
dx = x1;
dy = y1;
! dax = 3f * ax; day = 3f * ay;
! dbx = 2f * bx; dby = 2f * by;
}
void set(float x1, float y1,
float x2, float y2,
float x3, float y3)
{
! ax = 0f; ay = 0f;
! bx = x1 - 2f * x2 + x3;
! by = y1 - 2f * y2 + y3;
! cx = 2f * (x2 - x1);
! cy = 2f * (y2 - y1);
dx = x1;
dy = y1;
! dax = 0f; day = 0f;
! dbx = 2f * bx; dby = 2f * by;
}
float xat(float t) {
return t * (t * (t * ax + bx) + cx) + dx;
}
--- 54,88 ----
void set(float x1, float y1,
float x2, float y2,
float x3, float y3,
float x4, float y4)
{
! ax = 3.0f * (x2 - x3) + x4 - x1;
! ay = 3.0f * (y2 - y3) + y4 - y1;
! bx = 3.0f * (x1 - 2.0f * x2 + x3);
! by = 3.0f * (y1 - 2.0f * y2 + y3);
! cx = 3.0f * (x2 - x1);
! cy = 3.0f * (y2 - y1);
dx = x1;
dy = y1;
! dax = 3.0f * ax; day = 3.0f * ay;
! dbx = 2.0f * bx; dby = 2.0f * by;
}
void set(float x1, float y1,
float x2, float y2,
float x3, float y3)
{
! ax = 0.0f; ay = 0.0f;
! bx = x1 - 2.0f * x2 + x3;
! by = y1 - 2.0f * y2 + y3;
! cx = 2.0f * (x2 - x1);
! cy = 2.0f * (y2 - y1);
dx = x1;
dy = y1;
! dax = 0.0f; day = 0.0f;
! dbx = 2.0f * bx; dby = 2.0f * by;
}
float xat(float t) {
return t * (t * (t * ax + bx) + cx) + dx;
}
*** 109,119 ****
int infPoints(float[] pts, int off) {
// inflection point at t if -f'(t)x*f''(t)y + f'(t)y*f''(t)x == 0
// Fortunately, this turns out to be quadratic, so there are at
// most 2 inflection points.
final float a = dax * dby - dbx * day;
! final float b = 2f * (cy * dax - day * cx);
final float c = cy * dbx - cx * dby;
return Helpers.quadraticRoots(a, b, c, pts, off);
}
--- 109,119 ----
int infPoints(float[] pts, int off) {
// inflection point at t if -f'(t)x*f''(t)y + f'(t)y*f''(t)x == 0
// Fortunately, this turns out to be quadratic, so there are at
// most 2 inflection points.
final float a = dax * dby - dbx * day;
! final float b = 2.0f * (cy * dax - day * cx);
final float c = cy * dbx - cx * dby;
return Helpers.quadraticRoots(a, b, c, pts, off);
}
*** 124,138 ****
assert pts.length >= off + 4;
// these are the coefficients of some multiple of g(t) (not g(t),
// because the roots of a polynomial are not changed after multiplication
// by a constant, and this way we save a few multiplications).
! final float a = 2f * (dax*dax + day*day);
! final float b = 3f * (dax*dbx + day*dby);
! final float c = 2f * (dax*cx + day*cy) + dbx*dbx + dby*dby;
final float d = dbx*cx + dby*cy;
! return Helpers.cubicRootsInAB(a, b, c, d, pts, off, 0f, 1f);
}
// Tries to find the roots of the function ROC(t)-w in [0, 1). It uses
// a variant of the false position algorithm to find the roots. False
// position requires that 2 initial values x0,x1 be given, and that the
--- 124,138 ----
assert pts.length >= off + 4;
// these are the coefficients of some multiple of g(t) (not g(t),
// because the roots of a polynomial are not changed after multiplication
// by a constant, and this way we save a few multiplications).
! final float a = 2.0f * (dax*dax + day*day);
! final float b = 3.0f * (dax*dbx + day*dby);
! final float c = 2.0f * (dax*cx + day*cy) + dbx*dbx + dby*dby;
final float d = dbx*cx + dby*cy;
! return Helpers.cubicRootsInAB(a, b, c, d, pts, off, 0.0f, 1.0f);
}
// Tries to find the roots of the function ROC(t)-w in [0, 1). It uses
// a variant of the false position algorithm to find the roots. False
// position requires that 2 initial values x0,x1 be given, and that the
*** 149,166 ****
int rootsOfROCMinusW(float[] roots, int off, final float w, final float err) {
// no OOB exception, because by now off<=6, and roots.length >= 10
assert off <= 6 && roots.length >= 10;
int ret = off;
int numPerpdfddf = perpendiculardfddf(roots, off);
! float t0 = 0f, ft0 = ROCsq(t0) - w*w;
! roots[off + numPerpdfddf] = 1f; // always check interval end points
numPerpdfddf++;
for (int i = off; i < off + numPerpdfddf; i++) {
float t1 = roots[i], ft1 = ROCsq(t1) - w*w;
! if (ft0 == 0f) {
roots[ret++] = t0;
! } else if (ft1 * ft0 < 0f) { // have opposite signs
// (ROC(t)^2 == w^2) == (ROC(t) == w) is true because
// ROC(t) >= 0 for all t.
roots[ret++] = falsePositionROCsqMinusX(t0, t1, w*w, err);
}
t0 = t1;
--- 149,166 ----
int rootsOfROCMinusW(float[] roots, int off, final float w, final float err) {
// no OOB exception, because by now off<=6, and roots.length >= 10
assert off <= 6 && roots.length >= 10;
int ret = off;
int numPerpdfddf = perpendiculardfddf(roots, off);
! float t0 = 0.0f, ft0 = ROCsq(t0) - w*w;
! roots[off + numPerpdfddf] = 1.0f; // always check interval end points
numPerpdfddf++;
for (int i = off; i < off + numPerpdfddf; i++) {
float t1 = roots[i], ft1 = ROCsq(t1) - w*w;
! if (ft0 == 0.0f) {
roots[ret++] = t0;
! } else if (ft1 * ft0 < 0.0f) { // have opposite signs
// (ROC(t)^2 == w^2) == (ROC(t) == w) is true because
// ROC(t) >= 0 for all t.
roots[ret++] = falsePositionROCsqMinusX(t0, t1, w*w, err);
}
t0 = t1;
*** 216,236 ****
return r;
}
private static boolean sameSign(float x, float y) {
// another way is to test if x*y > 0. This is bad for small x, y.
! return (x < 0f && y < 0f) || (x > 0f && y > 0f);
}
// returns the radius of curvature squared at t of this curve
// see http://en.wikipedia.org/wiki/Radius_of_curvature_(applications)
private float ROCsq(final float t) {
// dx=xat(t) and dy=yat(t). These calls have been inlined for efficiency
final float dx = t * (t * dax + dbx) + cx;
final float dy = t * (t * day + dby) + cy;
! final float ddx = 2f * dax * t + dbx;
! final float ddy = 2f * day * t + dby;
final float dx2dy2 = dx*dx + dy*dy;
final float ddx2ddy2 = ddx*ddx + ddy*ddy;
final float ddxdxddydy = ddx*dx + ddy*dy;
return dx2dy2*((dx2dy2*dx2dy2) / (dx2dy2 * ddx2ddy2 - ddxdxddydy*ddxdxddydy));
}
--- 216,236 ----
return r;
}
private static boolean sameSign(float x, float y) {
// another way is to test if x*y > 0. This is bad for small x, y.
! return (x < 0.0f && y < 0.0f) || (x > 0.0f && y > 0.0f);
}
// returns the radius of curvature squared at t of this curve
// see http://en.wikipedia.org/wiki/Radius_of_curvature_(applications)
private float ROCsq(final float t) {
// dx=xat(t) and dy=yat(t). These calls have been inlined for efficiency
final float dx = t * (t * dax + dbx) + cx;
final float dy = t * (t * day + dby) + cy;
! final float ddx = 2.0f * dax * t + dbx;
! final float ddy = 2.0f * day * t + dby;
final float dx2dy2 = dx*dx + dy*dy;
final float ddx2ddy2 = ddx*ddx + ddy*ddy;
final float ddxdxddydy = ddx*dx + ddy*dy;
return dx2dy2*((dx2dy2*dx2dy2) / (dx2dy2 * ddx2ddy2 - ddxdxddydy*ddxdxddydy));
}
< prev index next >