Skip to content

Commit 837a527

Browse files
authored
Merge pull request #1 from pop4959/master
Add Ellipse API
2 parents 161fc1c + a9cfbd2 commit 837a527

File tree

1 file changed

+31
-6
lines changed
  • src/main/java/de/bluecolored/bluemap/api/marker

1 file changed

+31
-6
lines changed

src/main/java/de/bluecolored/bluemap/api/marker/Shape.java

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,26 +125,51 @@ public static Shape createRect(double x1, double y1, double x2, double y2) {
125125
}
126126

127127
/**
128-
* Creates a {@link Shape} representing a circle.
129-
* @param centerPos the center of the circle
130-
* @param radius the radius of the circle
131-
* @param points the amount of points used to create the circle (at least 3)
128+
* Creates a {@link Shape} representing an ellipse.
129+
* @param centerPos the center of the ellipse
130+
* @param radiusX the x radius of the ellipse
131+
* @param radiusY the y radius of the ellipse
132+
* @param points the amount of points used to create the ellipse (at least 3)
132133
* @return the created {@link Shape}
133134
*/
134-
public static Shape createCircle(Vector2d centerPos, double radius, int points) {
135+
public static Shape createEllipse(Vector2d centerPos, double radiusX, double radiusY, int points) {
135136
if (points < 3) throw new IllegalArgumentException("A shape has to have at least 3 points!");
136137

137138
Vector2d[] pointArray = new Vector2d[points];
138139
double segmentAngle = 2 * Math.PI / points;
139140
double angle = 0d;
140141
for (int i = 0; i < points; i++) {
141-
pointArray[i] = centerPos.add(Math.sin(angle) * radius, Math.cos(angle) * radius);
142+
pointArray[i] = centerPos.add(Math.sin(angle) * radiusX, Math.cos(angle) * radiusY);
142143
angle += segmentAngle;
143144
}
144145

145146
return new Shape(pointArray);
146147
}
147148

149+
/**
150+
* Creates a {@link Shape} representing an ellipse.
151+
* @param centerX the x-position of the center of the ellipse
152+
* @param centerY the y-position of the center of the ellipse
153+
* @param radiusX the x radius of the ellipse
154+
* @param radiusY the y radius of the ellipse
155+
* @param points the amount of points used to create the ellipse (at least 3)
156+
* @return the created {@link Shape}
157+
*/
158+
public static Shape createEllipse(double centerX, double centerY, double radiusX, double radiusY, int points) {
159+
return createEllipse(new Vector2d(centerX, centerY), radiusX, radiusY, points);
160+
}
161+
162+
/**
163+
* Creates a {@link Shape} representing a circle.
164+
* @param centerPos the center of the circle
165+
* @param radius the radius of the circle
166+
* @param points the amount of points used to create the circle (at least 3)
167+
* @return the created {@link Shape}
168+
*/
169+
public static Shape createCircle(Vector2d centerPos, double radius, int points) {
170+
return createEllipse(centerPos, radius, radius, points);
171+
}
172+
148173
/**
149174
* Creates a {@link Shape} representing a circle.
150175
* @param centerX the x-position of the center of the circle

0 commit comments

Comments
 (0)