コード例 #1
0
ファイル: Vector.java プロジェクト: MorS25/HonorsProjectSwarm
  public Point2D getClosestIntersectionToStart(Shape withThisShape) {
    // first, get the sides of the shape
    List<LineSegment> shapeSides = Utilities.getSides(withThisShape);

    // go through all the sides, and see if there are any intersections
    // there may be more than 1
    List<Point2D> shapeIntersectionPoints = new ArrayList<Point2D>();

    for (Line2D curSide : shapeSides) {
      if (curSide.intersectsLine(this)) {
        Point2D intersectionPoint = Utilities.getIntersectionPoint(this, curSide);
        shapeIntersectionPoints.add(intersectionPoint);
      }
    }

    if (shapeIntersectionPoints.size() <= 0) {
      return null;
    } else if (shapeIntersectionPoints.size() == 1) {
      return shapeIntersectionPoints.get(0);
    } else {
      // get the point closest to P1
      Point2D closestIntersectionPoint = null;
      double closestIntersectionPointDistSq = java.lang.Double.MAX_VALUE;
      for (Point2D curPoint : shapeIntersectionPoints) {
        double curDistSq = curPoint.distanceSq(this.getP1());
        if (curDistSq < closestIntersectionPointDistSq) {
          closestIntersectionPointDistSq = curDistSq;
          closestIntersectionPoint = curPoint;
        }
      }
      return closestIntersectionPoint;
    }
  }
コード例 #2
0
ファイル: Mouse.java プロジェクト: vscapesrc/vscapebot
  public void moveMouse(int x, int y, int randomX, int randomY) {
    int thisX = getLocation().x;
    int thisY = getLocation().y;
    if (thisX < 0 || thisY < 0)
      switch (nextInt(1, 5)) {
        case 1: // '\001'
          thisX = 1;
          thisY = nextInt(0, 500);
          setMousePos(thisX, thisY);
          break;

        case 2: // '\002'
          thisX = nextInt(0, 765);
          thisY = 501;
          setMousePos(thisX, thisY);
          break;

        case 3: // '\003'
          thisX = 766;
          thisY = nextInt(0, 500);
          setMousePos(thisX, thisY);
          break;

        case 4: // '\004'
          thisX = nextInt(0, 765);
          thisY = 1;
          setMousePos(thisX, thisY);
          break;
      }
    if (thisX == x && thisY == y) return;
    if (Point2D.distanceSq(thisX, thisY, x, y) < 10D) {
      SPLINE_LINES.clear();
      SPLINE_LINES.add(new Line(thisX, thisY, nextInt(x, x + randomX), nextInt(y, y + randomY)));
    } else {
      createSpline(
          new Point(thisX, thisY), new Point(nextInt(x, x + randomX), nextInt(y, y + randomY)));
    }
    splineMouse();
  }
コード例 #3
0
ファイル: Vector.java プロジェクト: MorS25/HonorsProjectSwarm
 public double getMagnitudeSquared() {
   return p1.distanceSq(p2);
 }
