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;
}
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);
}
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);
}
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);
}
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);
}
Aggregations