mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-25 01:45:26 +01:00
equalize linked endpoints
This commit is contained in:
parent
9944b71370
commit
99ceec4cd1
2 changed files with 38 additions and 10 deletions
|
|
@ -786,6 +786,8 @@ ParametricManager.prototype.prepareForSubSystem = function(locked, subSystemCons
|
|||
function solve(rough, alg) {
|
||||
return solver.solveSystem(rough, alg);
|
||||
}
|
||||
|
||||
const viewer = this.viewer;
|
||||
function sync() {
|
||||
for (var paramId in solverParamsDict) {
|
||||
var solverParam = solverParamsDict[paramId];
|
||||
|
|
@ -801,6 +803,7 @@ ParametricManager.prototype.prepareForSubSystem = function(locked, subSystemCons
|
|||
slave.set(master.get());
|
||||
}
|
||||
}
|
||||
viewer.equalizeLinkedEndpoints();
|
||||
}
|
||||
|
||||
function updateParameter(p) {
|
||||
|
|
|
|||
|
|
@ -151,6 +151,10 @@ Viewer.prototype.add = function(obj, layer) {
|
|||
obj.layer = layer;
|
||||
};
|
||||
|
||||
function isEndPoint(o) {
|
||||
return o._class === 'TCAD.TWO.EndPoint'
|
||||
}
|
||||
|
||||
Viewer.prototype.search = function(x, y, buffer, deep, onlyPoints, filter) {
|
||||
|
||||
buffer *= 0.5;
|
||||
|
|
@ -176,7 +180,7 @@ Viewer.prototype.search = function(x, y, buffer, deep, onlyPoints, filter) {
|
|||
var before = pickResult.length;
|
||||
objs[j].accept(function(o) {
|
||||
if (!o.visible) return true;
|
||||
if (onlyPoints && o._class !== 'TCAD.TWO.EndPoint') {
|
||||
if (onlyPoints && !isEndPoint(o)) {
|
||||
return false;
|
||||
}
|
||||
l = o.normalDistance(aim);
|
||||
|
|
@ -241,10 +245,10 @@ Viewer.prototype.repaint = function() {
|
|||
};
|
||||
|
||||
Viewer.__SKETCH_DRAW_PIPELINE = [
|
||||
(obj) => obj._class !== 'TCAD.TWO.EndPoint' && obj.marked === null,
|
||||
(obj) => obj._class !== 'TCAD.TWO.EndPoint' && obj.marked !== null,
|
||||
(obj) => obj._class === 'TCAD.TWO.EndPoint' && obj.marked === null,
|
||||
(obj) => obj._class === 'TCAD.TWO.EndPoint' && obj.marked !== null
|
||||
(obj) => !isEndPoint(obj) && obj.marked === null,
|
||||
(obj) => !isEndPoint(obj) && obj.marked !== null,
|
||||
(obj) => isEndPoint(obj) && obj.marked === null,
|
||||
(obj) => isEndPoint(obj) && obj.marked !== null
|
||||
];
|
||||
|
||||
Viewer.__SIMPLE_DRAW_PIPELINE = [
|
||||
|
|
@ -330,11 +334,9 @@ Viewer.prototype._screenToModel = function(x, y) {
|
|||
};
|
||||
|
||||
Viewer.prototype.accept = function(visitor) {
|
||||
for (var i = 0; i < this.layers.length; i++) {
|
||||
var objs = this.layers[i].objects;
|
||||
var result = null;
|
||||
for (var j = 0; j < objs.length; j++) {
|
||||
if (!objs[j].accept(visitor)) {
|
||||
for (let layer of this.layers) {
|
||||
for (let object of layer.objects) {
|
||||
if (!object.accept(visitor)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -427,6 +429,29 @@ Viewer.prototype.deselectAll = function() {
|
|||
while(this.selected.length > 0) this.selected.pop();
|
||||
};
|
||||
|
||||
Viewer.prototype.equalizeLinkedEndpoints = function() {
|
||||
const visited = new Set();
|
||||
|
||||
function equalize(obj) {
|
||||
if (visited.has(obj.id)) return;
|
||||
visited.add(obj.id);
|
||||
for (let link of obj.linked) {
|
||||
if (isEndPoint(link)) {
|
||||
equalize(obj, link);
|
||||
link.setFromPoint(obj);
|
||||
equalize(link);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.accept((obj) => {
|
||||
if (isEndPoint(obj)) {
|
||||
equalize(obj);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/** @constructor */
|
||||
function Layer(name, style) {
|
||||
this.name = name;
|
||||
|
|
|
|||
Loading…
Reference in a new issue