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