mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-07 17:04:58 +01:00
implement lock alternative locking mechanism
This commit is contained in:
parent
5a241e0545
commit
37e6c48698
2 changed files with 59 additions and 3 deletions
|
|
@ -34,6 +34,33 @@ TCAD.constraints.Equal = function(params) {
|
|||
|
||||
};
|
||||
|
||||
TCAD.constraints.ConstantWrapper = function(constr, mask) {
|
||||
|
||||
this.params = [];
|
||||
this.grad = [];
|
||||
|
||||
for (j = 0; j < constr.params.length; j++) {
|
||||
if (!mask[j]) {
|
||||
this.params.push(constr.params[j]);
|
||||
}
|
||||
this.grad.push(0);
|
||||
}
|
||||
|
||||
this.error = function() {
|
||||
return constr.error();
|
||||
}
|
||||
|
||||
this.gradient = function(out) {
|
||||
constr.gradient(this.grad);
|
||||
var jj = 0;
|
||||
for (j = 0; j < mask.length; j++) {
|
||||
if (!mask[j]) {
|
||||
out[jj ++] = this.grad[j];
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.constraints.EqualsTo = function(params, value) {
|
||||
|
||||
this.params = params;
|
||||
|
|
|
|||
|
|
@ -87,13 +87,42 @@ TCAD.parametric.System.prototype.getValues = function() {
|
|||
return values;
|
||||
};
|
||||
|
||||
TCAD.parametric.lock1 = function(constrs, locked) {
|
||||
|
||||
var lockedSet = {};
|
||||
for (var i = 0; i < locked.length; i++) {
|
||||
lockedSet[locked[i].id] = true;
|
||||
}
|
||||
|
||||
for (var i = 0; i < constrs.length; i++) {
|
||||
var c = constrs[i];
|
||||
var mask = [];
|
||||
var needWrap = false;
|
||||
for (var j = 0; j < c.params.length; j++) {
|
||||
var param = c.params[j];
|
||||
mask[j] = lockedSet[param.id] === true;
|
||||
needWrap = needWrap || mask[j];
|
||||
}
|
||||
if (needWrap) {
|
||||
var wrapper = new TCAD.constraints.ConstantWrapper(c, mask);
|
||||
constrs[i] = wrapper;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.parametric.lock2 = function(constrs, locked) {
|
||||
for (var i = 0; i < locked.length; ++i) {
|
||||
constrs.push(new TCAD.constraints.EqualsTo([locked[i]], locked[i].get()));
|
||||
}
|
||||
};
|
||||
|
||||
TCAD.parametric.solve = function(constrs, locked, fineLevel) {
|
||||
|
||||
if (constrs.length == 0) return;
|
||||
|
||||
for (var i = 0; i < locked.length; ++i) {
|
||||
constrs.push(new TCAD.constraints.EqualsTo([locked[i]], locked[i].get()));
|
||||
}
|
||||
|
||||
// this.lock1(constrs, locked);
|
||||
this.lock2(constrs, locked);
|
||||
|
||||
var sys = new TCAD.parametric.System(constrs);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue