java.awt.geom.CubicCurve2D Java Examples

The following examples show how to use java.awt.geom.CubicCurve2D. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Curve.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/** Chop the end of this curve. */
public void chopEnd(double t) {
    int n = list.size();
    t = t * n;
    double di = StrictMath.floor(t);
    int i = (int) di;
    //
    if (i < 0)
        list.clear();
    if (i >= n)
        return;
    while (i + 1 < list.size())
        list.remove(i + 1);
    if (list.isEmpty()) {
        endX = startX;
        endY = startY;
        list.add(new CubicCurve2D.Double(endX, endY, endX, endY, endX, endY, endX, endY));
        return;
    }
    CubicCurve2D.Double tmp = new CubicCurve2D.Double();
    divide(t - di, list.get(i), tmp, new CubicCurve2D.Double());
    list.get(i).setCurve(tmp);
    endX = tmp.x2;
    endY = tmp.y2;
}
 
Example #2
Source File: LivreBase.java    From brModelo with GNU General Public License v3.0 6 votes vote down vote up
public Shape getRegiaoDocumento() {
    if (Regiao == null) {
        final int v1 = getHeight() / 3;
        final int h1 = getWidth() / 2;
        final int repo = v1 / 3;
        final int L = getLeft();
        final int T = getTop();
        final int TH = T + getHeight() - repo;
        final int LW = L + getWidth();
        CubicCurve2D c = new CubicCurve2D.Double();
        c.setCurve(L, TH, L + h1, TH + v1, LW - h1, TH - v1, LW, TH);
        GeneralPath pa = new GeneralPath();

        pa.moveTo(LW, TH);
        pa.lineTo(LW, T);
        pa.lineTo(L, T);
        pa.lineTo(L, TH);
        pa.append(c, true);
        Regiao = pa;
        final int ptToMove = 3;
        this.reposicionePonto[ptToMove] = new Point(0, -repo);
        ptsToMove[ptToMove] = 1;
    }
    return Regiao;
}
 
Example #3
Source File: Spin.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void paintUsing(Graphics g, BX bx) {

    double cx = spin.center.getSX();
    double cy = spin.center.getSY();

    if(spin.use2D) {
      CubicCurve2D.Double curve =
        new CubicCurve2D.Double (sx, sy,
                                 cx, cy,
                                 cx, cy,
                                 bx.sx, bx.sy);

      ((Graphics2D)g).draw(curve);
    } else {
      drawSpline(g, sx, sy,
                 cx, cy,
                 cx, cy,
                 bx.sx, bx.sy, 5);
    }

  }
 
Example #4
Source File: SlurSymbol.java    From audiveris with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void paint (Graphics2D g,
                      Params p,
                      Point location,
                      Alignment alignment)
{
    Point loc = alignment.translatedPoint(TOP_LEFT, p.rect, location);

    CubicCurve2D curve = new CubicCurve2D.Double(
            loc.x,
            loc.y + p.rect.height,
            loc.x + ((3 * p.rect.width) / 10),
            loc.y + (p.rect.height / 5),
            loc.x + (p.rect.width / 2),
            loc.y,
            loc.x + p.rect.width,
            loc.y);

    // Slur
    g.draw(curve);
}
 
Example #5
Source File: BezierCurveTests.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void test_getControlBounds() {
	BezierCurve c0 = new BezierCurve(1, 1, 1, 10, 10, 1, 10, 10);
	assertEquals(new Rectangle(1, 1, 9, 9), c0.getControlBounds());

	BezierCurve c1 = new BezierCurve(1, 5, 5, 8, 10, 1);
	assertEquals(new Rectangle(1, 1, 9, 7), c1.getControlBounds());

	// Check the bounds are comparable to those returned by
	// CubicCurve2D.getBounds2D(), which returns the control polygon bounds
	// as well
	BezierCurve c3 = new BezierCurve(399.05999755859375, 96.6969985961914,
			484.6500244140625, 209.1699981689453, 456.27001953125,
			302.8699951171875, 438.55999755859375, 348.239990234375);
	Rectangle c3CubicCurve2DBounds = AWT2Geometry.toRectangle(
			new CubicCurve2D.Double(399.05999755859375, 96.6969985961914,
					484.6500244140625, 209.1699981689453, 456.27001953125,
					302.8699951171875, 438.55999755859375, 348.239990234375)
							.getBounds2D());
	assertEquals(c3CubicCurve2DBounds.getHeight(),
			c3.getControlBounds().getHeight(), 0.1);
	assertEquals(c3CubicCurve2DBounds.getWidth(),
			c3.getControlBounds().getWidth(), 0.1);
}
 
