2 package com.badlogic.gdx.math;
\r
4 import java.io.Serializable;
\r
6 import com.badlogic.gdx.math.Vector2;
\r
8 /** A convenient 2D ellipse class, based on the circle class
\r
10 public class Ellipse implements Serializable {
\r
13 public float width, height;
\r
15 private static final long serialVersionUID = 7381533206532032099L;
\r
17 /** Construct a new ellipse with all values set to zero */
\r
22 public Ellipse (Ellipse ellipse) {
\r
25 this.width = ellipse.width;
\r
26 this.height = ellipse.height;
\r
29 public Ellipse (float x, float y, float width, float height) {
\r
33 this.height = height;
\r
36 public Ellipse (Vector2 position, float width, float height) {
\r
37 this.x = position.x;
\r
38 this.y = position.y;
\r
40 this.height = height;
\r
43 public boolean contains (float x, float y) {
\r
47 return (x * x) / (width * 0.5f * width * 0.5f) + (y * y) / (height * 0.5f * height * 0.5f) <= 1.0f;
\r
50 public boolean contains (Vector2 point) {
\r
51 return contains(point.x, point.y);
\r
54 public void set (float x, float y, float width, float height) {
\r
58 this.height = height;
\r
61 public void set (Ellipse ellipse) {
\r
64 width = ellipse.width;
\r
65 height = ellipse.height;
\r
68 /** Sets the x and y-coordinates of ellipse center from vector
\r
69 * @param position The position vector
\r
70 * @return this ellipse for chaining */
\r
71 public Ellipse setPosition (Vector2 position) {
\r
72 this.x = position.x;
\r
73 this.y = position.y;
\r
78 /** Sets the x and y-coordinates of ellipse center
\r
79 * @param x The x-coordinate
\r
80 * @param y The y-coordinate
\r
81 * @return this ellipse for chaining */
\r
82 public Ellipse setPosition (float x, float y) {
\r
89 /** Sets the width and height of this ellipse
\r
90 * @param width The width
\r
91 * @param height The height
\r
92 * @return this ellipse for chaining */
\r
93 public Ellipse setSize (float width, float height) {
\r
95 this.height = height;
\r