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

Rectangle.intersect can give negative rectangles - worth a comment #34

Open
davidedc opened this issue Nov 28, 2015 · 1 comment
Open

Comments

@davidedc
Copy link

This is correct, but I think it deserves a comment, because, say, it matters if one wants to implement a proper isEmpty routine (which I didn't, and costed me several hours of debugging :-)

new Rectangle(10,10,20,20).intersect(new Rectangle(15,25,19,25))

gives a rectangle with the corner above the origin:

  origin: Point
    x: 15
    y: 25
  corner: Point
    x: 19
    y: 20

(the proper "is empty" test indeed is already in morphic.js
!dirty.extent().gt(new Point(0, 0))
, just not in a dedicated routine)

Also note how a negative rectangle can be expanded to be positive (which again is correct but worth a comment, as the intuition might otherwise suggest that many operations including expansion should be "void" on an empty rectangle):

new Rectangle(10,10,20,20).intersect(new Rectangle(15,25,19,25)).expandBy(3).area() -> 10

@davidedc
Copy link
Author

Also - similar topic: 2 empty rectangles can be merged into a bigger non-empty rectangle

new Rectangle(0,0,0,0).merge(new Rectangle(10,10,10,10))

gives the rectangle at origin 0,0 and corner at 10,10

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