Example #6
Source File: SlurSymbol.java    From libreveris with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected void paint (Graphics2D g,
                      Params p,
                      Point location,
                      Alignment alignment)
{
    Point loc = alignment.translatedPoint(
            TOP_LEFT,
            p.rect,
            location);

    CubicCurve2D curve = new CubicCurve2D.Double(
            loc.x,
            loc.y + p.rect.height,
            loc.x + ((3 * p.rect.width) / 10),
            loc.y + (p.rect.height / 5),
            loc.x + (p.rect.width / 2),
            loc.y,
            loc.x + p.rect.width,
            loc.y);

    // Slur
    g.draw(curve);
}
 
Example #7
Source File: Curve.java    From org.alloytools.alloy with Apache License 2.0 6 votes vote down vote up
/**
 * Given 0<=t<=1 and an existing curve, divide it into two chunks and store the
 * two chunks into "first" and "second"
 */
public static void divide(double t, CubicCurve2D.Double curve, CubicCurve2D.Double first, CubicCurve2D.Double second) {
    // This algorithm uses de Casteljau's algorithm for chopping one bezier
    // curve into two bezier curves
    first.x1 = curve.x1;
    second.x2 = curve.x2;
    first.ctrlx1 = (1 - t) * curve.x1 + t * curve.ctrlx1;
    double x = (1 - t) * curve.ctrlx1 + t * curve.ctrlx2;
    second.ctrlx2 = (1 - t) * curve.ctrlx2 + t * curve.x2;
    first.ctrlx2 = (1 - t) * first.ctrlx1 + t * x;
    second.ctrlx1 = (1 - t) * x + t * second.ctrlx2;
    second.x1 = first.x2 = (1 - t) * first.ctrlx2 + t * second.ctrlx1;
    // now that we've computed the x coordinates, we now compute the y
    // coordinates
    first.y1 = curve.y1;
    second.y2 = curve.y2;
    first.ctrly1 = (1 - t) * curve.y1 + t * curve.ctrly1;
    double y = (1 - t) * curve.ctrly1 + t * curve.ctrly2;
    second.ctrly2 = (1 - t) * curve.ctrly2 + t * curve.y2;
    first.ctrly2 = (1 - t) * first.ctrly1 + t * y;
    second.ctrly1 = (1 - t) * y + t * second.ctrly2;
    second.y1 = first.y2 = (1 - t) * first.ctrly2 + t * second.ctrly1;
}
 
Example #8
Source File: GeometryTests.java    From workcraft with MIT License 5 votes vote down vote up
@Test
public void oneThirdTest() {
    CubicCurve2D curve = new CubicCurve2D.Double(0, 0, 1, 1, 2, 2, 3, 3);
    CurveSplitResult split = Geometry.splitCubicCurve(curve, 0.3);
    Assertions.assertEquals(0.9, split.curve1.getX2(), 1e-8);
    Assertions.assertEquals(0.9, split.curve2.getY1(), 1e-8);
    Assertions.assertEquals(0.6, split.curve1.getCtrlX2(), 1e-8);
    Assertions.assertEquals(0.6, split.curve1.getCtrlY2(), 1e-8);
    Assertions.assertEquals(1.6, split.curve2.getCtrlX1(), 1e-8);
    Assertions.assertEquals(1.6, split.curve2.getCtrlY1(), 1e-8);
}
 
