use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class TinyGControllerTest method jogMachineToWhenUsingInchesShouldConvertCoordinates.
@Test
public void jogMachineToWhenUsingInchesShouldConvertCoordinates() throws Exception {
// Given
when(communicator.isConnected()).thenReturn(true);
// Simulate that the machine is running in inches
controller.getCurrentGcodeState().units = Code.G20;
// When
InOrder orderVerifier = inOrder(communicator);
controller.jogMachineTo(new PartialPosition(1.0, 2.0, 3.0, UnitUtils.Units.MM), 1000);
// Then
orderVerifier.verify(communicator, times(1)).queueCommand(any(GcodeCommand.class));
orderVerifier.verify(communicator).streamCommands();
GcodeCommand command = queueCommandArgumentCaptor.getAllValues().get(0);
assertEquals("G20G90G1X0.039Y0.079Z0.118F39.37", command.getCommandString());
assertTrue(command.isGenerated());
assertTrue(command.isTemporaryParserModalChange());
}
use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class GcodeUtilsTest method generateMoveToCommand.
@Test
public void generateMoveToCommand() {
String result = GcodeUtils.generateMoveToCommand("G90", new PartialPosition(1.0, 2.0, 3.1, UnitUtils.Units.MM), 1000.1);
assertEquals("G21G90X1Y2Z3.1F1000.1", result);
result = GcodeUtils.generateMoveToCommand("G90", new PartialPosition(-1.0, -2.0, -3.1, UnitUtils.Units.MM), 1000.1);
assertEquals("G21G90X-1Y-2Z-3.1F1000.1", result);
result = GcodeUtils.generateMoveToCommand("G90", new PartialPosition(-1.0, -2.0, -3.1, UnitUtils.Units.INCH), 10000);
assertEquals("G20G90X-1Y-2Z-3.1F10000", result);
result = GcodeUtils.generateMoveToCommand("G90", new PartialPosition(-1.0, -2.0, -3.1, UnitUtils.Units.INCH), 0);
assertEquals("G20G90X-1Y-2Z-3.1", result);
result = GcodeUtils.generateMoveToCommand("G90", new PartialPosition(-1.0, -2.0, -3.1, UnitUtils.Units.INCH), -10);
assertEquals("G20G90X-1Y-2Z-3.1", result);
result = GcodeUtils.generateMoveToCommand("G90G1", new PartialPosition(-1.0, -2.0, -3.1, UnitUtils.Units.INCH), -10);
assertEquals("G20G90G1X-1Y-2Z-3.1", result);
}
use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class AbstractRotateAction method getCenter.
private Position getCenter(File gcodeFile) throws IOException, GcodeParserException {
List<LineSegment> lineSegments = parseGcodeLinesFromFile(gcodeFile);
// We only care about carving motion, filter those commands out
List<PartialPosition> pointList = lineSegments.parallelStream().filter(lineSegment -> !lineSegment.isFastTraverse()).flatMap(lineSegment -> {
// We map both the start and end points in MM
PartialPosition start = PartialPosition.from(lineSegment.getStart());
PartialPosition end = PartialPosition.from(lineSegment.getEnd());
return Stream.of(start, end);
}).distinct().collect(Collectors.toList());
return MathUtils.getCenter(pointList);
}
use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class MathUtilsTest method orientationWithPointsCollinear.
@Test
public void orientationWithPointsCollinear() {
PartialPosition p1 = new PartialPosition(0d, 0d, UnitUtils.Units.MM);
PartialPosition p2 = new PartialPosition(1d, 1d, UnitUtils.Units.MM);
PartialPosition p3 = new PartialPosition(2d, 2d, UnitUtils.Units.MM);
int orientation = MathUtils.orientation(p1, p2, p3);
assertEquals(MathUtils.COLLINEAR, orientation);
}
use of com.willwinder.universalgcodesender.model.PartialPosition in project Universal-G-Code-Sender by winder.
the class MathUtilsTest method createConvexHullShouldRemoveInternalPoints.
@Test
public void createConvexHullShouldRemoveInternalPoints() {
List<PartialPosition> points = Arrays.asList(new PartialPosition(0d, 0d, UnitUtils.Units.MM), new PartialPosition(0d, 10d, UnitUtils.Units.MM), new PartialPosition(10d, 10d, UnitUtils.Units.MM), new PartialPosition(5d, 5d, UnitUtils.Units.MM));
List<PartialPosition> convexHull = MathUtils.generateConvexHull(points);
assertEquals(3, convexHull.size());
assertEquals(new PartialPosition(0d, 0d, UnitUtils.Units.MM), convexHull.get(0));
assertEquals(new PartialPosition(10d, 10d, UnitUtils.Units.MM), convexHull.get(1));
assertEquals(new PartialPosition(0d, 10d, UnitUtils.Units.MM), convexHull.get(2));
}
Aggregations