mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-09 18:02:50 +01:00
line geometry validation and recovery
This commit is contained in:
parent
f2f3cd92ac
commit
aaa360e48d
2 changed files with 40 additions and 23 deletions
|
|
@ -502,6 +502,8 @@ TCAD.TWO.SketchObject.prototype.validate = function() {
|
|||
return true;
|
||||
};
|
||||
|
||||
TCAD.TWO.SketchObject.prototype.recover = function() {
|
||||
};
|
||||
|
||||
TCAD.TWO.SketchObject.prototype.getDefaultTool = function(viewer) {
|
||||
return new TCAD.TWO.DragTool(this, viewer);
|
||||
|
|
@ -628,14 +630,17 @@ TCAD.TWO.Segment = function(a, b) {
|
|||
TCAD.TWO.utils.extend(TCAD.TWO.Segment, TCAD.TWO.SketchObject);
|
||||
|
||||
TCAD.TWO.Segment.prototype._class = 'TCAD.TWO.Segment';
|
||||
TCAD.TWO.Segment.MIN_LENGTH = 0.1; // 0.08; // if length < 0.08 canvas doesn't even draw a line
|
||||
|
||||
TCAD.TWO.Segment.prototype.validate = function() {
|
||||
return TCAD.math.distanceAB(this.a, this.b) > TCAD.TWO.Segment.MIN_LENGTH;
|
||||
return TCAD.math.distanceAB(this.a, this.b) > TCAD.TOLERANCE;
|
||||
};
|
||||
|
||||
TCAD.TWO.Segment.prototype.addFixingGeomConstraints = function(constrs) {
|
||||
constrs.push(new TCAD.TWO.Constraints.MinLength(this.a, this.b, TCAD.TWO.Segment.MIN_LENGTH));
|
||||
TCAD.TWO.Segment.prototype.recover = function() {
|
||||
var recoverLength = 100;
|
||||
this.a.x -= recoverLength;
|
||||
this.a.y -= recoverLength;
|
||||
this.b.x += recoverLength;
|
||||
this.b.y += recoverLength;
|
||||
};
|
||||
|
||||
TCAD.TWO.Segment.prototype.collectParams = function(params) {
|
||||
|
|
@ -1051,21 +1056,22 @@ TCAD.TWO.DragTool.prototype.mousewheel = function(e) {
|
|||
TCAD.TWO.DragTool.prototype.solveRequest = function(rough) {
|
||||
this.solver.solve(rough, 1);
|
||||
this.solver.sync();
|
||||
if (false) {
|
||||
var fixingConstrs = [];
|
||||
this.viewer.accept(function(obj) {
|
||||
if (obj._class === 'TCAD.TWO.Segment') {
|
||||
if (!obj.validate()) {
|
||||
obj.addFixingGeomConstraints(fixingConstrs);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
if (fixingConstrs.length !== 0) {
|
||||
this.prepareSolver(fixingConstrs);
|
||||
this.solver.solve(rough, 1);
|
||||
this.solver.sync();
|
||||
|
||||
var paramsToUpdate = [];
|
||||
this.viewer.accept(function(obj) {
|
||||
if (!obj.validate()) {
|
||||
obj.recover();
|
||||
obj.collectParams(paramsToUpdate);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
if (paramsToUpdate.length != 0) {
|
||||
for (var i = 0; i < paramsToUpdate.length; i++) {
|
||||
this.solver.updateParameter(paramsToUpdate[i]);
|
||||
}
|
||||
this.solver.solve(rough, 1);
|
||||
this.solver.sync();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -517,6 +517,12 @@ TCAD.TWO.ParametricManager.prototype._prepare = function(locked, subSystems, ext
|
|||
}
|
||||
},
|
||||
|
||||
updateParameter : function(p) {
|
||||
for (var i = 0; i < solvers.length; i++) {
|
||||
solvers[i].updateParameter(p);
|
||||
}
|
||||
},
|
||||
|
||||
updateLock : function(values) {
|
||||
for (var i = 0; i < solvers.length; i++) {
|
||||
solvers[i].updateLock(values);
|
||||
|
|
@ -798,24 +804,29 @@ TCAD.TWO.ParametricManager.prototype.prepareForSubSystem = function(locked, subS
|
|||
}
|
||||
var viewer = this.viewer;
|
||||
function sync() {
|
||||
for (p in pdict) {
|
||||
_p = pdict[p];
|
||||
for (var p in pdict) {
|
||||
var _p = pdict[p];
|
||||
if (!!_p._backingParam.__aux) continue;
|
||||
_p._backingParam.set(_p.get());
|
||||
}
|
||||
|
||||
//Make sure all coincident constraints are equal
|
||||
for (ei = 0; ei < equalsIndex.length; ++ei) {
|
||||
for (var ei = 0; ei < equalsIndex.length; ++ei) {
|
||||
var master = equalsDict[ equalsIndex[ei][0]];
|
||||
for (i = 1; i < equalsIndex[ei].length; ++i) {
|
||||
for (var i = 1; i < equalsIndex[ei].length; ++i) {
|
||||
var slave = equalsDict[equalsIndex[ei][i]];
|
||||
slave.set(master.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function updateParameter(p) {
|
||||
getParam(p).set(p.get());
|
||||
}
|
||||
|
||||
solver.solve = solve;
|
||||
solver.sync = sync;
|
||||
solver.updateParameter = updateParameter;
|
||||
return solver;
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue