Few bug fixes for Ellipse methods.

This commit is contained in:
Antriel 2018-01-17 11:43:34 +01:00
parent b17744df61
commit ca24bce499
3 changed files with 9 additions and 9 deletions

View file

@ -10,8 +10,8 @@
*/
var Circumference = function (ellipse)
{
var rx = ellipse.width;
var ry = ellipse.height;
var rx = ellipse.width / 2;
var ry = ellipse.height / 2;
var h = Math.pow((rx - ry), 2) / Math.pow((rx + ry), 2);
return (Math.PI * (rx + ry)) * (1 + ((3 * h) / (10 + Math.sqrt(4 - (3 * h)))));

View file

@ -16,14 +16,14 @@ var Contains = function (ellipse, x, y)
{
return false;
}
// Normalize the coords to an ellipse with center 0,0 and a radius of 0.5
var normx = ((x - ellipse.x) / ellipse.width) - 0.5;
var normy = ((y - ellipse.y) / ellipse.height) - 0.5;
var normx = ((x - ellipse.x) / ellipse.width);
var normy = ((y - ellipse.y) / ellipse.height);
normx *= normx;
normy *= normy;
return (normx + normy < 0.25);
};

View file

@ -15,8 +15,8 @@ var GetBounds = function (ellipse, out)
{
if (out === undefined) { out = new Rectangle(); }
out.x = ellipse.x - ellipse.width;
out.y = ellipse.y - ellipse.height;
out.x = ellipse.left;
out.y = ellipse.top;
out.width = ellipse.width;
out.height = ellipse.height;