public void setCenterX(float centerX) { if ((points == null) || (center == null)) { checkPoints(); } float xDiff = centerX - getCenterX(); setX(x + xDiff); }
public void setCenterY(float centerY) { if ((points == null) || (center == null)) { checkPoints(); } float yDiff = centerY - getCenterY(); setY(y + yDiff); }
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; }
public float[] getPoint(int index) { checkPoints(); float result[] = new float[2]; result[0] = points[index * 2]; result[1] = points[index * 2 + 1]; return result; }
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; }
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; } }
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; } }
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; }
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; }
public Triangle getTriangles() { checkPoints(); calculateTriangles(); return triangle; }
public float getBoundingCircleRadius() { checkPoints(); return boundingCircleRadius; }
public float getMinY() { checkPoints(); return minY; }
public float getMinX() { checkPoints(); return minX; }
public float getMaxY() { checkPoints(); return maxY; }
public float getMaxX() { checkPoints(); return maxX; }
public float getCenterY() { checkPoints(); return center[1]; }
public void increaseTriangulation() { checkPoints(); calculateTriangles(); triangle = new TriangleOver(triangle); }
public float[] getCenter() { checkPoints(); return center; }
public void preCache() { checkPoints(); getTriangles(); }
public float[] getPoints() { checkPoints(); return points; }
public int getPointCount() { checkPoints(); return points.length / 2; }
public float getCenterX() { checkPoints(); return center[0]; }