public static boolean isPointNearSegment(Point from, Point to, Point testPos, int nearTolerance) {
   Rectangle r =
       new Rectangle(
           testPos.x - nearTolerance / 2,
           testPos.y - nearTolerance / 2,
           nearTolerance,
           nearTolerance);
   return r.intersectsLine(from.x, from.y, to.x, to.y);
 }
Example #2
0
 public static boolean isPointNearSegment(Point from, Point to, Point testPos, int nearTolerance) {
   Rectangle r =
       new Rectangle(
           testPos.getX() - nearTolerance,
           testPos.getY() - nearTolerance,
           2 * nearTolerance,
           2 * nearTolerance);
   return r.intersectsLine(from.getX(), from.getY(), to.getX(), to.getY());
 }
Example #3
0
 public boolean needDrawing(Rectangle rect) {
   for (int i = 0; i < data_.getModel().npoints - 1; ++i) {
     if (rect.intersectsLine(
         data_.getModel().xpoints[i],
         data_.getModel().ypoints[i],
         data_.getModel().xpoints[i + 1],
         data_.getModel().ypoints[i + 1])) return true;
   }
   return false;
 }
Example #4
0
  public int getIndexOfNewPoint(int x, int y, int tol) {
    Rectangle rect = new Rectangle(x - tol / 2, y - tol / 2, tol, tol);
    List<mxPoint> pts = getAbsolutePoints();

    int length = pts.size();
    mxPoint start, end;
    start = pts.get(0);
    for (int i = 1; i < length; i++) {
      end = pts.get(i);
      if (rect.intersectsLine(start.getX(), start.getY(), end.getX(), end.getY())) return i;
      start = end;
    }
    return -1;
  }