Browse Source

Fixes bounds for circle

main
Steve Ruiz 4 years ago
parent
commit
09dd62c8ec
1 changed files with 8 additions and 16 deletions
  1. 8
    16
      utils/shape-utils.ts

+ 8
- 16
utils/shape-utils.ts View File

@@ -9,7 +9,7 @@ import * as vec from "./vec"
9 9
 
10 10
 type BaseShapeUtils<K extends ShapeType> = {
11 11
   getBounds(shape: Shapes[K]): Bounds
12
-  hitTest(shape: Shapes[K], test: number[] | Bounds): boolean
12
+  hitTest(shape: Shapes[K], test: number[]): boolean
13 13
   rotate(shape: Shapes[K]): Shapes[K]
14 14
   translate(shape: Shapes[K]): Shapes[K]
15 15
   scale(shape: Shapes[K], scale: number): Shapes[K]
@@ -35,9 +35,6 @@ const DotUtils: BaseShapeUtils<ShapeType.Dot> = {
35 35
   },
36 36
 
37 37
   hitTest(shape, test) {
38
-    if ("minX" in test) {
39
-      return pointInBounds(shape.point, test)
40
-    }
41 38
     return vec.dist(shape.point, test) < 4
42 39
   },
43 40
 
@@ -68,24 +65,19 @@ const CircleUtils: BaseShapeUtils<ShapeType.Circle> = {
68 65
     } = shape
69 66
 
70 67
     return {
71
-      minX: cx - radius,
72
-      maxX: cx + radius,
73
-      minY: cy - radius,
74
-      maxY: cy + radius,
68
+      minX: cx,
69
+      maxX: cx + radius * 2,
70
+      minY: cy,
71
+      maxY: cy + radius * 2,
75 72
       width: radius * 2,
76 73
       height: radius * 2,
77 74
     }
78 75
   },
79 76
 
80 77
   hitTest(shape, test) {
81
-    if ("minX" in test) {
82
-      const bounds = CircleUtils.getBounds(shape)
83
-      return (
84
-        boundsContain(bounds, test) ||
85
-        intersectCircleBounds(shape.point, shape.radius, bounds).length > 0
86
-      )
87
-    }
88
-    return vec.dist(shape.point, test) < 4
78
+    return (
79
+      vec.dist(vec.addScalar(shape.point, shape.radius), test) < shape.radius
80
+    )
89 81
   },
90 82
 
91 83
   rotate(shape) {

Loading…
Cancel
Save