nimble install bumpy
Based on the book http://www.jeffreythompson.org/collision-detection/table_of_contents.php
Supported collisions:
Shape | Point | Circle | Rectangle | Segment | Polygon |
---|---|---|---|---|---|
Point | ✅ | ✅ | ✅ | ✅ | ✅ |
Circle | ✅ | ✅ | ✅ | ✅ | ✅ |
Rectangle | ✅ | ✅ | ✅ | ✅ | ✅ |
Segment | ✅ | ✅ | ✅ | ✅ | ✅ |
Polygon | ✅ | ✅ | ✅ | ✅ | ✅ |
import bumpy
Circle = object
pos*: Vec2
radius*: float32
Segment = object
at*: Vec2
to*: Vec2
proc circle(pos: Vec2; radius: float32): Circle {.inline.}
proc segment(at, to: Vec2): Segment {.inline.}
Do two points overlap? (Must be exactly equal.)
proc overlap(a, b: Vec2): bool {.inline.}
Test overlap: point vs circle.
proc overlap(a: Vec2; b: Circle): bool {.inline.}
Test overlap: circle vs point.
proc overlap(a: Circle; b: Vec2): bool {.inline.}
Test overlap: circle vs circle.
proc overlap(a, b: Circle): bool
Test overlap: point vs rectangle.
proc overlap(a: Vec2; b: Rect): bool
Test overlap: rect vs point.
proc overlap(a: Rect; b: Vec2): bool {.inline.}
Do two rectangles overlap?
proc overlap(a, b: Rect): bool
Test overlap: circle vs rectangle.
proc overlap(a: Circle; b: Rect): bool
Test overlap: rect vs circle.
proc overlap(a: Rect; b: Circle): bool {.inline.}
Test overlap: point vs segment.
proc overlap(a: Vec2; s: Segment; buffer = 0.1): bool
Test overlap: segment vs point.
proc overlap(a: Segment; b: Vec2; buffer = 0.1): bool {.inline, tags: [].}
Test overlap: circle vs segment.
proc overlap(c: Circle; s: Segment): bool
Test overlap: circle vs segment.
proc overlap(s: Segment; c: Circle): bool {.inline.}
Test overlap: segment vs segment.
proc overlap(d, s: Segment): bool
Test overlap: segments vs rectangle.
proc overlap(s: Segment; r: Rect): bool
Test overlap: rectangle vs segment.
proc overlap(r: Rect; s: Segment): bool {.inline.}
Test overlap: polygon vs point.
proc overlap(poly: seq[Vec2]; p: Vec2): bool
Test overlap: point vs polygon.
proc overlap(p: Vec2; poly: seq[Vec2]): bool {.inline.}
Test overlap: polygon vs circle.
proc overlap(poly: seq[Vec2]; c: Circle): bool
Test overlap: circle vs polygon.
proc overlap(c: Circle; poly: seq[Vec2]): bool {.inline.}
Test overlap: polygon vs rect.
proc overlap(poly: seq[Vec2]; r: Rect): bool
Test overlap: rect vs polygon.
proc overlap(r: Rect; poly: seq[Vec2]): bool {.inline.}
Test overlap: polygon vs segment.
proc overlap(poly: seq[Vec2]; s: Segment): bool
Test overlap: segment vs polygon.
proc overlap(s: Segment; poly: seq[Vec2]): bool {.inline.}
Test overlap: polygon vs polygon.
proc overlap(a: seq[Vec2]; b: seq[Vec2]): bool
Checks if the a segment intersects b segment. If it returns true, at will have point of intersection
proc intersects(a, b: Segment; at: var Vec2): bool {.inline, tags: [].}