Exemplo n.º 1
0
  public void setCenterX(float centerX) {
    if ((points == null) || (center == null)) {
      checkPoints();
    }

    float xDiff = centerX - getCenterX();
    setX(x + xDiff);
  }
Exemplo n.º 2
0
  public void setCenterY(float centerY) {
    if ((points == null) || (center == null)) {
      checkPoints();
    }

    float yDiff = centerY - getCenterY();
    setY(y + yDiff);
  }
Exemplo n.º 3
0
  public boolean intersects(Shape shape) {
    if (shape == null) {
      return false;
    }

    checkPoints();

    boolean result = false;
    float points[] = getPoints();
    float thatPoints[] = shape.getPoints();
    int length = points.length;
    int thatLength = thatPoints.length;
    double unknownA;
    double unknownB;

    if (!closed()) {
      length -= 2;
    }
    if (!shape.closed()) {
      thatLength -= 2;
    }

    for (int i = 0; i < length; i += 2) {
      int iNext = i + 2;
      if (iNext >= points.length) {
        iNext = 0;
      }

      for (int j = 0; j < thatLength; j += 2) {
        int jNext = j + 2;
        if (jNext >= thatPoints.length) {
          jNext = 0;
        }

        unknownA =
            (((points[iNext] - points[i]) * (double) (thatPoints[j + 1] - points[i + 1]))
                    - ((points[iNext + 1] - points[i + 1]) * (thatPoints[j] - points[i])))
                / (((points[iNext + 1] - points[i + 1]) * (thatPoints[jNext] - thatPoints[j]))
                    - ((points[iNext] - points[i]) * (thatPoints[jNext + 1] - thatPoints[j + 1])));
        unknownB =
            (((thatPoints[jNext] - thatPoints[j]) * (double) (thatPoints[j + 1] - points[i + 1]))
                    - ((thatPoints[jNext + 1] - thatPoints[j + 1]) * (thatPoints[j] - points[i])))
                / (((points[iNext + 1] - points[i + 1]) * (thatPoints[jNext] - thatPoints[j]))
                    - ((points[iNext] - points[i]) * (thatPoints[jNext + 1] - thatPoints[j + 1])));

        if (unknownA >= 0 && unknownA <= 1 && unknownB >= 0 && unknownB <= 1) {
          result = true;
          break;
        }
      }
      if (result) {
        break;
      }
    }

    return result;
  }
Exemplo n.º 4
0
  public float[] getPoint(int index) {
    checkPoints();

    float result[] = new float[2];

    result[0] = points[index * 2];
    result[1] = points[index * 2 + 1];

    return result;
  }
Exemplo n.º 5
0
  public boolean hasVertex(float x, float y) {
    if (points.length == 0) {
      return false;
    }

    checkPoints();

    for (int i = 0; i < points.length; i += 2) {
      if ((points[i] == x) && (points[i + 1] == y)) {
        return true;
      }
    }

    return false;
  }
Exemplo n.º 6
0
 public void setX(float x) {
   if (x != this.x || x == 0) {
     float dx = x - this.x;
     this.x = x;
     if ((points == null) || (center == null)) {
       checkPoints();
     }
     for (int i = 0; i < points.length / 2; i++) {
       points[i * 2] += dx;
     }
     center[0] += dx;
     x += dx;
     maxX += dx;
     minX += dx;
     trianglesDirty = true;
   }
 }
Exemplo n.º 7
0
 public void setY(float y) {
   if (y != this.y || y == 0) {
     float dy = y - this.y;
     this.y = y;
     if ((points == null) || (center == null)) {
       checkPoints();
     }
     for (int i = 0; i < points.length / 2; i++) {
       points[(i * 2) + 1] += dy;
     }
     center[1] += dy;
     y += dy;
     maxY += dy;
     minY += dy;
     trianglesDirty = true;
   }
 }
Exemplo n.º 8
0
  public boolean contains(float x, float y) {

    checkPoints();
    if (points.length == 0) {
      return false;
    }

    boolean result = false;
    float xnew, ynew;
    float xold, yold;
    float x1, y1;
    float x2, y2;
    int npoints = points.length;

    xold = points[npoints - 2];
    yold = points[npoints - 1];
    for (int i = 0; i < npoints; i += 2) {
      xnew = points[i];
      ynew = points[i + 1];
      if (xnew > xold) {
        x1 = xold;
        x2 = xnew;
        y1 = yold;
        y2 = ynew;
      } else {
        x1 = xnew;
        x2 = xold;
        y1 = ynew;
        y2 = yold;
      }
      if ((xnew < x) == (x <= xold)
          && ((double) y - (double) y1) * (x2 - x1) < ((double) y2 - (double) y1) * (x - x1)) {
        result = !result;
      }
      xold = xnew;
      yold = ynew;
    }

    return result;
  }
Exemplo n.º 9
0
  public boolean includes(float x, float y) {
    if (points.length == 0) {
      return false;
    }

    checkPoints();

    Line testLine = new Line(0, 0, 0, 0);
    Vector2f pt = new Vector2f(x, y);

    for (int i = 0; i < points.length; i += 2) {
      int n = i + 2;
      if (n >= points.length) {
        n = 0;
      }
      testLine.set(points[i], points[i + 1], points[n], points[n + 1]);

      if (testLine.on(pt)) {
        return true;
      }
    }

    return false;
  }
Exemplo n.º 10
0
 public Triangle getTriangles() {
   checkPoints();
   calculateTriangles();
   return triangle;
 }
Exemplo n.º 11
0
 public float getBoundingCircleRadius() {
   checkPoints();
   return boundingCircleRadius;
 }
Exemplo n.º 12
0
 public float getMinY() {
   checkPoints();
   return minY;
 }
Exemplo n.º 13
0
 public float getMinX() {
   checkPoints();
   return minX;
 }
Exemplo n.º 14
0
 public float getMaxY() {
   checkPoints();
   return maxY;
 }
Exemplo n.º 15
0
 public float getMaxX() {
   checkPoints();
   return maxX;
 }
Exemplo n.º 16
0
  public float getCenterY() {
    checkPoints();

    return center[1];
  }
Exemplo n.º 17
0
  public void increaseTriangulation() {
    checkPoints();
    calculateTriangles();

    triangle = new TriangleOver(triangle);
  }
Exemplo n.º 18
0
 public float[] getCenter() {
   checkPoints();
   return center;
 }
Exemplo n.º 19
0
 public void preCache() {
   checkPoints();
   getTriangles();
 }
Exemplo n.º 20
0
 public float[] getPoints() {
   checkPoints();
   return points;
 }
Exemplo n.º 21
0
 public int getPointCount() {
   checkPoints();
   return points.length / 2;
 }
Exemplo n.º 22
0
 public float getCenterX() {
   checkPoints();
   return center[0];
 }