Example #9
Source File: ContainsTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    CubicCurve2D c = new CubicCurve2D.Double(0, 0, 4, -4, -2, -4, 2, 0);
    Rectangle2D r = new Rectangle2D.Double(0.75, -2.5, 0.5, 2);

    if (c.contains(r)) {
        throw new Exception("The rectangle should not be contained in the curve");
    }
}
 
Example #10
Source File: RenderTests.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    FillCubics.Context cctx = (FillCubics.Context) ctx;
    int size = cctx.size;
    // Note: 2x2 ends up hitting exactly 1 pixel...
    if (size < 2) size = 2;
    int x = cctx.initX;
    int y = cctx.initY;
    int cpoffset = (int) (size/relYmax/2);
    CubicCurve2D curve = cctx.curve;
    Graphics2D g2d = (Graphics2D) cctx.graphics;
    g2d.translate(cctx.orgX, cctx.orgY);
    Color rCArray[] = cctx.colorlist;
    int ci = cctx.colorindex;
    do {
        curve.setCurve(x, y+size/2.0,
                       x+size/2.0, y+size/2.0-cpoffset,
                       x+size/2.0, y+size/2.0+cpoffset,
                       x+size, y+size/2.0);

        if (rCArray != null) {
            g2d.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        g2d.fill(curve);
        if ((x -= 3) < 0) x += cctx.maxX;
        if ((y -= 1) < 0) y += cctx.maxY;
    } while (--numReps > 0);
    cctx.colorindex = ci;
    g2d.translate(-cctx.orgX, -cctx.orgY);
}
 
Example #11
Source File: Slur.java    From libreveris with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create a slur with all the specified parameters.
 *
 * @param part      the containing system part
 * @param glyph     the underlying glyph
 * @param curve     the underlying bezier curve
 * @param below     true if below, false if above
 * @param leftNote  the note on the left
 * @param rightNote the note on the right
 */
public Slur (SystemPart part,
             Glyph glyph,
             CubicCurve2D curve,
             boolean below,
             Note leftNote,
             Note rightNote)
{
    super(part);
    this.glyph = glyph;
    this.curve = curve;
    this.below = below;
    this.leftNote = leftNote;
    this.rightNote = rightNote;

    // Link embraced notes to this slur instance
    if (leftNote != null) {
        leftNote.addSlur(this);
    }

    if (rightNote != null) {
        rightNote.addSlur(this);
    }

    // Tie ?
    tie = isTie(leftNote, rightNote);
}
 
Example #12
Source File: IntersectsTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    CubicCurve2D c = new CubicCurve2D.Double(50.0, 300.0,
                                             150.0, 166.6666717529297,
                                             238.0, 456.66668701171875,
                                             350.0, 300.0);
    Rectangle2D r = new Rectangle2D.Double(260, 300, 10, 10);

    if (!c.intersects(r)) {
        throw new Exception("The rectangle is contained. " +
                            "intersects(Rectangle2D) should return true");
    }
}
 
Example #13
Source File: IntersectsTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    CubicCurve2D c = new CubicCurve2D.Double(50.0, 300.0,
                                             150.0, 166.6666717529297,
                                             238.0, 456.66668701171875,
                                             350.0, 300.0);
    Rectangle2D r = new Rectangle2D.Double(260, 300, 10, 10);

    if (!c.intersects(r)) {
        throw new Exception("The rectangle is contained. " +
                            "intersects(Rectangle2D) should return true");
    }
}
 
