Search in sources :

Example 31 with Point2f

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

the class PageTest method getFPTestRotated.

/**
 * Tests the computeFramePosition-method with rotation.
 * See PageTest.odg in this folder.
 */
@Test
public void getFPTestRotated() {
    Layout layout = createPageWithRotatedFrames();
    Page page = layout.getPages().get(0);
    FP fp;
    float delta = 1;
    // Test 1 (yellow)
    fp = page.getFP(p(162.1f, 96.1f));
    assertNull(fp);
    fp = page.getFP(p(163f, 107.3f));
    assertNull(fp);
    fp = page.getFP(p(163f, 100.4f));
    assertNotNull(fp);
    assertEquals(frm1, fp.getFrame());
    Point2f pExpected = p(27, -38);
    assertEquals(pExpected.x, fp.getPosition().x, delta);
    assertEquals(pExpected.y, fp.getPosition().y, delta);
    // Test 2 (green)
    fp = page.getFP(p(137, 145));
    assertEquals(frm1, fp.getFrame());
    fp = page.getFP(p(130, 160));
    assertEquals(frm1, fp.getFrame());
    fp = page.getFP(p(132, 152.1f));
    assertEquals(frm3, fp.getFrame());
    fp = page.getFP(p(137, 152.1f));
    assertEquals(frm3, fp.getFrame());
    // Test 3 (orange)
    fp = page.getFP(p(100, 85));
    assertEquals(frm2, fp.getFrame());
    fp = page.getFP(p(102, 90));
    assertEquals(frm2, fp.getFrame());
    fp = page.getFP(p(102, 95));
    assertEquals(frm2a, fp.getFrame());
    pExpected = p(-2, -4);
    assertEquals(pExpected.x, fp.getPosition().x, delta);
    assertEquals(pExpected.y, fp.getPosition().y, delta);
    fp = page.getFP(p(109, 84));
    assertEquals(frm1, fp.getFrame());
    fp = page.getFP(p(105, 82.1f));
    assertNull(fp);
    // Test 4 (red)
    fp = page.getFP(p(82, 130));
    assertEquals(frm2b, fp.getFrame());
    pExpected = p(-8, -9);
    assertEquals(pExpected.x, fp.getPosition().x, delta);
    assertEquals(pExpected.y, fp.getPosition().y, delta);
    fp = page.getFP(p(76, 127.1f));
    assertEquals(frm2, fp.getFrame());
    fp = page.getFP(p(75, 135));
    assertEquals(frm2, fp.getFrame());
    fp = page.getFP(p(75, 139));
    assertEquals(frm1, fp.getFrame());
    fp = page.getFP(p(75, 144.1f));
    assertEquals(frm3, fp.getFrame());
    fp = page.getFP(p(70, 137.1f));
    assertNull(fp);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) FP(com.xenoage.zong.layout.frames.FP) Test(org.junit.Test)

Example 32 with Point2f

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

the class FrameTest method createFrameWithChildren.

public static GroupFrame createFrameWithChildren() {
    // frame
    GroupFrame frame = new GroupFrame();
    frame.setPosition(new Point2f(50, 75));
    frame.setSize(new Size2f(80, 50));
    frame.setRotation(30);
    // child frame
    GroupFrame child = new GroupFrame();
    child.setPosition(new Point2f(20, 10));
    child.setSize(new Size2f(30, 20));
    child.setRotation(30);
    // child frame of child frame
    TestFrame child2 = new TestFrame();
    child2.setPosition(new Point2f(-15, -10));
    child2.setSize(new Size2f(5, 5));
    child2.setRotation(45);
    // hierarchy
    child.addChildFrame(child2);
    frame.addChildFrame(child);
    return frame;
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) Size2f(com.xenoage.utils.math.geom.Size2f)

Example 33 with Point2f

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

the class ScoreFrameLayoutTest method getLayoutElementAt.

@Test
public void getLayoutElementAt() {
    /* 0    5   10   15    20    | 0
		 *                             
		 *       ***********           2
		 *  +----*   [0]   *     
		 *  |    *         *~~~~~~~    4
		 *  |[1] ***********      |
		 *  +--------+       [2]  |    6
		 *     |                  |
		 *     ~~~~~~~~~~~~~~~~~~~~    8
		 */
    Stamping[] stampings = new Stamping[3];
    StampingMock s1 = new StampingMock(Level.Music, new Rectangle2f(6, 2, 10, 3));
    stampings[0] = s1;
    StampingMock s2 = new StampingMock(Level.Staff, new Rectangle2f(1, 3, 9, 3));
    stampings[1] = s2;
    StampingMock s3 = new StampingMock(Level.EmptySpace, new Rectangle2f(4, 4, 19, 4));
    stampings[2] = s3;
    ScoreFrameLayout layout = new ScoreFrameLayout(null, new ArrayList<>(), alist(stampings), new ArrayList<>());
    // no hit (but empty space)
    assertTrue(isNot(layout.getStampingAt(new Point2f(0, 0)), s1, s2, s3));
    assertTrue(isNot(layout.getStampingAt(new Point2f(3, 7)), s1, s2, s3));
    assertTrue(isNot(layout.getStampingAt(new Point2f(17, 3)), s1, s2, s3));
    // single hit
    assertEquals(s1, layout.getStampingAt(new Point2f(10, 2)));
    assertEquals(s2, layout.getStampingAt(new Point2f(3, 5)));
    assertEquals(s3, layout.getStampingAt(new Point2f(22, 8)));
    // intersection hit
    assertEquals(s1, layout.getStampingAt(new Point2f(15, 4)));
    assertEquals(s2, layout.getStampingAt(new Point2f(5, 5)));
    assertEquals(s1, layout.getStampingAt(new Point2f(8, 4)));
}
Also used : Stamping(com.xenoage.zong.musiclayout.stampings.Stamping) Point2f(com.xenoage.utils.math.geom.Point2f) Rectangle2f(com.xenoage.utils.math.geom.Rectangle2f) StampingMock(com.xenoage.zong.musiclayout.stampings.StampingMock) Test(org.junit.Test)

