private void close() { if (lastCurrent.equals(end) == false) { lines.add(new Line2D.Double(lastCurrent, end)); } } }
static double getAngle(Point2D p1, Point2D p2) { if (p1.equals(p2)) { throw new IllegalArgumentException(); } return Math.atan2(p2.getY() - p1.getY(), p2.getX() - p1.getX()); }
public LineSegmentDouble(Point2D p1, Point2D p2) { this.p1 = p1; this.p2 = p2; if (p1.equals(p2)) { throw new IllegalArgumentException(); } assert p1 != null && p2 != null; assert getLength() > 0; assert this.getDistance(this) == 0; }
public void addLine(Line2D.Double newLine) { // Log.println("# Polyline2::addLine " + // GeomUtils.toString(newLine)); if (lastCurrent.equals(newLine.getP1()) == false) { lines.add(new Line2D.Double(lastCurrent, newLine.getP1())); } lines.add(newLine); lastCurrent = newLine.getP2(); }
private Line2D.Double change(Line2D.Double line, Point2D p1, Point2D p2) { if (line.getP1().equals(p1) == false && line.getP2().equals(p2) == false) { return line; } final double dx = line.x2 - line.x1; final double dy = line.y2 - line.y1; if (line.getP1().equals(p1)) { p1 = new Point2D.Double(line.x1 + dx / 10, line.y1 + dy / 10); } else { p1 = line.getP1(); } if (line.getP2().equals(p2)) { p2 = new Point2D.Double(line.x2 - dx / 10, line.y2 - dy / 10); } else { p2 = line.getP2(); } return new Line2D.Double(p1, p2); }
static final double getAngle(Line2D.Double line) { if (line.getP1().equals(line.getP2())) { throw new IllegalArgumentException(); } return Math.atan2(line.getP2().getY() - line.getP1().getY(), line.getP2().getX() - line.getP1().getX()); }
public void draw(Graphics2D g2d) { close(); if (debug) { g2d.setColor(Color.GREEN); drawDebug(g2d); } g2d.setColor(Color.BLUE); final List<Point2D.Double> centers = new ArrayList<Point2D.Double>(); for (Line2D.Double l : lines) { centers.add(GeomUtils.getCenter(l)); } g2d.draw(new Line2D.Double(lines.get(0).getP1(), centers.get(0))); g2d.draw(new Line2D.Double(centers.get(centers.size() - 1), end)); for (int i = 0; i < lines.size() - 1; i++) { final Point2D c1 = centers.get(i); final Point2D c2 = centers.get(i + 1); final Point2D ctrl = lines.get(i).getP2(); assert ctrl.equals(lines.get(i + 1).getP1()); final QuadCurve2D.Double quad = new QuadCurve2D.Double(c1.getX(), c1.getY(), ctrl.getX(), ctrl.getY(), c2 .getX(), c2.getY()); g2d.draw(quad); } if (debug) { for (Point2D.Double c : centers) { GeomUtils.fillPoint2D(g2d, c); } } }
final double getMindist(Point2D.Double pt) { double result = Double.MAX_VALUE; for (Point2D p : points.keySet()) { if (pt.equals(p)) { continue; } final double v = p.distance(pt); if (v < 1E-4) { throw new IllegalStateException(); } result = Math.min(result, v); } for (Line2D line : lines) { if (line.getP1().equals(pt) || line.getP2().equals(pt)) { continue; } final double v = line.ptSegDist(pt); if (result < 1E-4) { throw new IllegalStateException("pt=" + pt + " line=" + GeomUtils.toString(line)); } result = Math.min(result, v); } if (result == 0) { throw new IllegalStateException(); } // Log.println("getMindist=" + result); return result; } }
public List<Line2D.Double> inflate(Collection<Line2D.Double> segments) { final Collection<Line2D.Double> cutSegments = cutSegments(segments); Line2D.Double last = null; final List<Line2D.Double> inflated = inflateSegmentCollection(cutSegments); final List<Line2D.Double> result = new ArrayList<Line2D.Double>(); for (Line2D.Double seg : inflated) { if (last != null && last.getP2().equals(seg.getP1()) == false) { result.add(new Line2D.Double(last.getP2(), seg.getP1())); } result.add(seg); last = seg; } return result; }
@SuppressWarnings("WeakerAccess") protected Paint createLinearGradientPaint(GradientPaint fill, Graphics2D graphics) { // TODO: we need to find the two points for gradient - the problem is, which point at the outline // do you take? My solution would be to apply the gradient rotation to the shape in reverse // and then scan the shape for the largest possible horizontal distance double angle = fill.getGradientAngle(); if (!fill.isRotatedWithShape()) { angle -= shape.getRotation(); } Rectangle2D anchor = DrawShape.getAnchor(graphics, shape); AffineTransform at = AffineTransform.getRotateInstance(Math.toRadians(angle), anchor.getCenterX(), anchor.getCenterY()); double diagonal = Math.sqrt(Math.pow(anchor.getWidth(),2) + Math.pow(anchor.getHeight(),2)); final Point2D p1 = at.transform(new Point2D.Double(anchor.getCenterX() - diagonal / 2, anchor.getCenterY()), null); final Point2D p2 = at.transform(new Point2D.Double(anchor.getMaxX(), anchor.getCenterY()), null); // snapToAnchor(p1, anchor); // snapToAnchor(p2, anchor); // gradient paint on the same point throws an exception ... and doesn't make sense return (p1.equals(p2)) ? null : safeFractions((f,c)->new LinearGradientPaint(p1,p2,f,c), fill); }
static public double getStartingAngle(final CubicCurve2D.Double left) { if (left.getP1().equals(left.getCtrlP1())) { return getAngle(left.getP1(), left.getP2()); } return getAngle(left.getP1(), left.getCtrlP1()); }
static public double getEndingAngle(final CubicCurve2D.Double left) { if (left.getCtrlP2().equals(left.getP2())) { return getAngle(left.getP1(), left.getP2()); } return getAngle(left.getCtrlP2(), left.getP2()); }
@Override public boolean equals(Object other) { if (this == other) return true; if (!(other instanceof PolygonVertex)) return false; return this.point.equals(((PolygonVertex) other).point); }
final CubicCurve2D.Double part2 = new CubicCurve2D.Double(); current.subdivide(part1, part2); assert part1.getP2().equals(part2.getP1()); if (clusterPosition.contains(part1.getP2())) { current = part2; final CubicCurve2D.Double part2 = new CubicCurve2D.Double(); current.subdivide(part1, part2); assert part1.getP2().equals(part2.getP1()); if (clusterPosition.contains(part1.getP2())) { current = part1;
private static boolean isTooSmallToRender(Point2D p0, Point2D p1, double minLen) { if (p0.equals(p1)) { return true; } double dx = p1.getX() - p0.getX(); double dy = p1.getY() - p0.getY(); double len = Math.sqrt(dx * dx + dy * dy); return len < minLen; } }
private void repaintOnMouseMoved(MouseEvent event) { double zoom = this.editorPart.getZoomFactor(); Point2D mousePoint = new Point2D.Double(event.getX() / zoom, event.getY() / zoom); Point2D snappedMousePoint = grid.snap(mousePoint); if (!snappedMousePoint.equals(lastMousePoint)) { this.editorPart.getSwingComponent().invalidate(); this.editorPart.getSwingComponent().repaint(); } this.lastMousePoint = snappedMousePoint; }
static public double getEndingAngle(final CubicCurve2D.Double left) { if (left.getCtrlP2().equals(left.getP2())) { return getAngle(left.getP1(), left.getP2()); } return getAngle(left.getCtrlP2(), left.getP2()); }