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

is intersect --> rectIntersect necessary? #3

Open
nabsul opened this issue Feb 25, 2017 · 0 comments
Open

is intersect --> rectIntersect necessary? #3

nabsul opened this issue Feb 25, 2017 · 0 comments

Comments

@nabsul
Copy link

nabsul commented Feb 25, 2017

Is it my imagination, or is the use of this function redundant? Instead of doing all combinations of two dimensions, why not just do all three dims at the same time? Or one dimension at a time?

func rectIntersect(i1, i2 *Item, x, y Axis) bool {
	d1 := i1.GetDimension()
	d2 := i2.GetDimension()

	cx1 := i1.Position[x] + d1[x]/2
	cy1 := i1.Position[y] + d1[y]/2
	cx2 := i2.Position[x] + d2[x]/2
	cy2 := i2.Position[y] + d2[y]/2

	ix := math.Max(cx1, cx2) - math.Min(cx1, cx2)
	iy := math.Max(cy1, cy2) - math.Min(cy1, cy2)

	return ix < (d1[x]+d2[x])/2 && iy < (d1[y]+d2[y])/2
}
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

1 participant