UNPKG

awv3

Version:
107 lines (92 loc) 3.76 kB
var _class, _temp; import { getTangent } from '../geomutils'; import ConstraintAdder from './adder'; import { incidence, horizontality, tangency, verticality } from './type'; var ConstraintGenerator = (_temp = _class = /*#__PURE__*/ function () { function ConstraintGenerator(sketch) { this.sketch = sketch; this.adder = new ConstraintAdder(this.sketch); this.generate = { horizontality: true, verticality: true, pointCoincidence: true, tangency: true }; } // generate implied constraints which are somehow related to "relatedTo" object var _proto = ConstraintGenerator.prototype; _proto.generateImpliedConstraints = function generateImpliedConstraints(relatedTo) { for (var _iterator = relatedTo.descendants, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { var _ref; if (_isArray) { if (_i >= _iterator.length) break; _ref = _iterator[_i++]; } else { _i = _iterator.next(); if (_i.done) break; _ref = _i.value; } var _baseObj = _ref; if (_baseObj.isLine()) { // generate implied horizontality or verticality var vec = getTangent(_baseObj.geomParams); // unit vector or zero if (vec.lengthSq() === 0) continue; if (Math.abs(vec.y) <= ConstraintGenerator.angularTolerance) this.adder.add(horizontality, [_baseObj], { fixed: true, noVisualize: true }); if (Math.abs(vec.x) <= ConstraintGenerator.angularTolerance) this.adder.add(verticality, [_baseObj], { fixed: true, noVisualize: true }); } if (!_baseObj.isPoint()) continue; var basePar = _baseObj.parent; for (var _iterator2 = this.sketch.descendants, _isArray2 = Array.isArray(_iterator2), _i2 = 0, _iterator2 = _isArray2 ? _iterator2 : _iterator2[Symbol.iterator]();;) { var _ref2; if (_isArray2) { if (_i2 >= _iterator2.length) break; _ref2 = _iterator2[_i2++]; } else { _i2 = _iterator2.next(); if (_i2.done) break; _ref2 = _i2.value; } var _otherObj = _ref2; // generate implied incidence of points if (!_otherObj.isPoint()) continue; var basePos = _baseObj.geomParams.start, otherPos = _otherObj.geomParams.start; if (basePos.distanceTo(otherPos) > ConstraintGenerator.linearTolerance) continue; this.adder.add(incidence, [_baseObj, _otherObj], { noVisualize: true }); var otherPar = _otherObj.parent; // generate implied tangency of touching endpoints if (!_baseObj.isSubPoint() || !_otherObj.isSubPoint() || basePar.id === otherPar.id) continue; if (_baseObj.isCenterPoint() || _otherObj.isCenterPoint()) continue; var baseDir = getTangent(basePar.geomParams, basePos), otherDir = getTangent(otherPar.geomParams, otherPos); if (baseDir.lengthSq() === 0 || otherDir.lengthSq() === 0) continue; if (Math.abs(baseDir.cross(otherDir).z) > ConstraintGenerator.angularTolerance) continue; var type = basePar.isLine() && otherPar.isLine() ? incidence : tangency; this.adder.add(type, [basePar, otherPar], { noVisualize: true }); } } return this.adder.commit(); }; return ConstraintGenerator; }(), Object.defineProperty(_class, "angularTolerance", { configurable: true, enumerable: true, writable: true, value: 1e-6 }), Object.defineProperty(_class, "linearTolerance", { configurable: true, enumerable: true, writable: true, value: 1e-6 }), _temp); export { ConstraintGenerator as default };