OSDN Git Service

added Ellipse
authorMario Zechner <contact@badlogicgames.com>
Mon, 18 Feb 2013 19:54:33 +0000 (20:54 +0100)
committerMario Zechner <contact@badlogicgames.com>
Mon, 18 Feb 2013 19:54:33 +0000 (20:54 +0100)
gdx/src/com/badlogic/gdx/math/Ellipse.java [new file with mode: 0755]

diff --git a/gdx/src/com/badlogic/gdx/math/Ellipse.java b/gdx/src/com/badlogic/gdx/math/Ellipse.java
new file mode 100755 (executable)
index 0000000..22b169b
--- /dev/null
@@ -0,0 +1,57 @@
+\r
+package com.badlogic.gdx.math;\r
+\r
+import java.io.Serializable;\r
+\r
+import com.badlogic.gdx.math.Vector2;\r
+\r
+/** A convenient 2D ellipse class, based on the circle class\r
+ * @author tonyp7 */\r
+public class Ellipse implements Serializable {\r
+\r
+       public float x, y;\r
+       public float width, height;\r
+       private float halfWidth, halfHeight;\r
+\r
+       private static final long serialVersionUID = 7381533206532032099L;\r
+\r
+       /** Construct a new ellipse with all values set to zero */\r
+       public Ellipse () {\r
+\r
+       }\r
+\r
+       public Ellipse (float x, float y, float width, float height) {\r
+               this.x = x;\r
+               this.y = y;\r
+               this.width = width;\r
+               this.height = height;\r
+       }\r
+\r
+       public Ellipse (Vector2 position, float width, float height) {\r
+               this.x = position.x;\r
+               this.y = position.y;\r
+               this.width = width;\r
+               this.height = height;\r
+       }\r
+\r
+       public boolean contains (float x, float y) {\r
+               x = x - this.x;\r
+               y = y - this.y;\r
+               halfWidth = width * 0.5f;\r
+               halfHeight = height * 0.5f;\r
+\r
+               return (x * x) / (halfWidth * halfWidth) + (y * y) / (halfHeight * halfHeight) <= 1.0f;\r
+       }\r
+\r
+       public boolean contains (Vector2 point) {\r
+               return contains(point.x, point.y);\r
+       }\r
+\r
+       public void set (float x, float y, float width, float height) {\r
+               this.x = x;\r
+               this.y = y;\r
+               this.width = width;\r
+               this.height = height;\r
+       }\r
+\r
+}\r