Example 34 with Point2f

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

the class SlurRenderer method draw.

/**
 * Draws the given {@link SlurStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    SlurStamping slur = (SlurStamping) stamping;
    float scaling = args.targetScaling;
    // compute absolute coordinates in px
    float p1xMm = slur.p1.xMm;
    float p2xMm = slur.p2.xMm;
    float c1xMm = p1xMm + slur.c1.xMm;
    float c2xMm = p2xMm + slur.c2.xMm;
    float p1yMm = 0, p2yMm = 0, c1yMm = 0, c2yMm = 0;
    if (canvas.getFormat() == CanvasFormat.Raster) {
        float staff1YMm = slur.staff1.positionMm.y;
        float staff2YMm = slur.staff2.positionMm.y;
        BitmapStaff screenStaff1 = slur.staff1.getBitmapInfo().getBitmapStaff(scaling);
        BitmapStaff screenStaff2 = slur.staff2.getBitmapInfo().getBitmapStaff(scaling);
        float bottomLineMm1 = staff1YMm + screenStaff1.lp0Mm;
        float bottomLineMm2 = staff2YMm + screenStaff2.lp0Mm;
        float isMm1 = screenStaff1.interlineSpaceMm;
        float isMm2 = screenStaff2.interlineSpaceMm;
        p1yMm = bottomLineMm1 - isMm1 * slur.p1.lp / 2;
        p2yMm = bottomLineMm2 - isMm2 * slur.p2.lp / 2;
        c1yMm = p1yMm - isMm1 * slur.c1.lp / 2;
        c2yMm = p2yMm - isMm2 * slur.c2.lp / 2;
    } else if (canvas.getFormat() == CanvasFormat.Vector) {
        p1yMm = slur.staff1.computeYMm(slur.p1.lp);
        p2yMm = slur.staff2.computeYMm(slur.p2.lp);
        c1yMm = slur.staff1.computeYMm(slur.p1.lp + slur.c1.lp);
        c2yMm = slur.staff2.computeYMm(slur.p2.lp + slur.c2.lp);
    }
    Point2f p1 = new Point2f(p1xMm, p1yMm);
    Point2f p2 = new Point2f(p2xMm, p2yMm);
    Point2f c1 = new Point2f(c1xMm, c1yMm);
    Point2f c2 = new Point2f(c2xMm, c2yMm);
    Color color = Color.Companion.getBlack();
    /* //TEST
		Point2i lastPoint = new Point2i(MathTools.bezier(p1, p2, c1, c2, 0));
		for (int i = 1; i <= iterations; i++)
		{
			float t = 1f * i / iterations;
			float width = 0.7f + (0.5f - Math.abs(t - 0.5f)) * 2.5f;
			Point2i p = new Point2i(MathTools.bezier(p1, p2, c1, c2, t));
		  params.renderTarget.drawLine(lastPoint, p, color, MathTools.clampMin((int) (scaling * width), 1));
		  lastPoint = p;
		} */
    SimpleSlurShape slurShape = new SimpleSlurShape(p1, p2, c1, c2, slur.staff1.is);
    canvas.fillPath(slurShape.getPath(), color);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) Color(com.xenoage.utils.color.Color) SlurStamping(com.xenoage.zong.musiclayout.stampings.SlurStamping) BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff) SimpleSlurShape(com.xenoage.zong.renderer.slur.SimpleSlurShape)

Example 35 with Point2f

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

the class StaffCursorRenderer method draw.

/**
 * Draws the given {@link StaffCursorStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    StaffCursorStamping cursor = (StaffCursorStamping) stamping;
    float viewScaling = args.targetScaling;
    StaffStamping parentStaff = cursor.parentStaff;
    float x, y1, y2;
    if (canvas.getFormat() == CanvasFormat.Raster) {
        float staffY = parentStaff.positionMm.y;
        BitmapStaff ss = parentStaff.getBitmapInfo().getBitmapStaff(viewScaling);
        // top: one interline space above staff
        y1 = staffY + ss.getYMm(parentStaff.linesCount * 2);
        // bottom: one interline space under staff
        y2 = staffY + ss.getYMm(-2);
    } else {
        y1 = parentStaff.computeYMm(parentStaff.linesCount * 2);
        y2 = parentStaff.computeYMm(-2);
    }
    x = parentStaff.positionMm.x + cursor.xMm + cursor.offsetIs * parentStaff.is;
    canvas.drawLine(new Point2f(x, y1), new Point2f(x, y2), Companion.color(30, 200, 30), getCursorWidth(viewScaling));
}
Also used : StaffCursorStamping(com.xenoage.zong.musiclayout.stampings.StaffCursorStamping) Point2f(com.xenoage.utils.math.geom.Point2f) StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) 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