private void fillMap(Map<Double, EnumFacing> map, double x, double y, EnumFacing... dirs) { map.put(Line2D.ptLineDistSq(0, 0, 1, 0, x, y), dirs[0]); map.put(Line2D.ptLineDistSq(0, 1, 1, 1, x, y), dirs[1]); map.put(Line2D.ptLineDistSq(0, 0, 0, 1, x, y), dirs[2]); map.put(Line2D.ptLineDistSq(1, 0, 1, 1, x, y), dirs[3]); }
private static Point2D detectLine( Point2D p1, Point2D p2, Point2D p, Line2D line, GeneralPath path) { if (p2 == null) { p2 = p; line.setLine(p1, p2); } // check for line else if (line.ptLineDistSq(p) < 1) { // its on the line // make it p2 p2.setLocation(p); } else { // its not on the current line p1.setLocation(p2); p2.setLocation(p); line.setLine(p1, p2); path.lineTo((float) p1.getX(), (float) p1.getY()); } return p2; } /**
if(line.ptLineDistSq(p) == 0) { // p is on the line p1,p2
private static Point2D detectLine(Point2D p1, Point2D p2, Point2D p, Line2D line, GeneralPath path) { if(p2 == null) { p2 = p; line.setLine(p1,p2); } // check for line else if(line.ptLineDistSq(p) < 1) { // its on the line // make it p2 p2.setLocation(p); } else { // its not on the current line p1.setLocation(p2); p2.setLocation(p); line.setLine(p1,p2); path.lineTo((float)p1.getX(), (float)p1.getY()); } return p2; } /**
if (line.ptLineDistSq(p) == 0) { // p is on the line p1,p2
/** * Computation of rotation from first to last point, with middle as approximate * middle point of the curve. * * @param line straight line from curve start to curve stop * @param middle middle point of curve * @return central rotation angle (in radians) from curve start to curve stop. */ public static double rotation (Line2D line, Point2D middle) { double dx = line.getX2() - line.getX1(); double dy = line.getY2() - line.getY1(); double halfChordLengthSq = ((dx * dx) + (dy * dy)) / 4; double sagittaSq = line.ptLineDistSq(middle); return 4 * Math.atan(Math.sqrt(sagittaSq / halfChordLengthSq)); }
double d = Line2D.ptLineDistSq(p0.x, p0.y, p1.x, p1.y, p.x, p.y); if (d < EPSILON)