Search in sources :

Example 16 with Point2f

use of com.xenoage.utils.math.geom.Point2f in project Zong by Xenoage.

the class SimpleSlurShape method createPath.

private Path createPath() {
    List<PathElement> elements = alist(5);
    float cap = interlineSpace / 4;
    elements.add(new MoveTo(p1top));
    // bezier curve from p1top to p2top
    elements.add(new CubicCurveTo(c1top, c2top, p2top));
    // cap at p2
    Point2f capDir = p2top.sub(c2top).normalize().scale(cap);
    elements.add(new CubicCurveTo(p2top.add(capDir), p2bottom.add(capDir), p2bottom));
    // bezier curve back from p2bottom to p1bottom
    elements.add(new CubicCurveTo(c2bottom, c1bottom, p1bottom));
    // cap at p1
    capDir = p1top.sub(c1top).normalize().scale(cap);
    elements.add(new CubicCurveTo(p1bottom.add(capDir), p1top.add(capDir), p1top));
    Path path = new Path(elements);
    return path;
}
Also used : Path(com.xenoage.zong.symbols.path.Path) Point2f(com.xenoage.utils.math.geom.Point2f) PathElement(com.xenoage.zong.symbols.path.PathElement) MoveTo(com.xenoage.zong.symbols.path.MoveTo) CubicCurveTo(com.xenoage.zong.symbols.path.CubicCurveTo)

Example 17 with Point2f

use of com.xenoage.utils.math.geom.Point2f in project Zong by Xenoage.

the class BarlineRenderer method paintLine.

/**
 * Draws the given line with the given width in px.
 */
private static void paintLine(Canvas canvas, RendererArgs args, StaffStamping staff1, float staff1LinePosition, StaffStamping staff2, float staff2LinePosition, float xMm, float widthMm, Color color) {
    if (canvas.getFormat() == CanvasFormat.Raster) {
        float scaling = args.targetScaling;
        BitmapStaff screenStaff1 = staff1.getBitmapInfo().getBitmapStaff(scaling);
        BitmapStaff screenStaff2 = staff2.getBitmapInfo().getBitmapStaff(scaling);
        Point2f p1 = new Point2f(xMm, staff1.positionMm.y + screenStaff1.getYMm(staff1LinePosition));
        Point2f p2 = new Point2f(xMm, staff2.positionMm.y + screenStaff2.getYMm(staff2LinePosition));
        canvas.drawLine(p1, p2, color, widthMm);
    } else if (canvas.getFormat() == CanvasFormat.Vector) {
        Point2f p1 = new Point2f(xMm, staff1.positionMm.y + staff1.is * (staff1.linesCount - 1 - staff1LinePosition / 2));
        Point2f p2 = new Point2f(xMm, staff2.positionMm.y + staff2.is * (staff2.linesCount - 1 - staff2LinePosition / 2));
        canvas.drawLine(p1, p2, color, widthMm);
    }
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)

Example 18 with Point2f

use of com.xenoage.utils.math.geom.Point2f in project Zong by Xenoage.

the class PageTest method getFPTestUnrotated.

/**
 * Tests the computeFramePosition-method
 * without rotation.
 */
@Test
public void getFPTestUnrotated() {
    Layout layout = createPageWithUnrotatedFrames();
    Page page = layout.getPages().get(0);
    // Test 1
    Point2f p = new Point2f(113, 122);
    FP fp = page.getFP(p);
    assertNotNull(fp);
    assertEquals(frm2, fp.getFrame());
    assertEquals(23, fp.getPosition().x, Delta.DELTA_FLOAT);
    assertEquals(12, fp.getPosition().y, Delta.DELTA_FLOAT);
    // Test 2
    p = new Point2f(122, 108);
    fp = page.getFP(p);
    assertNotNull(fp);
    assertEquals(frm2a, fp.getFrame());
    assertEquals(2, fp.getPosition().x, Delta.DELTA_FLOAT);
    assertEquals(-2, fp.getPosition().y, Delta.DELTA_FLOAT);
    // Test 3
    p = new Point2f(86, 88);
    fp = page.getFP(p);
    assertNull(fp);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) FP(com.xenoage.zong.layout.frames.FP) Test(org.junit.Test)

Example 19 with Point2f

use of com.xenoage.utils.math.geom.Point2f in project Zong by Xenoage.

the class FrameTest method getAbsolutePosition.

/**
 * Tests the computation of the absolute position.
 */
