Adam Shaw 8 лет назад
Родитель
Сommit
8f5a376acf
4 измененных файлов с 48 добавлено и 51 удалено
  1. 1 1
      src/common/HitDragListener.ts
  2. 5 2
      src/exports.ts
  3. 0 48
      src/util.ts
  4. 42 0
      src/util/geom.ts

+ 1 - 1
src/common/HitDragListener.ts

@@ -3,7 +3,7 @@ import {
   intersectRects,
   getRectCenter,
   diffPoints
-} from '../util'
+} from '../util/geom'
 import {
   getEvX,
   getEvY,

+ 5 - 2
src/exports.ts

@@ -31,10 +31,13 @@ export {
   durationHasTime,
   log,
   warn,
-  removeExact,
-  intersectRects
+  removeExact
 } from './util'
 
+export {
+  intersectRects
+} from './util/geom'
+
 export {
   assignTo
 } from './util/object'

+ 0 - 48
src/util.ts

@@ -176,54 +176,6 @@ export function allowSelection(el: HTMLElement) {
 }
 
 
-
-/* General Geometry Utils
-----------------------------------------------------------------------------------------------------------------------*/
-
-
-// Returns a new rectangle that is the intersection of the two rectangles. If they don't intersect, returns false
-export function intersectRects(rect1, rect2) {
-  let res = {
-    left: Math.max(rect1.left, rect2.left),
-    right: Math.min(rect1.right, rect2.right),
-    top: Math.max(rect1.top, rect2.top),
-    bottom: Math.min(rect1.bottom, rect2.bottom)
-  }
-
-  if (res.left < res.right && res.top < res.bottom) {
-    return res
-  }
-  return false
-}
-
-
-// Returns a new point that will have been moved to reside within the given rectangle
-export function constrainPoint(point, rect) {
-  return {
-    left: Math.min(Math.max(point.left, rect.left), rect.right),
-    top: Math.min(Math.max(point.top, rect.top), rect.bottom)
-  }
-}
-
-
-// Returns a point that is the center of the given rectangle
-export function getRectCenter(rect) {
-  return {
-    left: (rect.left + rect.right) / 2,
-    top: (rect.top + rect.bottom) / 2
-  }
-}
-
-
-// Subtracts point2's coordinates from point1's coordinates, returning a delta
-export function diffPoints(point1, point2) {
-  return {
-    left: point1.left - point2.left,
-    top: point1.top - point2.top
-  }
-}
-
-
 /* Object Ordering by Field
 ----------------------------------------------------------------------------------------------------------------------*/
 

+ 42 - 0
src/util/geom.ts

@@ -0,0 +1,42 @@
+
+// Returns a new rectangle that is the intersection of the two rectangles. If they don't intersect, returns false
+export function intersectRects(rect1, rect2) {
+  let res = {
+    left: Math.max(rect1.left, rect2.left),
+    right: Math.min(rect1.right, rect2.right),
+    top: Math.max(rect1.top, rect2.top),
+    bottom: Math.min(rect1.bottom, rect2.bottom)
+  }
+
+  if (res.left < res.right && res.top < res.bottom) {
+    return res
+  }
+  return false
+}
+
+
+// Returns a new point that will have been moved to reside within the given rectangle
+export function constrainPoint(point, rect) {
+  return {
+    left: Math.min(Math.max(point.left, rect.left), rect.right),
+    top: Math.min(Math.max(point.top, rect.top), rect.bottom)
+  }
+}
+
+
+// Returns a point that is the center of the given rectangle
+export function getRectCenter(rect) {
+  return {
+    left: (rect.left + rect.right) / 2,
+    top: (rect.top + rect.bottom) / 2
+  }
+}
+
+
+// Subtracts point2's coordinates from point1's coordinates, returning a delta
+export function diffPoints(point1, point2) {
+  return {
+    left: point1.left - point2.left,
+    top: point1.top - point2.top
+  }
+}