@turbox3d/event-manager
Version:
Large-scale productivity application event management library
80 lines • 2.54 kB
JavaScript
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import { CoordinateType } from './type';
export var CoordinateController = /*#__PURE__*/function () {
function CoordinateController(_ref) {
var getCanvasRectImpl = _ref.getCanvasRectImpl,
canvasToSceneImpl = _ref.canvasToSceneImpl,
sceneToCanvasImpl = _ref.sceneToCanvasImpl;
_classCallCheck(this, CoordinateController);
this.getCanvasRectImpl = getCanvasRectImpl;
this.canvasToSceneImpl = canvasToSceneImpl;
this.sceneToCanvasImpl = sceneToCanvasImpl;
}
/**
* 将坐标进行转化
*/
return _createClass(CoordinateController, [{
key: "transform",
value: function transform(point, type, z) {
switch (type) {
case CoordinateType.ScreenToCanvas:
return this.screenToCanvas(point);
case CoordinateType.ScreenToScene:
return this.screenToScene(point, z);
case CoordinateType.CanvasToScreen:
return this.canvasToScreen(point);
case CoordinateType.CanvasToScene:
return this.canvasToScene(point, z);
case CoordinateType.SceneToScreen:
return this.sceneToScreen(point);
case CoordinateType.SceneToCanvas:
return this.sceneToCanvas(point);
default:
return point;
}
}
}, {
key: "screenToCanvas",
value: function screenToCanvas(point) {
var _this$getCanvasRectIm = this.getCanvasRectImpl(),
x = _this$getCanvasRectIm.x,
y = _this$getCanvasRectIm.y;
return {
x: point.x - x,
y: point.y - y
};
}
}, {
key: "canvasToScreen",
value: function canvasToScreen(point) {
var _this$getCanvasRectIm2 = this.getCanvasRectImpl(),
x = _this$getCanvasRectIm2.x,
y = _this$getCanvasRectIm2.y;
return {
x: point.x + x,
y: point.y + y
};
}
}, {
key: "canvasToScene",
value: function canvasToScene(point, z) {
return this.canvasToSceneImpl(point, z);
}
}, {
key: "sceneToCanvas",
value: function sceneToCanvas(point) {
return this.sceneToCanvasImpl(point);
}
}, {
key: "screenToScene",
value: function screenToScene(point, z) {
return this.canvasToScene(this.screenToCanvas(point), z);
}
}, {
key: "sceneToScreen",
value: function sceneToScreen(point) {
return this.canvasToScreen(this.sceneToCanvas(point));
}
}]);
}();