mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-28 11:22:59 +01:00
make solving configurable by fine level param
This commit is contained in:
parent
8c2cccc2cb
commit
dfb6c6cccf
3 changed files with 24 additions and 13 deletions
|
|
@ -609,8 +609,8 @@ TCAD.TWO.DragTool.prototype.mousemove = function(e) {
|
|||
var y = this._point.y;
|
||||
this.viewer.screenToModel2(e.x, e.y, this._point);
|
||||
this.obj.translate(this._point.x - x, this._point.y - y);
|
||||
this.solveRequest(2);
|
||||
this.viewer.refresh();
|
||||
this.solveRequest();
|
||||
};
|
||||
|
||||
TCAD.TWO.DragTool.prototype.mousedown = function(e) {
|
||||
|
|
@ -618,19 +618,20 @@ TCAD.TWO.DragTool.prototype.mousedown = function(e) {
|
|||
};
|
||||
|
||||
TCAD.TWO.DragTool.prototype.mouseup = function(e) {
|
||||
this.solveRequest();
|
||||
this.solveRequest(0);
|
||||
this.viewer.refresh();
|
||||
this.viewer.toolManager.releaseControl();
|
||||
};
|
||||
|
||||
TCAD.TWO.DragTool.prototype.mousewheel = function(e) {
|
||||
};
|
||||
|
||||
TCAD.TWO.DragTool.prototype.solveRequest = function(e) {
|
||||
TCAD.TWO.DragTool.prototype.solveRequest = function(fineLevel) {
|
||||
var locked;
|
||||
if (this.obj._class == 'TCAD.TWO.EndPoint') {
|
||||
locked = [this.obj._x, this.obj._y];
|
||||
} else {
|
||||
locked = [];
|
||||
}
|
||||
this.viewer.parametricManager.solve(locked);
|
||||
this.viewer.parametricManager.solve(locked, fineLevel);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -77,7 +77,7 @@ TCAD.parametric.System.prototype.getValues = function() {
|
|||
return values;
|
||||
};
|
||||
|
||||
TCAD.parametric.solve = function(constrs, locked) {
|
||||
TCAD.parametric.solve = function(constrs, locked, fineLevel) {
|
||||
|
||||
if (constrs.length == 0) return;
|
||||
|
||||
|
|
@ -109,9 +109,21 @@ TCAD.parametric.solve = function(constrs, locked) {
|
|||
};
|
||||
|
||||
var opt = new LMOptimizer(sys.getParams(), arr(sys.constraints.length), model, jacobian);
|
||||
opt.init();
|
||||
|
||||
switch (fineLevel) {
|
||||
case 1:
|
||||
eps = 0.01;
|
||||
opt.init0(eps, eps, eps);
|
||||
break;
|
||||
case 2:
|
||||
eps = 0.1;
|
||||
opt.init0(eps, eps, eps);
|
||||
break;
|
||||
default:
|
||||
eps = 0.00000001;
|
||||
opt.init0(eps, eps, eps);
|
||||
}
|
||||
|
||||
var res = opt.doOptimize();
|
||||
|
||||
sys.setParams(res[0]);
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ TCAD.TWO.ParametricManager = function(viewer) {
|
|||
TCAD.TWO.ParametricManager.prototype.add = function(constr) {
|
||||
this.system.push(constr);
|
||||
this.solve();
|
||||
this.viewer.refresh();
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype._fetchTwoPoints = function(objs) {
|
||||
|
|
@ -189,7 +190,7 @@ TCAD.TWO.ParametricManager.prototype.solve1 = function(locked, onSolved) {
|
|||
};
|
||||
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype.solve = function(locked, onSolved) {
|
||||
TCAD.TWO.ParametricManager.prototype.solve = function(locked, fineLevel) {
|
||||
var pdict = {};
|
||||
var params;
|
||||
var i;
|
||||
|
|
@ -226,15 +227,12 @@ TCAD.TWO.ParametricManager.prototype.solve = function(locked, onSolved) {
|
|||
}
|
||||
}
|
||||
|
||||
TCAD.parametric.solve(_constrs, _locked);
|
||||
TCAD.parametric.solve(_constrs, _locked, fineLevel);
|
||||
|
||||
for (var p in pdict) {
|
||||
var _p = pdict[p];
|
||||
_p._backingParam.set(_p.get());
|
||||
}
|
||||
if (onSolved !== undefined) {
|
||||
onSolved();
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.TWO.Constraints.Equal = function(p1, p2) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue