Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Best practice regarding different (0,0) origins #3

Open
Robert-M-Muench opened this issue Jan 5, 2021 · 1 comment
Open

Best practice regarding different (0,0) origins #3

Robert-M-Muench opened this issue Jan 5, 2021 · 1 comment

Comments

@Robert-M-Muench
Copy link

I have a graphics lib, where the origin (0,0) is at the top/left, and rects use a top/left and width/height notation.

rbang origin (0,0) is bottom/left and uses a bottom/left, top/right notation.

So, when inserting rects from the graphics lib, I use code like this to update the same rectangle:

  • r = rectangle
  • xll = x lower-left
  • yll = y lower-left
  • xur = x upper-right
  • your = y upper-right
rbang.Replace(
	[2]float64{
		float64(r.xll),
		float64(r.yll)},
	[2]float64{
		float64(r.xur),
		float64(r.yur)},
	r,
	[2]float64{
		float64(r.GetLeft()),
		float64(r.GetTop())},
	[2]float64{
		float64(r.GetLeft() + r.GetWidth()),
		float64(r.GetTop() + r.GetHeight())}, r)

The problem is, that I have a very simple three rects layout (root, two childs with 50% width and 100% height of root), where a search with a point inside c2, returns the root node and c1... and not the root node and c2.

@tidwall
Copy link
Owner

tidwall commented Jan 6, 2021

This library uses a standard R-tree that accepts any rectangles with min and max values. It has no concept of direction or coordinate systems. It shouldn't matter if you use screen coordinates (min is top-left and max is bottom-right) or cartesian coordinates (min is bottom-left and max is top-right). Just as long as you always use the the same coordinate system for all of your operations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants