Search in sources :

Example 6 with Point2f

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

the class Frame method getAbsolutePosition.

/**
 * Gets the center position of the frame in mm, relative to the page.
 */
public final Point2f getAbsolutePosition() {
    Point2f ret = position;
    if (parent != null) {
        ret = MathUtils.INSTANCE.rotate(ret, parent.getAbsoluteRotation());
        ret = ret.add(parent.getAbsolutePosition());
    }
    return ret;
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f)

Example 7 with Point2f

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

the class Frame method getCenterLP.

/**
 * Gets the {@link LayoutPos} of the center of the frame.
 * If this frame is not part of a layout, the page index -1 is returned.
 */
public final LayoutPos getCenterLP() {
    Point2f pos = getAbsolutePosition();
    Layout layout = getParentLayout();
    Page page = getParentPage();
    int pageIndex = (page != null ? page.getIndex() : -1);
    return layoutPos(layout, pageIndex, pos);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) Layout(com.xenoage.zong.layout.Layout) Page(com.xenoage.zong.layout.Page)

Example 8 with Point2f

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

the class Frame method getPagePosition.

/**
 * Transforms the given coordinates in frame space to
 * a position in page space.
 *
 * Untested for higher levels
 */
@Untested
public final Point2f getPagePosition(Point2f p) {
    Point2f ret = p;
    Frame frame = this;
    if (parent != null) {
        if (frame.rotation != 0f)
            ret = MathUtils.INSTANCE.rotate(ret, frame.rotation);
        ret = ret.add(frame.position);
    }
    return parent.getPagePosition(p);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) Untested(com.xenoage.utils.annotations.Untested)

Example 9 with Point2f

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

the class MathUtilsTest method rotateTest.

/**
 * Tests the rotate-method.
 */
@Test
public void rotateTest() {
    Point2f p = new Point2f(10, 5);
    Point2f res;
    // angle 0
    res = rotate(p, 0);
    assertEquals(10, res.x, DRf);
    assertEquals(5, res.y, DRf);
    // angle 90
    res = rotate(p, 90);
    assertEquals(5, res.x, DRf);
    assertEquals(-10, res.y, DRf);
    // angle 122
    res = rotate(p, 122);
    double cos = Math.cos(122 * Math.PI / 180f);
    double sin = Math.sin(122 * Math.PI / 180f);
    assertEquals(10 * cos + 5 * sin, res.x, DRf);
    assertEquals(10 * -sin + 5 * cos, res.y, DRf);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f) Test(org.junit.Test)

Example 10 with Point2f

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

the class BezierCurveTools method computeBezierFrom.

/**
 * Computes a curbic bezier curve from the given quadratic curve.
 * @param curve   the quadratic curve
 * @param startX  the horizontal start coordinate
 * @param endX    the horizontal end coordinate
 */
public static CubicBezierCurve computeBezierFrom(QuadraticCurve curve, float startX, float endX) {
    // compute p1 and p2
    Point2f p1 = p(startX, curve.getY(startX));
    Point2f p2 = p(endX, curve.getY(endX));
    // compute a helper point about in the middle of the curve
    float hx = (startX + endX) / 2;
    Point2f h = p(hx, curve.getY(hx));
    // t ist simply 0.5 :-)
    float t = 0.5f;
    // using the quadratic bezier formula, compute c (the control point of a quadratic bezier curve):
    // c = (h - (1-t)²p1 - t²p2) / (2t(1-t))
    Point2f c = h.sub(p1.scale((1 - t) * (1 - t))).sub(p2.scale(t * t)).scale(1f / (2 * t * (1 - t)));
    // since we want to have a cubic bezier curve, compute c1 and c2 out of p1, p2, and c.
    // this is easy, because the direction of the control points does not change and
    // the length of the distance is multiplied by 2/3
    Point2f c1 = p1.scale(1f / 3).add(c.scale(2f / 3));
    Point2f c2 = p2.scale(1f / 3).add(c.scale(2f / 3));
    return new CubicBezierCurve(p1, c1, c2, p2);
}
Also used : Point2f(com.xenoage.utils.math.geom.Point2f)

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