Example #14
Source File: IntersectionsTest.java    From pumpernickel with MIT License 5 votes vote down vote up
private Shape getShape(int i) {
	random.setSeed(i * 1000);
	String type = (String) shape.getSelectedItem();
	if (type.equals("All")) {
		int j = random.nextInt(3);
		if (j == 0) {
			type = "Lines";
		} else if (j == 1) {
			type = "Quads";
		} else if (j == 2) {
			type = "Cubics";
		}
	}
	if (type.equals("Lines")) {
		return new Line2D.Double(random.nextDouble() * 100,
				random.nextDouble() * 100, random.nextDouble() * 100,
				random.nextDouble() * 100);
	} else if (type.equals("Quads")) {
		return new QuadCurve2D.Double(random.nextDouble() * 100,
				random.nextDouble() * 100, random.nextDouble() * 100,
				random.nextDouble() * 100, random.nextDouble() * 100,
				random.nextDouble() * 100);
	} else if (type.equals("Cubics")) {
		return new CubicCurve2D.Double(random.nextDouble() * 100,
				random.nextDouble() * 100, random.nextDouble() * 100,
				random.nextDouble() * 100, random.nextDouble() * 100,
				random.nextDouble() * 100, random.nextDouble() * 100,
				random.nextDouble() * 100);
	}
	throw new RuntimeException("unrecognized type \"" + type + "\"");
}
 
Example #15
Source File: FluxNota.java    From brModelo with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Shape getRegiao() {
    if (Regiao == null) {
        final int v1 = getHeight() / 3;
        final int h1 = getWidth() / 2;
        final int repo = v1 / 3;
        final int L = getLeft();
        final int T = getTop();
        final int TH = T + getHeight() - repo;
        final int LW = L + getWidth();

        CubicCurve2D c = new CubicCurve2D.Double();
        c.setCurve(LW, TH, LW - h1, TH - v1, L + h1, TH + v1, L, TH);
        CubicCurve2D c2 = new CubicCurve2D.Double();
        int v2 = v1 / 3;
        c2.setCurve(L, T + v2, L + h1, T + v1 + v2, LW - h1, T - v1 + v2, LW, T + v2);

        GeneralPath pa = new GeneralPath();
        pa.setWindingRule(GeneralPath.WIND_EVEN_ODD);
        pa.append(c2, true);
        pa.lineTo(LW, TH);
        pa.append(c, true);
        pa.lineTo(L,  T + v2);
        pa.closePath();
        
        Regiao = pa;
        int ptToMove = 3;
        this.reposicionePonto[ptToMove] = new Point(0, -repo);
        ptsToMove[ptToMove] = 1;
        ptToMove = 1;
        this.reposicionePonto[ptToMove] = new Point(0, repo);
        ptsToMove[ptToMove] = 1;
    }
    return Regiao;
}
 
Example #16
Source File: Circle.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Report the left-to-right Bézier curve which best approximates the circle arc.
 *
 * @return the Bézier curve
 */
public CubicCurve2D getCurve ()
{
    if (curve == null) {
        computeCurve();
    }

    return curve;
}
 
Example #17
Source File: ShapeUtilities.java    From sis with Apache License 2.0 5 votes vote down vote up
/**
 * Attempts to replace an arbitrary shape by one of the standard Java2D constructs.
 * For example if the given {@code path} is a {@link Path2D} containing only a single
 * line or a quadratic curve, then this method replaces it by a {@link Line2D} or
 * {@link QuadCurve2D} object respectively.
 *
 * @param  path  the shape to replace by a simpler Java2D construct.
 *         This is generally an instance of {@link Path2D}, but not necessarily.
 * @return a simpler Java construct, or {@code path} if no better construct is proposed.
 */
public static Shape toPrimitive(final Shape path) {
    final PathIterator it = path.getPathIterator(null);
    if (!it.isDone()) {
        final double[] buffer = new double[6];
        if (it.currentSegment(buffer) == PathIterator.SEG_MOVETO) {
            it.next();
            if (!it.isDone()) {
                final double x1 = buffer[0];
                final double y1 = buffer[1];
                final int code = it.currentSegment(buffer);
                it.next();
                if (it.isDone()) {
                    if (isFloat(path)) {
                        switch (code) {
                            case PathIterator.SEG_LINETO:  return new       Line2D.Float((float) x1, (float) y1, (float) buffer[0], (float) buffer[1]);
                            case PathIterator.SEG_QUADTO:  return new  QuadCurve2D.Float((float) x1, (float) y1, (float) buffer[0], (float) buffer[1], (float) buffer[2], (float) buffer[3]);
                            case PathIterator.SEG_CUBICTO: return new CubicCurve2D.Float((float) x1, (float) y1, (float) buffer[0], (float) buffer[1], (float) buffer[2], (float) buffer[3], (float) buffer[4], (float) buffer[5]);
                        }
                    } else {
                        switch (code) {
                            case PathIterator.SEG_LINETO:  return new       Line2D.Double(x1,y1, buffer[0], buffer[1]);
                            case PathIterator.SEG_QUADTO:  return new  QuadCurve2D.Double(x1,y1, buffer[0], buffer[1], buffer[2], buffer[3]);
                            case PathIterator.SEG_CUBICTO: return new CubicCurve2D.Double(x1,y1, buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5]);
                        }
                    }
                }
            }
        }
    }
    return path;
}
 
