Go func (Rect) Intersection strange behavior

26 views
Skip to first unread message

Diego

unread,
Nov 4, 2020, 7:29:15 AM11/4/20
to s2geometry-io
Hi,
I'm using the go version of s2 to build some services and I come across to this behavior of the Intersection function of a Rect that I cannot understand.


This is a snippet of the code:

rectA := s2.RectFromCenterSize(s2.LatLngFromDegrees(45, 10.5), s2.LatLngFromDegrees(2, 1))
rectB := s2.RectFromCenterSize(s2.LatLngFromDegrees(0, -4.5), s2.LatLngFromDegrees(8, 11))
intersection := rectA.Intersection(rectB)
fmt.Printf("Intersects? %t Valid? %t\n", rectA.Intersects(rectB), intersection.IsValid())
fmt.Printf("Rect A: %+v\n", rectA)
fmt.Printf("Rect B: %+v\n", rectB)
fmt.Printf("Intersection: %+v\n", intersection)


and this is the output:

Intersects? false Valid? true
Rect A: [Lo[44.0000000, 10.0000000], Hi[46.0000000, 11.0000000]]
Rect B: [Lo[-4.0000000, -10.0000000], Hi[4.0000000, 1.0000000]]
Intersection: [Lo[57.2957795, 180.0000000], Hi[0.0000000, -180.0000000]]


The Intersects() correctly returns false, but why the intersection is non-empty and valid? 
On the godoc ther's no reference to the intersection of two disjoints Rect.
I will check if the two Rects intersects before to calculate the intersection, but the Intersection() behaviour remains a little strange..  or maybe I missed something?

Thanks a lot.
Diego



Jesse Rosenstock

unread,
Nov 4, 2020, 7:50:30 AM11/4/20
to Diego, s2geometry-io
Check intersection.IsEmpty. I think this should be a valid, empty rect.


--
You received this message because you are subscribed to the Google Groups "s2geometry-io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to s2geometry-i...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/s2geometry-io/73fe50a6-3fba-4f04-90c3-ef2544db04d8n%40googlegroups.com.

Diego Savardi

unread,
Nov 5, 2020, 2:08:01 PM11/5/20
to Jesse Rosenstock, s2geometry-io
True, you're right. 

Thanks for the reply.
Diego



Reply all
Reply to author
Forward
0 new messages