コード例 #4
0
  @Override
  public void createEdge(IDVINode node1, IDVINode node2, List<Point2D> edgePoints) {
    if (edgePoints == null || edgePoints.size() < 2) return;

    Map<Point2D, IDVINode> pointsOnBoundingBoxes = new HashMap<Point2D, IDVINode>();

    for (int i = 1; i < edgePoints.size(); i++) {
      Point2D point1 = edgePoints.get(i - 1);
      Point2D point2 = edgePoints.get(i);

      for (IDVINode node : dataGraph.getNodes()) {
        Rectangle2D box = node.getBoundingBox();
        int code1 = box.outcode(point1);
        int code2 = box.outcode(point2);

        boolean isPoint1OnBoundingBox = (pointsOnBoundingBoxes.get(point1) == node);
        boolean isPoint2OnBoundingBox = (pointsOnBoundingBoxes.get(point2) == node);

        if (((code1 & code2) != 0)
            || (code1 == 0 && !isPoint1OnBoundingBox)
            || (code2 == 0 && !isPoint2OnBoundingBox)
            || (isPoint1OnBoundingBox && isPoint2OnBoundingBox)) {
          continue;
        }

        Point2D intersection1 =
            (isPoint1OnBoundingBox)
                ? (point1)
                : (GeometryUtil.calcIntersectionPoint(point1, point2, box));
        Point2D intersection2 =
            (isPoint2OnBoundingBox)
                ? (point2)
                : (GeometryUtil.calcIntersectionPoint(point2, point1, box));

        if (intersection1 != null && intersection2 != null) {

          if (intersection1.getX() <= intersection2.getX() + 0.0000001
              && intersection1.getX() >= intersection2.getX() - 0.0000001
              && intersection1.getY() <= intersection2.getY() + 0.0000001
              && intersection1.getY() >= intersection2.getY() - 0.0000001) {
            continue;
          }

          Point2D[] corners = new Point2D[4];
          // corners[0] = new Point2D.Double(box.getMinX() - 0.001,
          // box.getMinY() - 0.001);
          // corners[1] = new Point2D.Double(box.getMaxX() + 0.001,
          // box.getMinY() - 0.001);
          // corners[2] = new Point2D.Double(box.getMaxX() + 0.001,
          // box.getMaxY() + 0.001);
          // corners[3] = new Point2D.Double(box.getMinX() - 0.001,
          // box.getMaxY() + 0.001);
          corners[0] = new Point2D.Double(box.getMinX(), box.getMinY());
          corners[1] = new Point2D.Double(box.getMaxX(), box.getMinY());
          corners[2] = new Point2D.Double(box.getMaxX(), box.getMaxY());
          corners[3] = new Point2D.Double(box.getMinX(), box.getMaxY());

          double minDistance = Double.MAX_VALUE;
          Point2D bendPoint = null;

          for (int j = 0; j < 4; j++) {
            if ((corners[j].getX() == point1.getX()
                    && corners[j].getY() == point1.getY()
                    && isPoint1OnBoundingBox)
                || (corners[j].getX() == point2.getX() && corners[j].getY() == point2.getY())
                    && isPoint2OnBoundingBox) {
              continue;
            }
            double currentSummedDistance =
                intersection1.distanceSq(corners[j]) + intersection2.distanceSq(corners[j]);
            if (currentSummedDistance < minDistance) {
              minDistance = currentSummedDistance;
              bendPoint = corners[j];
            }
          }
          if (bendPoint == null) {
            System.out.println("null");
          }

          boolean isPointAlreadyAdded = false;

          for (Point2D point : edgePoints) {
            if (point.getX() == bendPoint.getX() && point.getY() == bendPoint.getY()) {
              isPointAlreadyAdded = true;
              break;
            }
          }

          if (isPointAlreadyAdded) {
            continue;
          }

          edgePoints.add(i, bendPoint);
          pointsOnBoundingBoxes.put(bendPoint, node);
          i--;

          // gl.glPointSize(5);
          // gl.glColor3f(0, 0, 1);
          // gl.glBegin(GL2.GL_POINTS);
          // gl.glVertex2d(intersection1.getX(),
          // intersection1.getY());
          // gl.glVertex2d(intersection2.getX(),
          // intersection2.getY());
          // gl.glEnd();
          //
          // gl.glLineWidth(1);
          // gl.glColor3f(0, 0, 1);
          // gl.glBegin(GL.GL_LINE_LOOP);
          // gl.glVertex2d(box.getMinX(), box.getMinY());
          // gl.glVertex2d(box.getMaxX(), box.getMinY());
          // gl.glVertex2d(box.getMaxX(), box.getMaxY());
          // gl.glVertex2d(box.getMinX(), box.getMaxY());
          // gl.glEnd();

          break;
        }
      }
    }

    for (int step = edgePoints.size() - 2; step >= 2; step--) {

      for (int i = 0; i + step < edgePoints.size(); i++) {
        Point2D point1 = edgePoints.get(i);
        Point2D point2 = edgePoints.get(i + step);

        boolean hasIntersection = false;

        for (IDVINode node : dataGraph.getNodes()) {
          Rectangle2D box = node.getBoundingBox();
          int code1 = box.outcode(point1);
          int code2 = box.outcode(point2);

          boolean isPoint1OnBoundingBox = (pointsOnBoundingBoxes.get(point1) == node);
          boolean isPoint2OnBoundingBox = (pointsOnBoundingBoxes.get(point2) == node);

          if ((code1 & code2) != 0) {
            continue;
          }

          if ((code1 == 0
                  && !isPoint1OnBoundingBox
                  && edgePoints.indexOf(point1) != 0
                  && edgePoints.indexOf(point1) != edgePoints.size() - 1)
              || (code2 == 0
                  && !isPoint2OnBoundingBox
                  && edgePoints.indexOf(point2) != 0
                  && edgePoints.indexOf(point2) != edgePoints.size() - 1)
              || (isPoint1OnBoundingBox && isPoint2OnBoundingBox)) {
            hasIntersection = true;
            break;
          }

          Point2D intersection1 =
              (isPoint1OnBoundingBox)
                  ? (point1)
                  : (GeometryUtil.calcIntersectionPoint(point1, point2, box));
          Point2D intersection2 =
              (isPoint2OnBoundingBox)
                  ? (point2)
                  : (GeometryUtil.calcIntersectionPoint(point2, point1, box));

          if (intersection1 == null || intersection2 == null) {
            continue;
          }

          if (intersection1.distance(intersection2) < 0.000001
              && (isPoint1OnBoundingBox || isPoint2OnBoundingBox)) {
            continue;
          }

          hasIntersection = true;
          break;
        }

        if (!hasIntersection) {
          for (int j = i + 1; j < i + step; j++) {
            edgePoints.remove(i + 1);
          }
          step = edgePoints.size() - 2;
          break;
        }
      }
    }

    if (edgePoints.size() > 2) {
      for (int i = 0; i < edgePoints.size() - 1; i++) {
        Point2D point1 = edgePoints.get(i);
        Point2D point2 = edgePoints.get(i + 1);

        if (point1.distance(point2) < pixelGLConverter.getGLWidthForPixelWidth(40)) {
          if (i != edgePoints.size() - 2) {
            edgePoints.remove(i + 1);
            i--;
          } else {
            edgePoints.remove(i);
          }
        }
      }
    }
  }
コード例 #5
0
ファイル: VisualState.java プロジェクト: tuura/workcraft
 @Override
 public boolean hitTestInLocalSpace(Point2D pointInLocalSpace) {
   return pointInLocalSpace.distanceSq(0, 0) < size * size / 4;
 }