Search in sources :

Example 11 with Rectangle2f

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

the class Path method computeBounds.

private Rectangle2f computeBounds() {
    // just an estimate (curve lines not included, just the points), but ok for now
    float minX = Float.MAX_VALUE, maxX = Float.MIN_VALUE;
    float minY = Float.MAX_VALUE, maxY = Float.MIN_VALUE;
    for (PathElement e : elements) {
        Point2f p = e.getTarget();
        if (p != null) {
            minX = Math.min(minX, p.x);
            maxX = Math.max(maxX, p.x);
            minY = Math.min(minY, p.y);
            maxY = Math.max(maxY, p.y);
        }
    }
    return new Rectangle2f(minX, minY, maxX - minX, maxY - minY);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) Rectangle2f(com.xenoage.utils.math.geom.Rectangle2f)

Example 12 with Rectangle2f

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

the class FrameRenderer method paint.

/**
 * Paints the given {@link Frame} on the
 * given {@link Canvas} using the given {@link RendererArgs}.
 */
public void paint(Frame frame, Canvas canvas, RendererArgs args) {
    // backup old transformation
    canvas.transformSave();
    // apply translation: origin offset in screen space
    canvas.transformTranslate(args.offsetPx.x, args.offsetPx.y);
    // apply scaling
    float scaling = Units.mmToPx(args.scaling, 1);
    canvas.transformScale(scaling, scaling);
    // apply translation: absolute frame position in layout space
    Point2f pos = frame.getAbsolutePosition();
    canvas.transformTranslate(pos.x, pos.y);
    // apply rotation
    canvas.transformRotate(-frame.getAbsoluteRotation());
    // if there is a background, draw it
    if (frame.getBackground() != null) {
        Rectangle2f rect = getLocalRect(frame);
        canvas.fillRect(rect, frame.getBackground());
    }
    // paint the frame
    paintTransformed(frame, canvas, args);
    // restore old transformation
    canvas.transformRestore();
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) Rectangle2f(com.xenoage.utils.math.geom.Rectangle2f)

Example 13 with Rectangle2f

use of com.xenoage.utils.math.geom.Rectangle2f 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 14 with Rectangle2f

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

the class StemRenderer method draw.

/**
 * Draws the given {@link StemStamping} on the given {@link Canvas},
 * using the given {@link RendererArgs}.
 */
@Override
public void draw(Stamping stamping, Canvas canvas, RendererArgs args) {
    StemStamping stem = (StemStamping) stamping;
    float scaling = args.targetScaling;
    // TODO: stem is thinner
    float lineWidthMm = stem.noteStaff.getLineWidthMm();
    Point2f p1Mm = new Point2f(stem.xMm - lineWidthMm / 2, stem.noteStaff.positionMm.y);
    Point2f p2Mm = new Point2f(stem.xMm + lineWidthMm / 2, stem.endStaff.positionMm.y);
    Color color = Color.Companion.getBlack();
    // shorten stem a little bit at the notehead - TODO: looks good. is code ok?
    float noteLp = stem.noteLp + 0.2f * (stem.endLp > stem.noteLp ? 1 : -1);
    if (canvas.getFormat() == CanvasFormat.Raster) {
        // render on screen or print
        BitmapLine screenLine = new BitmapLine(lineWidthMm, color, scaling);
        BitmapStaff noteScreenStaff = stem.noteStaff.getBitmapInfo().getBitmapStaff(scaling);
        BitmapStaff endScreenStaff = stem.endStaff.getBitmapInfo().getBitmapStaff(scaling);
        p1Mm = new Point2f(p1Mm.x, p1Mm.y + noteScreenStaff.getYMm(noteLp));
        p2Mm = new Point2f(p2Mm.x, p2Mm.y + endScreenStaff.getYMm(stem.endLp));
        // ensure same width for each stem in this staff
        float width = screenLine.widthMm;
        canvas.fillRect(new Rectangle2f(p1Mm.x, p1Mm.y, width, p2Mm.y - p1Mm.y), screenLine.color);
    } else if (canvas.getFormat() == CanvasFormat.Vector) {
        // render with high quality
        p1Mm = new Point2f(p1Mm.x, stem.noteStaff.computeYMm(noteLp));
        p2Mm = new Point2f(p2Mm.x, stem.endStaff.computeYMm(stem.endLp));
        canvas.fillRect(new Rectangle2f(p1Mm.x, p1Mm.y, p2Mm.x - p1Mm.x, p2Mm.y - p1Mm.y), color);
    }
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) Color(com.xenoage.utils.color.Color) BitmapLine(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine) Rectangle2f(com.xenoage.utils.math.geom.Rectangle2f) BitmapStaff(com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff) StemStamping(com.xenoage.zong.musiclayout.stampings.StemStamping)

Example 15 with Rectangle2f

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

the class ScoreFrameLayout method getSystemBoundaries.

/**
 * Computes and returns the bounding rectangle of the system with the given index
 * (relative to the frame). Only the staves are regarded, not text around them
 * or notes over the top staff or notes below the bottom staff.
 * If there are no staves in this system, null is returned.
 */
public Rectangle2f getSystemBoundaries(int systemIndex) {
    boolean found = false;
    float minX = Float.MAX_VALUE;
    float minY = Float.MAX_VALUE;
    float maxX = Float.MIN_VALUE;
    float maxY = Float.MIN_VALUE;
    for (StaffStamping staff : staffStampings) {
        if (staff.system.getSystemIndexInFrame() == systemIndex) {
            found = true;
            minX = Math.min(minX, staff.positionMm.x);
            minY = Math.min(minY, staff.positionMm.y);
            maxX = Math.max(maxX, staff.positionMm.x + staff.lengthMm);
            maxY = Math.max(maxY, staff.positionMm.y + (staff.linesCount - 1) * staff.is);
        }
    }
    if (found)
        return new Rectangle2f(minX, minY, maxX - minX, maxY - minY);
    else
        return null;
}
Also used : StaffStamping(com.xenoage.zong.musiclayout.stampings.StaffStamping) Rectangle2f(com.xenoage.utils.math.geom.Rectangle2f)

Aggregations

Rectangle2f (com.xenoage.utils.math.geom.Rectangle2f)15 Point2f (com.xenoage.utils.math.geom.Point2f)4 Color (com.xenoage.utils.color.Color)2 Stamping (com.xenoage.zong.musiclayout.stampings.Stamping)2 ImageFrame (com.xenoage.zong.layout.frames.ImageFrame)1 ScoreFrame (com.xenoage.zong.layout.frames.ScoreFrame)1 TextFrame (com.xenoage.zong.layout.frames.TextFrame)1 ScoreFrameLayout (com.xenoage.zong.musiclayout.ScoreFrameLayout)1 StaffStamping (com.xenoage.zong.musiclayout.stampings.StaffStamping)1 StampingMock (com.xenoage.zong.musiclayout.stampings.StampingMock)1 StemStamping (com.xenoage.zong.musiclayout.stampings.StemStamping)1 BitmapLine (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapLine)1 BitmapStaff (com.xenoage.zong.musiclayout.stampings.bitmap.BitmapStaff)1 Test (org.junit.Test)1