question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ellipse contains method is incorrect

See original GitHub issue

Issue 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:closed
  • Created 3 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
MobiDevelopcommented, Jan 5, 2021

Reading the source of the Ellipse class suggests the (x,y) is considered to be the center point of the ellipse.

0reactions
obigucommented, Jan 12, 2021

Looks like Implementation is correct, the issue can be closed. If you believe documentation can be improved, please feel free to open a PR.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found