kitchen-simulator
Version:
It is a kitchen simulator (self-contained micro-frontend).
101 lines (100 loc) • 4.21 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.sceneSnapElements = sceneSnapElements;
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
var _snap = require("./snap");
var _export = require("./export");
var _immutable = require("immutable");
function sceneSnapElements(scene) {
var snapElements = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new _immutable.List();
var snapMask = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new _immutable.Map();
var width = scene.width,
height = scene.height;
var a, b, c;
return snapElements.withMutations(function (snapElements) {
scene.layers.forEach(function (layer) {
var lines = layer.lines,
vertices = layer.vertices;
vertices.forEach(function (_ref) {
var vertexID = _ref.id,
x = _ref.x,
y = _ref.y;
if (snapMask.get(_snap.SNAP_POINT)) {
(0, _snap.addPointSnap)(snapElements, x, y, 10, 10, vertexID);
}
if (snapMask.get(_snap.SNAP_LINE)) {
var _GeometryUtils$horizo = _export.GeometryUtils.horizontalLine(y);
a = _GeometryUtils$horizo.a;
b = _GeometryUtils$horizo.b;
c = _GeometryUtils$horizo.c;
(0, _snap.addLineSnap)(snapElements, a, b, c, 10, 1, vertexID);
var _GeometryUtils$vertic = _export.GeometryUtils.verticalLine(x);
a = _GeometryUtils$vertic.a;
b = _GeometryUtils$vertic.b;
c = _GeometryUtils$vertic.c;
(0, _snap.addLineSnap)(snapElements, a, b, c, 10, 1, vertexID);
var _GeometryUtils$upcros = _export.GeometryUtils.upcrossLine(x, y);
a = _GeometryUtils$upcros.a;
b = _GeometryUtils$upcros.b;
c = _GeometryUtils$upcros.c;
(0, _snap.addLineSnap)(snapElements, a, b, c, 10, 3, null);
var _GeometryUtils$downcr = _export.GeometryUtils.downcrossLine(x, y);
a = _GeometryUtils$downcr.a;
b = _GeometryUtils$downcr.b;
c = _GeometryUtils$downcr.c;
(0, _snap.addLineSnap)(snapElements, a, b, c, 10, 3, null);
}
});
if (snapMask.get(_snap.SNAP_SEGMENT)) {
lines.forEach(function (_ref2) {
var lineID = _ref2.id,
_ref2$vertices = (0, _slicedToArray2["default"])(_ref2.vertices, 2),
v0 = _ref2$vertices[0],
v1 = _ref2$vertices[1];
var _vertices$get = vertices.get(v0),
x1 = _vertices$get.x,
y1 = _vertices$get.y;
var _vertices$get2 = vertices.get(v1),
x2 = _vertices$get2.x,
y2 = _vertices$get2.y;
(0, _snap.addLineSegmentSnap)(snapElements, x1, y1, x2, y2, 20, 1, lineID);
});
}
});
if (snapMask.get(_snap.SNAP_GRID)) {
var divider = 5;
var gridCellSize = 100 / divider;
var xCycle = width / gridCellSize;
var yCycle = height / gridCellSize;
for (var x = 0; x < xCycle; x++) {
var xMul = x * gridCellSize;
for (var y = 0; y < yCycle; y++) {
var yMul = y * gridCellSize;
var onXCross = !(x % divider) ? true : false;
var onYCross = !(y % divider) ? true : false;
(0, _snap.addGridSnap)(snapElements, xMul, yMul, 10, onXCross && onYCross ? 15 : 10, null);
}
}
}
if (snapMask.get(_snap.SNAP_GUIDE)) {
var horizontal = scene.getIn(['guides', 'horizontal']);
var vertical = scene.getIn(['guides', 'vertical']);
var hValues = horizontal.valueSeq();
var vValues = vertical.valueSeq();
hValues.forEach(function (hVal) {
vValues.forEach(function (vVal) {
(0, _snap.addPointSnap)(snapElements, vVal, hVal, 10, 10);
});
});
hValues.forEach(function (hVal) {
return (0, _snap.addLineSegmentSnap)(snapElements, 0, hVal, width, hVal, 20, 1);
});
vValues.forEach(function (vVal) {
return (0, _snap.addLineSegmentSnap)(snapElements, vVal, 0, vVal, height, 20, 1);
});
}
});
}