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
 
9
 
10
 type BaseShapeUtils<K extends ShapeType> = {
10
 type BaseShapeUtils<K extends ShapeType> = {
11
   getBounds(shape: Shapes[K]): Bounds
11
   getBounds(shape: Shapes[K]): Bounds
12
-  hitTest(shape: Shapes[K], test: number[] | Bounds): boolean
12
+  hitTest(shape: Shapes[K], test: number[]): boolean
13
   rotate(shape: Shapes[K]): Shapes[K]
13
   rotate(shape: Shapes[K]): Shapes[K]
14
   translate(shape: Shapes[K]): Shapes[K]
14
   translate(shape: Shapes[K]): Shapes[K]
15
   scale(shape: Shapes[K], scale: number): Shapes[K]
15
   scale(shape: Shapes[K], scale: number): Shapes[K]
35
   },
35
   },
36
 
36
 
37
   hitTest(shape, test) {
37
   hitTest(shape, test) {
38
-    if ("minX" in test) {
39
-      return pointInBounds(shape.point, test)
40
-    }
41
     return vec.dist(shape.point, test) < 4
38
     return vec.dist(shape.point, test) < 4
42
   },
39
   },
43
 
40
 
68
     } = shape
65
     } = shape
69
 
66
 
70
     return {
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
       width: radius * 2,
72
       width: radius * 2,
76
       height: radius * 2,
73
       height: radius * 2,
77
     }
74
     }
78
   },
75
   },
79
 
76
 
80
   hitTest(shape, test) {
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
   rotate(shape) {
83
   rotate(shape) {

Loading…
Cancel
Save