Skip to content

Commit

Permalink
replace Point2D with Point2d
Browse files Browse the repository at this point in the history
  • Loading branch information
i-make-robots committed Jun 26, 2024
1 parent c57261f commit cd6c0fa
Show file tree
Hide file tree
Showing 33 changed files with 192 additions and 344 deletions.
6 changes: 4 additions & 2 deletions src/main/java/com/marginallyclever/convenience/Clipper2D.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.marginallyclever.convenience;

import javax.vecmath.Point2d;

/**
* Convenience methods for clipping shapes in 2D
* @author Dan Royer
Expand All @@ -15,7 +17,7 @@ public class Clipper2D {
* @param rMin minimum extent of rectangle
* @return true if some of the line remains, false if the entire line is cut.
*/
public static boolean clipLineToRectangle(Point2D P0,Point2D P1,Point2D rMax,Point2D rMin) {
public static boolean clipLineToRectangle(Point2d P0, Point2d P1, Point2d rMax, Point2d rMin) {
double xLeft = rMin.x;
double xRight = rMax.x;
double yBottom = rMin.y;
Expand Down Expand Up @@ -70,7 +72,7 @@ public static boolean clipLineToRectangle(Point2D P0,Point2D P1,Point2D rMax,Poi
return true; // partially in
}

private static int outCodes(Point2D P,double xLeft,double xRight,double yTop,double yBottom) {
private static int outCodes(Point2d P,double xLeft,double xRight,double yTop,double yBottom) {
int code = 0;
if(P.y > yTop ) code += 1; // code for above
else if(P.y < yBottom) code += 2; // code for below
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.marginallyclever.convenience;

import javax.vecmath.Point2d;
import java.util.ArrayList;
import java.util.Collections;

Expand Down Expand Up @@ -81,11 +82,11 @@ public LineCollection simplify(double distanceTolerance) {
simplifySection(0, size() - 1,distanceTolerance);

LineCollection result = new LineCollection();
Point2D head = get(0).start;
Point2d head = get(0).start;

for (int i = 0; i < size(); i++) {
if (usePt[i]) {
Point2D next = get(i).end;
Point2d next = get(i).end;
result.add(new LineSegment2D(head,next,get(i).color));
head=next;
}
Expand Down Expand Up @@ -119,11 +120,11 @@ private void simplifySection(int i, int j,double distanceTolerance) {
}
}

public Point2D getStart() {
public Point2d getStart() {
return get(0).start;
}

public Point2D getEnd() {
public Point2d getEnd() {
return get(size()-1).end;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.marginallyclever.convenience;

import javax.vecmath.Point2d;
import java.awt.*;

/**
Expand All @@ -8,22 +9,22 @@
*
*/
public class LineSegment2D {
public Point2D start, end;
public Point2d start, end;
public Color color;
// used while processing line segments.
public boolean flag;

public LineSegment2D(Point2D start, Point2D end, Color color) {
public LineSegment2D(Point2d start, Point2d end, Color color) {
super();
this.start = start;
this.end = end;
this.color = color;
}

public void flip() {
Point2D temp= end;
Point2d temp = end;
end = start;
start =temp;
start = temp;
}

public String toString() {
Expand All @@ -38,13 +39,13 @@ public double lengthSquared() {

// The distance measured is the distance between the specified point,
// and the closest point between the start and end points of line a.
public double ptSegDistSq(Point2D point) {
public double ptSegDistSq(Point2d point) {
return java.awt.geom.Line2D.ptSegDistSq(start.x, start.y, end.x, end.y, point.x, point.y);
}

// The distance measured is the distance between the specified point
// and the closest point on the infinite extension of line a.
public double ptLineDistSq(Point2D point) {
public double ptLineDistSq(Point2d point) {
return java.awt.geom.Line2D.ptLineDistSq(start.x, start.y, end.x, end.y, point.x, point.y);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ public interface PreviewListener extends EventListener {
* Callback from {@link PreviewPanel} that it is time to render to the WYSIWYG display.
* @param gl the render context
*/
void render(GL3 gl3);
void render(GL3 gl3,ShaderProgram shaderProgram);
}
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ public PreviewPanel(Paper paper, Plotter plotter) {

addListener(paper);
addListener(myTurtleRenderer);
addListener((gl) -> {
addListener((gl,shaderProgram) -> {
if(myPlotterRenderer!=null) {
myPlotterRenderer.render(gl, myPlotter);
myPlotterRenderer.render(gl, myPlotter, shaderProgram);
}
});

Expand Down Expand Up @@ -219,6 +219,7 @@ private void buildToolBar() {

JButton buttonZoomToFit = new JButton(Translator.get("MenuView.zoomFit"));
//buttonZoomToFit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_0, SHORTCUT_CTRL));
buttonZoomToFit.setIcon(new ImageIcon(Objects.requireNonNull(getClass().getResource("/com/marginallyclever/makelangelo/icons8-zoom-to-extents-16.png"))));
buttonZoomToFit.addActionListener((e) -> camera.zoomToFit(myPaper.getPaperWidth(),myPaper.getPaperHeight()));
toolBar.add(buttonZoomToFit);

Expand Down Expand Up @@ -368,7 +369,7 @@ public void display(GLAutoDrawable glautodrawable) {
var list = previewListeners.getListeners(PreviewListener.class);
ArrayUtils.reverse(list);
for( PreviewListener p : list ) {
p.render(gl3);
p.render(gl3,shader);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.jogamp.opengl.GL3;
import com.marginallyclever.convenience.Point2D;
import com.marginallyclever.makelangelo.Mesh;
import com.marginallyclever.makelangelo.apps.previewpanel.ShaderProgram;
import com.marginallyclever.makelangelo.plotter.Plotter;
import com.marginallyclever.makelangelo.plotter.plottersettings.PlotterSettings;

Expand All @@ -19,7 +20,7 @@ public class Cartesian implements PlotterRenderer {


@Override
public void render(GL3 gl,Plotter robot) {
public void render(GL3 gl,Plotter robot, ShaderProgram shaderProgram) {
paintGantryAndHead(gl,robot);
paintMotors(gl,robot);
paintControlBox(gl,robot);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.marginallyclever.makelangelo.apps.previewpanel.plotterrenderer;

import com.jogamp.opengl.GL3;
import com.marginallyclever.makelangelo.apps.previewpanel.ShaderProgram;
import com.marginallyclever.makelangelo.plotter.Plotter;
import com.marginallyclever.makelangelo.plotter.plottersettings.PlotterSettings;

Expand All @@ -12,7 +13,7 @@
public class Makelangelo3 implements PlotterRenderer {

@Override
public void render(GL3 gl,Plotter robot) {
public void render(GL3 gl,Plotter robot, ShaderProgram shaderProgram) {
paintControlBox(gl,robot);
Polargraph.paintMotors(gl,robot);
if(robot.getDidFindHome())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.marginallyclever.makelangelo.apps.previewpanel.plotterrenderer;

import com.jogamp.opengl.GL3;
import com.marginallyclever.makelangelo.apps.previewpanel.ShaderProgram;
import com.marginallyclever.makelangelo.plotter.Plotter;
import com.marginallyclever.makelangelo.plotter.plottersettings.PlotterSettings;

public class Makelangelo3_3 implements PlotterRenderer {

@Override
public void render(GL3 gl,Plotter robot) {
public void render(GL3 gl,Plotter robot, ShaderProgram shaderProgram) {
paintControlBox(gl,robot);
Polargraph.paintMotors(gl,robot);
if(robot.getDidFindHome())
Expand Down
Loading

0 comments on commit cd6c0fa

Please sign in to comment.