mirror of
https://github.com/BlueMap-Minecraft/BlueMapAPI.git
synced 2024-11-14 22:35:30 +01:00
Add ellipse API
This commit is contained in:
parent
161fc1c968
commit
66edc5654b
@ -123,7 +123,42 @@ public static Shape createRect(Vector2d pos1, Vector2d pos2) {
|
||||
public static Shape createRect(double x1, double y1, double x2, double y2) {
|
||||
return createRect(new Vector2d(x1, y1), new Vector2d(x2, y2));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a {@link Shape} representing an ellipse.
|
||||
* @param centerPos the center of the ellipse
|
||||
* @param radiusX the x radius of the ellipse
|
||||
* @param radiusY the y radius of the ellipse
|
||||
* @param points the amount of points used to create the ellipse (at least 3)
|
||||
* @return the created {@link Shape}
|
||||
*/
|
||||
public static Shape createEllipse(Vector2d centerPos, double radiusX, double radiusY, int points) {
|
||||
if (points < 3) throw new IllegalArgumentException("A shape has to have at least 3 points!");
|
||||
|
||||
Vector2d[] pointArray = new Vector2d[points];
|
||||
double segmentAngle = 2 * Math.PI / points;
|
||||
double angle = 0d;
|
||||
for (int i = 0; i < points; i++) {
|
||||
pointArray[i] = centerPos.add(Math.sin(angle) * radiusX, Math.cos(angle) * radiusY);
|
||||
angle += segmentAngle;
|
||||
}
|
||||
|
||||
return new Shape(pointArray);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Shape} representing an ellipse.
|
||||
* @param centerX the x-position of the center of the ellipse
|
||||
* @param centerY the y-position of the center of the ellipse
|
||||
* @param radiusX the x radius of the ellipse
|
||||
* @param radiusY the y radius of the ellipse
|
||||
* @param points the amount of points used to create the ellipse (at least 3)
|
||||
* @return the created {@link Shape}
|
||||
*/
|
||||
public static Shape createEllipse(double centerX, double centerY, double radiusX, double radiusY, int points) {
|
||||
return createEllipse(new Vector2d(centerX, centerY), radiusX, radiusY, points);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a {@link Shape} representing a circle.
|
||||
* @param centerPos the center of the circle
|
||||
@ -132,17 +167,7 @@ public static Shape createRect(double x1, double y1, double x2, double y2) {
|
||||
* @return the created {@link Shape}
|
||||
*/
|
||||
public static Shape createCircle(Vector2d centerPos, double radius, int points) {
|
||||
if (points < 3) throw new IllegalArgumentException("A shape has to have at least 3 points!");
|
||||
|
||||
Vector2d[] pointArray = new Vector2d[points];
|
||||
double segmentAngle = 2 * Math.PI / points;
|
||||
double angle = 0d;
|
||||
for (int i = 0; i < points; i++) {
|
||||
pointArray[i] = centerPos.add(Math.sin(angle) * radius, Math.cos(angle) * radius);
|
||||
angle += segmentAngle;
|
||||
}
|
||||
|
||||
return new Shape(pointArray);
|
||||
return createEllipse(centerPos, radius, radius, points);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user