下面列出了怎么用java.awt.geom.QuadCurve2D的API类实例代码及写法,或者点击链接到github查看源代码。
public static int getHorizontalParams(double c0, double cp0,
double cp1, double c1,
double ret[]) {
if (c0 <= cp0 && cp0 <= cp1 && cp1 <= c1) {
return 0;
}
c1 -= cp1;
cp1 -= cp0;
cp0 -= c0;
ret[0] = cp0;
ret[1] = (cp1 - cp0) * 2;
ret[2] = (c1 - cp1 - cp1 + cp0);
int numroots = QuadCurve2D.solveQuadratic(ret, ret);
int j = 0;
for (int i = 0; i < numroots; i++) {
double t = ret[i];
// No splits at t==0 and t==1
if (t > 0 && t < 1) {
if (j < i) {
ret[j] = t;
}
j++;
}
}
return j;
}
public static int getHorizontalParams(double c0, double cp0,
double cp1, double c1,
double ret[]) {
if (c0 <= cp0 && cp0 <= cp1 && cp1 <= c1) {
return 0;
}
c1 -= cp1;
cp1 -= cp0;
cp0 -= c0;
ret[0] = cp0;
ret[1] = (cp1 - cp0) * 2;
ret[2] = (c1 - cp1 - cp1 + cp0);
int numroots = QuadCurve2D.solveQuadratic(ret, ret);
int j = 0;
for (int i = 0; i < numroots; i++) {
double t = ret[i];
// No splits at t==0 and t==1
if (t > 0 && t < 1) {
if (j < i) {
ret[j] = t;
}
j++;
}
}
return j;
}
public static int getHorizontalParams(double c0, double cp0,
double cp1, double c1,
double ret[]) {
if (c0 <= cp0 && cp0 <= cp1 && cp1 <= c1) {
return 0;
}
c1 -= cp1;
cp1 -= cp0;
cp0 -= c0;
ret[0] = cp0;
ret[1] = (cp1 - cp0) * 2;
ret[2] = (c1 - cp1 - cp1 + cp0);
int numroots = QuadCurve2D.solveQuadratic(ret, ret);
int j = 0;
for (int i = 0; i < numroots; i++) {
double t = ret[i];
// No splits at t==0 and t==1
if (t > 0 && t < 1) {
if (j < i) {
ret[j] = t;
}
j++;
}
}
return j;
}
public static int getHorizontalParams(double c0, double cp0,
double cp1, double c1,
double ret[]) {
if (c0 <= cp0 && cp0 <= cp1 && cp1 <= c1) {
return 0;
}
c1 -= cp1;
cp1 -= cp0;
cp0 -= c0;
ret[0] = cp0;
ret[1] = (cp1 - cp0) * 2;
ret[2] = (c1 - cp1 - cp1 + cp0);
int numroots = QuadCurve2D.solveQuadratic(ret, ret);
int j = 0;
for (int i = 0; i < numroots; i++) {
double t = ret[i];
// No splits at t==0 and t==1
if (t > 0 && t < 1) {
if (j < i) {
ret[j] = t;
}
j++;
}
}
return j;
}
public static int getHorizontalParams(double c0, double cp0,
double cp1, double c1,
double ret[]) {
if (c0 <= cp0 && cp0 <= cp1 && cp1 <= c1) {
return 0;
}
c1 -= cp1;
cp1 -= cp0;
cp0 -= c0;
ret[0] = cp0;
ret[1] = (cp1 - cp0) * 2;
ret[2] = (c1 - cp1 - cp1 + cp0);
int numroots = QuadCurve2D.solveQuadratic(ret, ret);
int j = 0;
for (int i = 0; i < numroots; i++) {
double t = ret[i];
// No splits at t==0 and t==1
if (t > 0 && t < 1) {
if (j < i) {
ret[j] = t;
}
j++;
}
}
return j;
}
public static int getHorizontalParams(double c0, double cp0,
double cp1, double c1,
double ret[]) {
if (c0 <= cp0 && cp0 <= cp1 && cp1 <= c1) {
return 0;
}
c1 -= cp1;
cp1 -= cp0;
cp0 -= c0;
ret[0] = cp0;
ret[1] = (cp1 - cp0) * 2;
ret[2] = (c1 - cp1 - cp1 + cp0);
int numroots = QuadCurve2D.solveQuadratic(ret, ret);
int j = 0;
for (int i = 0; i < numroots; i++) {
double t = ret[i];
// No splits at t==0 and t==1
if (t > 0 && t < 1) {
if (j < i) {
ret[j] = t;
}
j++;
}
}
return j;
}
public static int getHorizontalParams(double c0, double cp0,
double cp1, double c1,
double[] ret) {
if (c0 <= cp0 && cp0 <= cp1 && cp1 <= c1) {
return 0;
}
c1 -= cp1;
cp1 -= cp0;
cp0 -= c0;
ret[0] = cp0;
ret[1] = (cp1 - cp0) * 2;
ret[2] = (c1 - cp1 - cp1 + cp0);
int numroots = QuadCurve2D.solveQuadratic(ret, ret);
int j = 0;
for (int i = 0; i < numroots; i++) {
double t = ret[i];
// No splits at t==0 and t==1
if (t > 0 && t < 1) {
if (j < i) {
ret[j] = t;
}
j++;
}
}
return j;
}
public static int getHorizontalParams(double c0, double cp0,
double cp1, double c1,
double ret[]) {
if (c0 <= cp0 && cp0 <= cp1 && cp1 <= c1) {
return 0;
}
c1 -= cp1;
cp1 -= cp0;
cp0 -= c0;
ret[0] = cp0;
ret[1] = (cp1 - cp0) * 2;
ret[2] = (c1 - cp1 - cp1 + cp0);
int numroots = QuadCurve2D.solveQuadratic(ret, ret);
int j = 0;
for (int i = 0; i < numroots; i++) {
double t = ret[i];
// No splits at t==0 and t==1
if (t > 0 && t < 1) {
if (j < i) {
ret[j] = t;
}
j++;
}
}
return j;
}
public static int getHorizontalParams(double c0, double cp0,
double cp1, double c1,
double ret[]) {
if (c0 <= cp0 && cp0 <= cp1 && cp1 <= c1) {
return 0;
}
c1 -= cp1;
cp1 -= cp0;
cp0 -= c0;
ret[0] = cp0;
ret[1] = (cp1 - cp0) * 2;
ret[2] = (c1 - cp1 - cp1 + cp0);
int numroots = QuadCurve2D.solveQuadratic(ret, ret);
int j = 0;
for (int i = 0; i < numroots; i++) {
double t = ret[i];
// No splits at t==0 and t==1
if (t > 0 && t < 1) {
if (j < i) {
ret[j] = t;
}
j++;
}
}
return j;
}
public static int getHorizontalParams(double c0, double cp0,
double cp1, double c1,
double ret[]) {
if (c0 <= cp0 && cp0 <= cp1 && cp1 <= c1) {
return 0;
}
c1 -= cp1;
cp1 -= cp0;
cp0 -= c0;
ret[0] = cp0;
ret[1] = (cp1 - cp0) * 2;
ret[2] = (c1 - cp1 - cp1 + cp0);
int numroots = QuadCurve2D.solveQuadratic(ret, ret);
int j = 0;
for (int i = 0; i < numroots; i++) {
double t = ret[i];
// No splits at t==0 and t==1
if (t > 0 && t < 1) {
if (j < i) {
ret[j] = t;
}
j++;
}
}
return j;
}
public static int getHorizontalParams(double c0, double cp0,
double cp1, double c1,
double ret[]) {
if (c0 <= cp0 && cp0 <= cp1 && cp1 <= c1) {
return 0;
}
c1 -= cp1;
cp1 -= cp0;
cp0 -= c0;
ret[0] = cp0;
ret[1] = (cp1 - cp0) * 2;
ret[2] = (c1 - cp1 - cp1 + cp0);
int numroots = QuadCurve2D.solveQuadratic(ret, ret);
int j = 0;
for (int i = 0; i < numroots; i++) {
double t = ret[i];
// No splits at t==0 and t==1
if (t > 0 && t < 1) {
if (j < i) {
ret[j] = t;
}
j++;
}
}
return j;
}
public static int getHorizontalParams(double c0, double cp0,
double cp1, double c1,
double ret[]) {
if (c0 <= cp0 && cp0 <= cp1 && cp1 <= c1) {
return 0;
}
c1 -= cp1;
cp1 -= cp0;
cp0 -= c0;
ret[0] = cp0;
ret[1] = (cp1 - cp0) * 2;
ret[2] = (c1 - cp1 - cp1 + cp0);
int numroots = QuadCurve2D.solveQuadratic(ret, ret);
int j = 0;
for (int i = 0; i < numroots; i++) {
double t = ret[i];
// No splits at t==0 and t==1
if (t > 0 && t < 1) {
if (j < i) {
ret[j] = t;
}
j++;
}
}
return j;
}
public static int getHorizontalParams(double c0, double cp0, double cp1,
double c1, double ret[]) {
if (c0 <= cp0 && cp0 <= cp1 && cp1 <= c1) {
return 0;
}
c1 -= cp1;
cp1 -= cp0;
cp0 -= c0;
ret[0] = cp0;
ret[1] = (cp1 - cp0) * 2;
ret[2] = (c1 - cp1 - cp1 + cp0);
int numroots = QuadCurve2D.solveQuadratic(ret, ret);
int j = 0;
for (int i = 0; i < numroots; i++) {
double t = ret[i];
// No splits at t==0 and t==1
if (t > 0 && t < 1) {
if (j < i) {
ret[j] = t;
}
j++;
}
}
return j;
}
/**
* Creates the shape for a top tab.
*
* @param x
* @param y
* @param w
* @param h
* @param rTop
* @param addBottom
* if {@code false}, the bottom line below the tab will not be added to the shape
* @return
*/
private static Path2D createTopTabShape(int x, int y, int w, int h, double rTop, boolean addBottom) {
Path2D path = new Path2D.Double();
path.append(new Line2D.Double(x, y + h - 1, x, y + rTop), true);
QuadCurve2D curve = new QuadCurve2D.Double(x, y + rTop, x, y, x + rTop, y);
path.append(curve, true);
path.append(new Line2D.Double(x + rTop, y, x + w - rTop, y), true);
curve = new QuadCurve2D.Double(x + w - rTop, y, x + w, y, x + w, y + rTop);
path.append(curve, true);
path.append(new Line2D.Double(x + w, y + rTop, x + w, y + h), true);
if (addBottom) {
path.append(new Line2D.Double(x + w, y + h - 1, x, y + h - 1), true);
}
return path;
}
/**
* Creates the shape for a left tab.
*
* @param x
* @param y
* @param w
* @param h
* @param rLeft
* @param addSide
* if {@code false}, the closing side line right of the tab will not be added to the
* shape
* @return
*/
private static Path2D createLeftTabShape(int x, int y, int w, int h, double rLeft, boolean addSide) {
Path2D path = new Path2D.Double();
path.append(new Line2D.Double(x + w, y + h, x + rLeft, y + h), true);
QuadCurve2D curve = new QuadCurve2D.Double(x + rLeft, y + h, x, y + h, x, y + h - rLeft);
path.append(curve, true);
path.append(new Line2D.Double(x, y + h - rLeft, x, y + rLeft), true);
curve = new QuadCurve2D.Double(x, y + rLeft, x, y, x + rLeft, y);
path.append(curve, true);
path.append(new Line2D.Double(x + rLeft, y, x + w, y), true);
if (addSide) {
path.append(new Line2D.Double(x + w, y, x + w, y + h - 1), true);
}
return path;
}
public static int getHorizontalParams(double c0, double cp0,
double cp1, double c1,
double ret[]) {
if (c0 <= cp0 && cp0 <= cp1 && cp1 <= c1) {
return 0;
}
c1 -= cp1;
cp1 -= cp0;
cp0 -= c0;
ret[0] = cp0;
ret[1] = (cp1 - cp0) * 2;
ret[2] = (c1 - cp1 - cp1 + cp0);
int numroots = QuadCurve2D.solveQuadratic(ret, ret);
int j = 0;
for (int i = 0; i < numroots; i++) {
double t = ret[i];
// No splits at t==0 and t==1
if (t > 0 && t < 1) {
if (j < i) {
ret[j] = t;
}
j++;
}
}
return j;
}
public static int getHorizontalParams(double c0, double cp0,
double cp1, double c1,
double ret[]) {
if (c0 <= cp0 && cp0 <= cp1 && cp1 <= c1) {
return 0;
}
c1 -= cp1;
cp1 -= cp0;
cp0 -= c0;
ret[0] = cp0;
ret[1] = (cp1 - cp0) * 2;
ret[2] = (c1 - cp1 - cp1 + cp0);
int numroots = QuadCurve2D.solveQuadratic(ret, ret);
int j = 0;
for (int i = 0; i < numroots; i++) {
double t = ret[i];
// No splits at t==0 and t==1
if (t > 0 && t < 1) {
if (j < i) {
ret[j] = t;
}
j++;
}
}
return j;
}
protected QuadCurve2D getCurvedLine(int index) {
double x1 = from.drawx;
double x2 = to.drawx;
double y1 = from.drawy;
double y2 = to.drawy;
double midx = calculateMidPointBetween(x1, x2);
double midy = calculateMidPointBetween(y1, y2);
int weight = index / 2;
if (index % 2 == 1) {
weight++;
weight = -weight;
}
Dimension offset = calculateOffset(x1, x2, y1, y2, LOADING * weight);
QuadCurve2D curve = new QuadCurve2D.Double(x1, y1,
midx-offset.width, midy+offset.height,
x2, y2);
return curve;
}
public double nextVertical(double t0, double t1) {
double eqn[] = {xcoeff1, 2 * xcoeff2, 3 * xcoeff3};
int numroots = QuadCurve2D.solveQuadratic(eqn, eqn);
for (int i = 0; i < numroots; i++) {
if (eqn[i] > t0 && eqn[i] < t1) {
t1 = eqn[i];
}
}
return t1;
}
public void enlarge(Rectangle2D r) {
r.add(x0, y0);
double eqn[] = {xcoeff1, 2 * xcoeff2, 3 * xcoeff3};
int numroots = QuadCurve2D.solveQuadratic(eqn, eqn);
for (int i = 0; i < numroots; i++) {
double t = eqn[i];
if (t > 0 && t < 1) {
r.add(XforT(t), YforT(t));
}
}
r.add(x1, y1);
}
public double nextVertical(double t0, double t1) {
double eqn[] = {xcoeff1, 2 * xcoeff2, 3 * xcoeff3};
int numroots = QuadCurve2D.solveQuadratic(eqn, eqn);
for (int i = 0; i < numroots; i++) {
if (eqn[i] > t0 && eqn[i] < t1) {
t1 = eqn[i];
}
}
return t1;
}
public void enlarge(Rectangle2D r) {
r.add(x0, y0);
double eqn[] = {xcoeff1, 2 * xcoeff2, 3 * xcoeff3};
int numroots = QuadCurve2D.solveQuadratic(eqn, eqn);
for (int i = 0; i < numroots; i++) {
double t = eqn[i];
if (t > 0 && t < 1) {
r.add(XforT(t), YforT(t));
}
}
r.add(x1, y1);
}
public double nextVertical(double t0, double t1) {
double eqn[] = {xcoeff1, 2 * xcoeff2, 3 * xcoeff3};
int numroots = QuadCurve2D.solveQuadratic(eqn, eqn);
for (int i = 0; i < numroots; i++) {
if (eqn[i] > t0 && eqn[i] < t1) {
t1 = eqn[i];
}
}
return t1;
}
public void enlarge(Rectangle2D r) {
r.add(x0, y0);
double eqn[] = {xcoeff1, 2 * xcoeff2, 3 * xcoeff3};
int numroots = QuadCurve2D.solveQuadratic(eqn, eqn);
for (int i = 0; i < numroots; i++) {
double t = eqn[i];
if (t > 0 && t < 1) {
r.add(XforT(t), YforT(t));
}
}
r.add(x1, y1);
}
public double nextVertical(double t0, double t1) {
double eqn[] = {xcoeff1, 2 * xcoeff2, 3 * xcoeff3};
int numroots = QuadCurve2D.solveQuadratic(eqn, eqn);
for (int i = 0; i < numroots; i++) {
if (eqn[i] > t0 && eqn[i] < t1) {
t1 = eqn[i];
}
}
return t1;
}
public void enlarge(Rectangle2D r) {
r.add(x0, y0);
double eqn[] = {xcoeff1, 2 * xcoeff2, 3 * xcoeff3};
int numroots = QuadCurve2D.solveQuadratic(eqn, eqn);
for (int i = 0; i < numroots; i++) {
double t = eqn[i];
if (t > 0 && t < 1) {
r.add(XforT(t), YforT(t));
}
}
r.add(x1, y1);
}
/**
* Tests {@link ShapeUtilities#toPrimitive(Shape)}.
*/
@Test
public void testToPrimitive() {
final Path2D path = new Path2D.Double();
path.moveTo(4, 5);
path.lineTo(7, 9);
Shape p = ShapeUtilities.toPrimitive(path);
assertInstanceOf("toPrimitive", Line2D.class, p);
assertEquals("P1", new Point2D.Double(4, 5), ((Line2D) p).getP1());
assertEquals("P2", new Point2D.Double(7, 9), ((Line2D) p).getP2());
path.reset();
path.moveTo(4, 5);
path.quadTo(6, 7, 8, 5);
p = ShapeUtilities.toPrimitive(path);
assertInstanceOf("toPrimitive", QuadCurve2D.class, p);
assertEquals("P1", new Point2D.Double(4, 5), ((QuadCurve2D) p).getP1());
assertEquals("CtrlPt", new Point2D.Double(6, 7), ((QuadCurve2D) p).getCtrlPt());
assertEquals("P2", new Point2D.Double(8, 5), ((QuadCurve2D) p).getP2());
path.reset();
path.moveTo(4, 5);
path.curveTo(6, 7, 8, 6, 9, 4);
p = ShapeUtilities.toPrimitive(path);
assertInstanceOf("toPrimitive", CubicCurve2D.class, p);
assertEquals("P1", new Point2D.Double(4, 5), ((CubicCurve2D) p).getP1());
assertEquals("CtrlP1", new Point2D.Double(6, 7), ((CubicCurve2D) p).getCtrlP1());
assertEquals("CtrlP2", new Point2D.Double(8, 6), ((CubicCurve2D) p).getCtrlP2());
assertEquals("P2", new Point2D.Double(9, 4), ((CubicCurve2D) p).getP2());
}
public void enlarge(Rectangle2D r) {
r.add(x0, y0);
double eqn[] = {xcoeff1, 2 * xcoeff2, 3 * xcoeff3};
int numroots = QuadCurve2D.solveQuadratic(eqn, eqn);
for (int i = 0; i < numroots; i++) {
double t = eqn[i];
if (t > 0 && t < 1) {
r.add(XforT(t), YforT(t));
}
}
r.add(x1, y1);
}
public double nextVertical(double t0, double t1) {
double eqn[] = {xcoeff1, 2 * xcoeff2, 3 * xcoeff3};
int numroots = QuadCurve2D.solveQuadratic(eqn, eqn);
for (int i = 0; i < numroots; i++) {
if (eqn[i] > t0 && eqn[i] < t1) {
t1 = eqn[i];
}
}
return t1;
}
public void enlarge(Rectangle2D r) {
r.add(x0, y0);
double eqn[] = {xcoeff1, 2 * xcoeff2, 3 * xcoeff3};
int numroots = QuadCurve2D.solveQuadratic(eqn, eqn);
for (int i = 0; i < numroots; i++) {
double t = eqn[i];
if (t > 0 && t < 1) {
r.add(XforT(t), YforT(t));
}
}
r.add(x1, y1);
}