mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-12 03:13:24 +01:00
fix Hor/Vert constraints
This commit is contained in:
parent
578fe5967b
commit
99f9e4ba44
2 changed files with 36 additions and 10 deletions
|
|
@ -62,6 +62,15 @@ TCAD.TWO.ParametricManager.prototype._fetchPointAndLine = function(objs) {
|
|||
return [point, line];
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype._fetchLine = function(objs) {
|
||||
for (var i = 0; i < objs.length; ++i) {
|
||||
if (objs[i]._class == 'TCAD.TWO.Segment') {
|
||||
return objs[i];
|
||||
}
|
||||
}
|
||||
throw "Illegal Argument. Constraint requires a line."
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype._fetchArcCircAndLine = function(objs) {
|
||||
|
||||
var arc = null;
|
||||
|
|
|
|||
|
|
@ -81,13 +81,11 @@ TCAD.TWO.ParametricManager.prototype.lock = function(objs) {
|
|||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype.vertical = function(objs) {
|
||||
var p = this._fetchTwoPoints(objs);
|
||||
this.add(new TCAD.TWO.Constraints.Equal(p[0]._x, p[1]._x));
|
||||
this.add(new TCAD.TWO.Constraints.Vertical(this._fetchLine(objs)));
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype.horizontal = function(objs) {
|
||||
var p = this._fetchTwoPoints(objs);
|
||||
this.add(new TCAD.TWO.Constraints.Equal(p[0]._y, p[1]._y));
|
||||
this.add(new TCAD.TWO.Constraints.Horizontal(this._fetchLine(objs)));
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype.parallel = function(objs) {
|
||||
|
|
@ -694,23 +692,42 @@ TCAD.TWO.Constraints.Factory[TCAD.TWO.Constraints.RR.prototype.NAME] = function(
|
|||
|
||||
// ------------------------------------------------------------------------------------------------------------------ //
|
||||
|
||||
TCAD.TWO.Constraints.Vertical = function(arc1, arc2) {
|
||||
this.arc1 = arc1;
|
||||
this.arc2 = arc2;
|
||||
TCAD.TWO.Constraints.Vertical = function(line) {
|
||||
this.line = line;
|
||||
};
|
||||
|
||||
TCAD.TWO.Constraints.Vertical.prototype.NAME = 'Vertical';
|
||||
|
||||
TCAD.TWO.Constraints.Vertical.prototype.getSolveData = function() {
|
||||
return [['equal', [this.arc1.r, this.arc2.r], []]];
|
||||
return [['equal', [this.line.a._x, this.line.b._x], []]];
|
||||
};
|
||||
|
||||
TCAD.TWO.Constraints.Vertical.prototype.serialize = function() {
|
||||
return [this.NAME, [this.arc1.id, this.arc2.id]];
|
||||
return [this.NAME, [this.line.id]];
|
||||
};
|
||||
|
||||
TCAD.TWO.Constraints.Factory[TCAD.TWO.Constraints.Vertical.prototype.NAME] = function(refs, data) {
|
||||
return new TCAD.TWO.Constraints.RR(refs(data[0]), refs(data[1]));
|
||||
return new TCAD.TWO.Constraints.Vertical(refs(data[0]));
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------------------ //
|
||||
|
||||
TCAD.TWO.Constraints.Horizontal = function(line) {
|
||||
this.line = line;
|
||||
};
|
||||
|
||||
TCAD.TWO.Constraints.Horizontal.prototype.NAME = 'Horizontal';
|
||||
|
||||
TCAD.TWO.Constraints.Horizontal.prototype.getSolveData = function() {
|
||||
return [['equal', [this.line.a._y, this.line.b._y], []]];
|
||||
};
|
||||
|
||||
TCAD.TWO.Constraints.Horizontal.prototype.serialize = function() {
|
||||
return [this.NAME, [this.line.id]];
|
||||
};
|
||||
|
||||
TCAD.TWO.Constraints.Factory[TCAD.TWO.Constraints.Horizontal.prototype.NAME] = function(refs, data) {
|
||||
return new TCAD.TWO.Constraints.Horizontal(refs(data[0]));
|
||||
};
|
||||
|
||||
// ------------------------------------------------------------------------------------------------------------------ //
|
||||
Loading…
Reference in a new issue