Example #18
Source File: ContainsTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    CubicCurve2D c = new CubicCurve2D.Double(0, 0, 4, -4, -2, -4, 2, 0);
    Rectangle2D r = new Rectangle2D.Double(0.75, -2.5, 0.5, 2);

    if (c.contains(r)) {
        throw new Exception("The rectangle should not be contained in the curve");
    }
}
 
Example #19
Source File: GeometryTests.java    From workcraft with MIT License 5 votes vote down vote up
@Test
public void bordersTest1() {
    CubicCurve2D curve = getSimpleCurve();
    CurveSplitResult split = Geometry.splitCubicCurve(curve, 0);
    Assertions.assertEquals(0.0, split.curve1.getX2(), 1e-8);
    Assertions.assertEquals(0.0, split.curve2.getY1(), 1e-8);
    Assertions.assertEquals(0.0, split.curve1.getCtrlX2(), 1e-8);
    Assertions.assertEquals(0.0, split.curve1.getCtrlY2(), 1e-8);
    Assertions.assertEquals(0.0, split.curve2.getCtrlX1(), 1e-8);
    Assertions.assertEquals(1.0, split.curve2.getCtrlY1(), 1e-8);
}
 
Example #20
Source File: Jaxb.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
CubicFacade (CubicCurve2D curve)
{
    this.x1 = curve.getX1();
    this.y1 = curve.getY1();
    this.ctrlx1 = curve.getCtrlX1();
    this.ctrly1 = curve.getCtrlY1();
    this.ctrlx2 = curve.getCtrlX2();
    this.ctrly2 = curve.getCtrlY2();
    this.x2 = curve.getX2();
    this.y2 = curve.getY2();
}
 
Example #21
Source File: RenderTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    FillCubics.Context cctx = (FillCubics.Context) ctx;
    int size = cctx.size;
    // Note: 2x2 ends up hitting exactly 1 pixel...
    if (size < 2) size = 2;
    int x = cctx.initX;
    int y = cctx.initY;
    int cpoffset = (int) (size/relYmax/2);
    CubicCurve2D curve = cctx.curve;
    Graphics2D g2d = (Graphics2D) cctx.graphics;
    g2d.translate(cctx.orgX, cctx.orgY);
    Color rCArray[] = cctx.colorlist;
    int ci = cctx.colorindex;
    do {
        curve.setCurve(x, y+size/2.0,
                       x+size/2.0, y+size/2.0-cpoffset,
                       x+size/2.0, y+size/2.0+cpoffset,
                       x+size, y+size/2.0);

        if (rCArray != null) {
            g2d.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        g2d.fill(curve);
        if ((x -= 3) < 0) x += cctx.maxX;
        if ((y -= 1) < 0) y += cctx.maxY;
    } while (--numReps > 0);
    cctx.colorindex = ci;
    g2d.translate(-cctx.orgX, -cctx.orgY);
}
 
