Ellipse contains method is incorrect
See original GitHub issueIssue details
Ellipse contains method is incorrect.
I was attempting to use the Ellipse to check for mouse clicks on Elliptical buttons and realized the contains method is incorrect.
x = x - this.x;
y = y - this.y;
return (x * x) / (width * 0.5f * width * 0.5f) + (y * y) / (height * 0.5f * height * 0.5f) <= 1.0f;
I believe the issue is that the x and y of the ellipse are the bottom left coordinate you would get if you drew a rectangle exactly encompassing the ellipse when the formula here is for an x and y at the center of the ellipse
Reproduction steps/code
Ellipse ellipse = new Ellipse(0, 0, 50, 50);
Assert.assertFalse(ellipse.contains(0, 0)); // Should not be within the ellipse, but the formula currently marks it as such.
Assert.assertTrue(ellipse.contains(25, 25)); // Should be contained as this is the center of the ellipse, but the formula currently marks it as outside.
Version of LibGDX and/or relevant dependencies
ALL (according to git) But I’m currently using 1.9.11
Stacktrace
N/A
Please select the affected platforms
- [x ] Android
- [ x] iOS
- [ x] HTML/GWT
- [ x] Windows
- [ x] Linux
- [ x] MacOS
Issue Analytics
- State:
- Created 3 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Determining if a point lies within an ellipse, including the edge
If you want to write your own method, it's as simple as taking the formula for an ellipse, plugging in the X and...
Read more >geometry - What is wrong with my equation for an ellipse ...
I'm drawing an ellipse on the screen by generating lots of random y-values for every x-value (this creates bristles of a paintbrush I...
Read more >Relationships between Ellipses and Circles
In some ellipses, the major axis is much longer than the minor axis. ... It has equation ... If false, draw a counterexample....
Read more >Ellipsis Marks - The Blue Book of Grammar and Punctuation
Ellipsis marks (three dots) are used to show the omission of a word, phrase, line, or paragraph(s), from a quoted passage. The plural...
Read more >C++ – OpenCV's fitEllipse() sometimes returns completely wrong ...
The function fitEllipse returns a RotatedRect that contains all the parameters of the ellipse. An ellipse is defined by 5 parameters: xc :...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Reading the source of the Ellipse class suggests the (x,y) is considered to be the center point of the ellipse.
Looks like Implementation is correct, the issue can be closed. If you believe documentation can be improved, please feel free to open a PR.