use of com.xenoage.zong.musiclayout.spacer.beam.placement.SingleStaffBeamPlacer.Placement in project Zong by Xenoage.
the class SingleStaffBeamPlacerTest method shortenTest.
@Test
public void shortenTest() {
// the following tests use arbitrary horizontal positions, but normal spacing (not close spacing)
// p104 r1 c1: could be 3.5/sit, but is 3.25/straddle
Placement old = new Placement(5f, 5f);
BeamedStems stems = new BeamedStems(ilist(beamedStem(5, -2, Up), beamedStem(10, -2, Up)));
Placement shortened = testee.shorten(old, Up, stems, 1, Companion.getStaff5Lines());
assertEquals(new Placement(4.5f, 4.5f), shortened);
// p104 r6 c1: could be 3.75/straddle and 3.5/hang, but is 3.5/sit and 3.25/straddle
old = new Placement(-2.5f, -3f);
stems = new BeamedStems(ilist(beamedStem(10, 5, Down), beamedStem(15, 4, Down)));
shortened = testee.shorten(old, Down, stems, 1, Companion.getStaff5Lines());
assertEquals(new Placement(-2f, -2.5f), shortened);
// p104 r7 c1: is not shortened, since then a stem would be shorter than 3 spaces
old = new Placement(-1f, -0.5f);
stems = new BeamedStems(ilist(beamedStem(0, 5, Down), beamedStem(5, 6, Down)));
shortened = testee.shorten(old, Down, stems, 1, Companion.getStaff5Lines());
assertEquals(old, shortened);
// p105 r1 c1: not shortened, because beam line would be within white space
old = new Placement(6f, 6f);
stems = new BeamedStems(ilist(beamedStem(0, -1, Up), beamedStem(8, -1, Up)));
shortened = testee.shorten(old, Up, stems, 1, Companion.getStaff5Lines());
assertEquals(old, shortened);
// p105 r1 c2: could be 3.5/hang, but is 3.25/staddle
old = new Placement(-1f, -1f);
stems = new BeamedStems(ilist(beamedStem(10, 6, Down), beamedStem(15, 6, Down)));
shortened = testee.shorten(old, Down, stems, 1, Companion.getStaff5Lines());
assertEquals(new Placement(-0.5f, -0.5f), shortened);
}
use of com.xenoage.zong.musiclayout.spacer.beam.placement.SingleStaffBeamPlacer.Placement in project Zong by Xenoage.
the class SingleStaffBeamPlacerTest method computeForOneStaffTestRoss.
/**
* Tests with examples from Ross.
*/
@Test
public void computeForOneStaffTestRoss() {
List<Example> examples = new RossBeamSlant().getExamples();
List<ExampleResult> results = alist();
for (Example example : examples) {
// collect data
BeamedStems stems = example.getStems();
Slant slant = singleStaffBeamSlanter.compute(stems, 5);
// run test
Placement offset = testee.compute(slant, stems, 1, StaffLines.Companion.getStaff5Lines());
// check result
ExampleResult result = check(offset, example);
results.add(result);
}
// success, when 100% of the examples are perfect or at least accepted
// print accepted and failed results
int perfect = 0, accepted = 0, failed = 0;
for (ExampleResult result : results) {
if (result.getResult() != Result.Perfect) {
System.out.print(result.getExample().getName() + ": ");
if (result.getResult() == Result.Accepted) {
accepted++;
System.out.print("not perfect, but accepted");
} else {
failed++;
System.out.print("FAILED");
}
if (result.getComment() != null)
System.out.print("; " + result.getComment());
System.out.println();
} else {
perfect++;
}
}
System.out.println(SingleStaffBeamPlacerTest.class.getSimpleName() + ": " + perfect + " perfect, " + accepted + " accepted, " + failed + " failed");
if (failed > 0)
fail();
}
use of com.xenoage.zong.musiclayout.spacer.beam.placement.SingleStaffBeamPlacer.Placement in project Zong by Xenoage.
the class TouchExample method example32nd.
public static TouchExample example32nd(String name, double leftLp, double rightLp, StemDirection stemDir) {
TouchExample ret = new TouchExample();
ret.name = name;
ret.placement = new Placement((float) leftLp, (float) rightLp);
ret.stemDir = stemDir;
// 3 lines, 2 gaps
ret.beamHeightIs = 0.5f + 0.25f + 0.5f + 0.25f + 0.5f;
return ret;
}
use of com.xenoage.zong.musiclayout.spacer.beam.placement.SingleStaffBeamPlacer.Placement in project Zong by Xenoage.
the class SingleStaffBeamPlacerTest method getPlacementTest.
@Test
public void getPlacementTest() {
// exact result: no rounding required
assertEqualsPlacement(new Placement(2, 3.5f), testee.getPlacement(2, 7, 3, 2.3f, 0.75f));
// 0.4 quarter spaces (= 0.2 LP) higher: should be rounded down to same result
assertEqualsPlacement(new Placement(2, 3.5f), testee.getPlacement(2, 7, 3, 2.3f + 0.2f, 0.75f));
// 0.6 quarter spaces (= 0.3 LP) higher: should be rounded up to the next quarter space
assertEqualsPlacement(new Placement(2.5f, 4), testee.getPlacement(2, 7, 3, 2.3f + 0.3f, 0.75f));
}
use of com.xenoage.zong.musiclayout.spacer.beam.placement.SingleStaffBeamPlacer.Placement in project Zong by Xenoage.
the class TouchExample method example8th.
public static TouchExample example8th(String name, double leftLp, double rightLp, StemDirection stemDir) {
TouchExample ret = new TouchExample();
ret.name = name;
ret.placement = new Placement((float) leftLp, (float) rightLp);
ret.stemDir = stemDir;
ret.beamHeightIs = 0.5f;
return ret;
}
Aggregations