@Test
public void getAbsolutePosition() {
    double u = Math.PI / 180d;
    Layout layout = new Layout(null);
    Page page = new Page(PageFormat.Companion.getDefaultValue());
    layout.addPage(page);
    GroupFrame frame = createFrameWithChildren();
    page.addFrame(frame);
    // frame
    Point2f p = frame.getAbsolutePosition();
    assertEquals(50, p.x, Delta.DELTA_FLOAT);
    assertEquals(75, p.y, Delta.DELTA_FLOAT);
    // child frame
    GroupFrame child = (GroupFrame) frame.children.get(0);
    p = child.getAbsolutePosition();
    float r = 30;
    double childX = 50 + 20 * Math.cos(r * u) + 10 * Math.sin(r * u);
    double childY = 75 - 20 * Math.sin(r * u) + 10 * Math.cos(r * u);
    assertEquals(childX, p.x, Delta.DELTA_FLOAT_ROUGH);
    assertEquals(childY, p.y, Delta.DELTA_FLOAT_ROUGH);
    // child frame of child frame
    Frame child2 = child.children.get(0);
    p = child2.getAbsolutePosition();
    r += 30;
    assertEquals(childX + -15 * Math.cos(r * u) + -10 * Math.sin(r * u), p.x, Delta.DELTA_FLOAT_ROUGH);
    assertEquals(childY - -15 * Math.sin(r * u) + -10 * Math.cos(r * u), p.y, Delta.DELTA_FLOAT_ROUGH);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) Layout(com.xenoage.zong.layout.Layout) Page(com.xenoage.zong.layout.Page) Test(org.junit.Test)

Example 20 with Point2f

use of com.xenoage.utils.math.geom.Point2f in project Zong by Xenoage.

the class StaffSymbolRenderer method drawWith.

/**
 * Paints the given symbol using the given information and rendering parameters.
 */
public static void drawWith(Symbol symbol, Color color, SP position, float scaling, StaffStamping parentStaff, boolean mirrorV, Canvas canvas, RendererArgs args) {
    float viewScaling = args.targetScaling;
    float symbolScaling = scaling * parentStaff.is;
    float yPosition;
    if (canvas.getFormat() == CanvasFormat.Raster) {
        BitmapStaff ss = parentStaff.getBitmapInfo().getBitmapStaff(viewScaling);
        yPosition = parentStaff.positionMm.y + ss.getYMm(position.lp);
        symbolScaling *= ss.heightScaling;
    /*
			//TEST
			int x = Units.mmToPx(positionX, viewScaling);
			int yOffset = ss.getYOffsetPx();
			int yTopLine = Units.mmToPx(
			  endStaff.getPosition().y + endStaff.getLineWidth() / 2,
			  viewScaling) + yOffset;
			for (int i = 0; i < 2; i++)
			  params.renderTarget.drawLine(
			  	new Point2i(x + i, yTopLine),
			  	new Point2i(x + i, yTopLine + ss.getHeightPx()), Color.red, 1); */
    } else {
        yPosition = parentStaff.computeYMm(position.lp);
    }
    Point2f correctedPosition = new Point2f(position.xMm, yPosition);
    SymbolsRenderer.draw(symbol, canvas, (color != null ? color : Color.Companion.getBlack()), correctedPosition, new Point2f(symbolScaling, (mirrorV ? -1 : 1) * symbolScaling));
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)

Aggregations

Point2f (com.xenoage.utils.math.geom.Point2f)51 BitmapStaff (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)11 StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)10 Test (org.junit.Test)10 Color (com.xenoage.utils.color.Color)7 Page (com.xenoage.zong.layout.Page)6 Size2f (com.xenoage.utils.math.geom.Size2f)5 Layout (com.xenoage.zong.layout.Layout)5 ScoreFrame (com.xenoage.zong.layout.frames.ScoreFrame)5 BitmapLine (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine)5 Rectangle2f (com.xenoage.utils.math.geom.Rectangle2f)4 FormattedText (com.xenoage.zong.core.text.FormattedText)4 TextMetrics (com.xenoage.utils.font.TextMetrics)3 FormattedTextParagraph (com.xenoage.zong.core.text.FormattedTextParagraph)3 ScoreFrameChain (com.xenoage.zong.layout.frames.ScoreFrameChain)3 ScoreLayout (com.xenoage.zong.musiclayout.ScoreLayout)3 Paint (android.graphics.Paint)2 Point2i (com.xenoage.utils.math.geom.Point2i)2 Size2i (com.xenoage.utils.math.geom.Size2i)2 Score (com.xenoage.zong.core.Score)2