use of javax.vecmath.Point3d in project JMRI by JMRI.
the class PositionFileTest method testRW.
public void testRW() throws IOException, org.jdom2.JDOMException {
PositionFile fout = new PositionFile();
fout.prepare();
fout.setReceiver(2, new Point3d(1.0f, 2.0f, 3.0f), true);
Reading rout = new Reading("21", new double[] { 11, 12, 13, 14 });
fout.setCalibrationPoint(new Point3d(-1.0f, -2.0f, -3.0f), rout);
FileUtil.createDirectory("temp");
fout.store(new File("temp" + File.separator + "PositionFileTest.xml"));
PositionFile fin = new PositionFile();
fin.loadFile(new File("temp" + File.separator + "PositionFileTest.xml"));
Point3d p;
p = fin.getReceiverPosition(2);
checkPoint3d(new Point3d(1.0f, 2.0f, 3.0f), p);
Assert.assertEquals("no 2nd receiver position", null, fin.getReceiverPosition(3));
p = fin.getCalibrationPosition(0);
checkPoint3d(new Point3d(-1.0f, -2.0f, -3.0f), p);
Assert.assertEquals("no 2nd calibration position", null, fin.getCalibrationPosition(1));
Reading rin = fin.getCalibrationReading(0);
checkReading(rout, rin);
Assert.assertEquals("no 2nd calibration reading", null, fin.getCalibrationReading(1));
}
use of javax.vecmath.Point3d in project JMRI by JMRI.
the class RegionTest method testEquals.
public void testEquals() {
// square
Region r1 = new Region(new Point3d[] { new Point3d(0., 0., 0.), new Point3d(1., 0., 0.), new Point3d(1., 1., 0.), new Point3d(0., 1., 0.) });
Region r2 = new Region(new Point3d[] { new Point3d(0., 0., 0.), new Point3d(1., 0., 0.), new Point3d(1., 1., 0.), new Point3d(0., 1., 0.) });
Region r3 = new Region(new Point3d[] { new Point3d(0., 0., 0.), new Point3d(2., 0., 0.), new Point3d(1., 1., 0.), new Point3d(0., 1., 0.) });
Region r4 = new Region(new Point3d[] { new Point3d(0., 0., 0.), new Point3d(1., 0., 0.), new Point3d(1., 1., 0.) });
Assert.assertTrue("r1==r2", r1.equals(r2));
Assert.assertTrue("r1!=r3", !r1.equals(r3));
Assert.assertTrue("r1!=r4", !r1.equals(r4));
Assert.assertTrue("r4==r4", r4.equals(r4));
}
use of javax.vecmath.Point3d in project JMRI by JMRI.
the class RegionTest method testInside2.
public void testInside2() {
// C chape
Region r = new Region(new Point3d[] { new Point3d(0., 0., 0.), new Point3d(3., 0., 0.), new Point3d(3., 1., 0.), new Point3d(1., 1., 0.), new Point3d(1., 2., 0.), new Point3d(2., 2., 0.), new Point3d(2., 3., 0.), new Point3d(0., 3., 0.), new Point3d(0., 0., 0.) });
Assert.assertTrue("inside", r.isInside(new Point3d(0.5, 0.5, 0.)));
Assert.assertTrue("outside", !r.isInside(new Point3d(-0.5, 0.5, 0.)));
Assert.assertTrue("outside", !r.isInside(new Point3d(0.5, -0.5, 0.)));
Assert.assertTrue("outside", !r.isInside(new Point3d(1.5, 1.5, 0.)));
Assert.assertTrue("outside", !r.isInside(new Point3d(3.0, 1.5, 0.)));
}
use of javax.vecmath.Point3d in project JMRI by JMRI.
the class RegionTest method testCtors.
public void testCtors() {
// square
new Region(new Point3d[] { new Point3d(0., 0., 0.), new Point3d(1., 0., 0.), new Point3d(1., 1., 0.), new Point3d(0., 1., 0.) });
// triangle
new Region(new Point3d[] { new Point3d(0., 0., 0.), new Point3d(1., 0., 0.), new Point3d(1., 1., 0.) });
}
use of javax.vecmath.Point3d in project JMRI by JMRI.
the class AlignmentPanel method load.
void load() {
try {
// request the filename from an open dialog
fci.rescanCurrentDirectory();
int retVal = fci.showOpenDialog(this);
// handle selection or cancel
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = fci.getSelectedFile();
if (log.isInfoEnabled()) {
log.info("located file " + file + " for load");
}
// handle the file
PositionFile pf = new PositionFile();
pf.loadFile(file);
Point3d p;
Reading r;
for (int i = 0; i < NREADINGS; i++) {
p = pf.getCalibrationPosition(i);
if (p != null) {
lines[i].setPoint(p);
} else {
lines[i].setPoint(new Point3d(0.f, 0.f, 0.f));
}
}
for (int i = 0; i < NREADINGS; i++) {
r = pf.getCalibrationReading(i);
lines[i].reset();
if (r != null) {
lines[i].setReading(r);
}
}
} else {
log.info("load cancelled in open dialog");
}
} catch (Exception e) {
log.error("exception during load: " + e);
}
}
Aggregations