Example #22
Source File: RenderTests.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    DrawCubics.Context cctx = (DrawCubics.Context) ctx;
    int size = cctx.size;
    // Note: 2x2 ends up hitting exactly 1 pixel...
    if (size < 2) size = 2;
    int x = cctx.initX;
    int y = cctx.initY;
    int cpoffset = (int) (size/relYmax/2);
    CubicCurve2D curve = cctx.curve;
    Graphics2D g2d = (Graphics2D) cctx.graphics;
    g2d.translate(cctx.orgX, cctx.orgY);
    Color rCArray[] = cctx.colorlist;
    int ci = cctx.colorindex;
    do {
        curve.setCurve(x, y+size/2.0,
                       x+size/2.0, y+size/2.0-cpoffset,
                       x+size/2.0, y+size/2.0+cpoffset,
                       x+size, y+size/2.0);

        if (rCArray != null) {
            g2d.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        g2d.draw(curve);
        if ((x -= 3) < 0) x += cctx.maxX;
        if ((y -= 1) < 0) y += cctx.maxY;
    } while (--numReps > 0);
    cctx.colorindex = ci;
    g2d.translate(-cctx.orgX, -cctx.orgY);
}
 
Example #23
Source File: RenderTests.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    FillCubics.Context cctx = (FillCubics.Context) ctx;
    int size = cctx.size;
    // Note: 2x2 ends up hitting exactly 1 pixel...
    if (size < 2) size = 2;
    int x = cctx.initX;
    int y = cctx.initY;
    int cpoffset = (int) (size/relYmax/2);
    CubicCurve2D curve = cctx.curve;
    Graphics2D g2d = (Graphics2D) cctx.graphics;
    g2d.translate(cctx.orgX, cctx.orgY);
    Color rCArray[] = cctx.colorlist;
    int ci = cctx.colorindex;
    do {
        curve.setCurve(x, y+size/2.0,
                       x+size/2.0, y+size/2.0-cpoffset,
                       x+size/2.0, y+size/2.0+cpoffset,
                       x+size, y+size/2.0);

        if (rCArray != null) {
            g2d.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        g2d.fill(curve);
        if ((x -= 3) < 0) x += cctx.maxX;
        if ((y -= 1) < 0) y += cctx.maxY;
    } while (--numReps > 0);
    cctx.colorindex = ci;
    g2d.translate(-cctx.orgX, -cctx.orgY);
}
 
Example #24
Source File: RenderTests.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    DrawCubics.Context cctx = (DrawCubics.Context) ctx;
    int size = cctx.size;
    // Note: 2x2 ends up hitting exactly 1 pixel...
    if (size < 2) size = 2;
    int x = cctx.initX;
    int y = cctx.initY;
    int cpoffset = (int) (size/relYmax/2);
    CubicCurve2D curve = cctx.curve;
    Graphics2D g2d = (Graphics2D) cctx.graphics;
    g2d.translate(cctx.orgX, cctx.orgY);
    Color rCArray[] = cctx.colorlist;
    int ci = cctx.colorindex;
    do {
        curve.setCurve(x, y+size/2.0,
                       x+size/2.0, y+size/2.0-cpoffset,
                       x+size/2.0, y+size/2.0+cpoffset,
                       x+size, y+size/2.0);

        if (rCArray != null) {
            g2d.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        g2d.draw(curve);
        if ((x -= 3) < 0) x += cctx.maxX;
        if ((y -= 1) < 0) y += cctx.maxY;
    } while (--numReps > 0);
    cctx.colorindex = ci;
    g2d.translate(-cctx.orgX, -cctx.orgY);
}
 
Example #25
Source File: IntersectsTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    CubicCurve2D c = new CubicCurve2D.Double(50.0, 300.0,
                                             150.0, 166.6666717529297,
                                             238.0, 456.66668701171875,
                                             350.0, 300.0);
    Rectangle2D r = new Rectangle2D.Double(260, 300, 10, 10);

    if (!c.intersects(r)) {
        throw new Exception("The rectangle is contained. " +
                            "intersects(Rectangle2D) should return true");
    }
}
 
Example #26
Source File: IntersectsTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    CubicCurve2D c = new CubicCurve2D.Double(50.0, 300.0,
                                             150.0, 166.6666717529297,
                                             238.0, 456.66668701171875,
                                             350.0, 300.0);
    Rectangle2D r = new Rectangle2D.Double(260, 300, 10, 10);

    if (!c.intersects(r)) {
        throw new Exception("The rectangle is contained. " +
                            "intersects(Rectangle2D) should return true");
    }
}
 
Example #27
Source File: GeometryTests.java    From workcraft with MIT License 5 votes vote down vote up
@Test
public void bordersTest2() {
    CubicCurve2D curve = getSimpleCurve();
    CurveSplitResult split = Geometry.splitCubicCurve(curve, 1);
    Assertions.assertEquals(1.0, split.curve1.getX2(), 1e-8);
    Assertions.assertEquals(0.0, split.curve2.getY1(), 1e-8);
    Assertions.assertEquals(1.0, split.curve1.getCtrlX2(), 1e-8);
    Assertions.assertEquals(1.0, split.curve1.getCtrlY2(), 1e-8);
    Assertions.assertEquals(1.0, split.curve2.getCtrlX1(), 1e-8);
    Assertions.assertEquals(0.0, split.curve2.getCtrlY1(), 1e-8);
}
 
Example #28
Source File: RenderTests.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    FillCubics.Context cctx = (FillCubics.Context) ctx;
    int size = cctx.size;
    // Note: 2x2 ends up hitting exactly 1 pixel...
    if (size < 2) size = 2;
    int x = cctx.initX;
    int y = cctx.initY;
    int cpoffset = (int) (size/relYmax/2);
    CubicCurve2D curve = cctx.curve;
    Graphics2D g2d = (Graphics2D) cctx.graphics;
    g2d.translate(cctx.orgX, cctx.orgY);
    Color rCArray[] = cctx.colorlist;
    int ci = cctx.colorindex;
    do {
        curve.setCurve(x, y+size/2.0,
                       x+size/2.0, y+size/2.0-cpoffset,
                       x+size/2.0, y+size/2.0+cpoffset,
                       x+size, y+size/2.0);

        if (rCArray != null) {
            g2d.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        g2d.fill(curve);
        if ((x -= 3) < 0) x += cctx.maxX;
        if ((y -= 1) < 0) y += cctx.maxY;
    } while (--numReps > 0);
    cctx.colorindex = ci;
    g2d.translate(-cctx.orgX, -cctx.orgY);
}
 
Example #29
Source File: RenderTests.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public void runTest(Object ctx, int numReps) {
    FillCubics.Context cctx = (FillCubics.Context) ctx;
    int size = cctx.size;
    // Note: 2x2 ends up hitting exactly 1 pixel...
    if (size < 2) size = 2;
    int x = cctx.initX;
    int y = cctx.initY;
    int cpoffset = (int) (size/relYmax/2);
    CubicCurve2D curve = cctx.curve;
    Graphics2D g2d = (Graphics2D) cctx.graphics;
    g2d.translate(cctx.orgX, cctx.orgY);
    Color rCArray[] = cctx.colorlist;
    int ci = cctx.colorindex;
    do {
        curve.setCurve(x, y+size/2.0,
                       x+size/2.0, y+size/2.0-cpoffset,
                       x+size/2.0, y+size/2.0+cpoffset,
                       x+size, y+size/2.0);

        if (rCArray != null) {
            g2d.setColor(rCArray[ci++ & NUM_RANDOMCOLORMASK]);
        }
        g2d.fill(curve);
        if ((x -= 3) < 0) x += cctx.maxX;
        if ((y -= 1) < 0) y += cctx.maxY;
    } while (--numReps > 0);
    cctx.colorindex = ci;
    g2d.translate(-cctx.orgX, -cctx.orgY);
}
 
Example #30
Source File: Curve.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the y position of the given segment at the given point 0 <= t <= 1
 */
private double getY(CubicCurve2D.Double curve, double t) {
    double py = (curve.ctrly1 - curve.y1) * t + curve.y1, qy = (curve.ctrly2 - curve.ctrly1) * t + curve.ctrly1,
                    ry = (curve.y2 - curve.ctrly2) * t + curve.ctrly2;
    double sy = (qy - py) * t + py, ty = (ry - qy) * t + qy;
    return (ty - sy) * t + sy;
}