mirror of
https://github.com/xibyte/jsketcher
synced 2025-12-14 20:33:30 +01:00
add radius equal constraint
This commit is contained in:
parent
5c144c0aff
commit
79e428d749
4 changed files with 77 additions and 50 deletions
60
web/app/fetchers.js
Normal file
60
web/app/fetchers.js
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
TCAD.TWO.ParametricManager.prototype._fetchTwoPoints = function(objs) {
|
||||
var points = [];
|
||||
for (var i = 0; i < objs.length; ++i) {
|
||||
if (objs[i]._class == 'TCAD.TWO.EndPoint') {
|
||||
points.push(objs[i]);
|
||||
} else if (objs[i]._class == 'TCAD.TWO.Segment') {
|
||||
points.push(objs[i].a);
|
||||
points.push(objs[i].b);
|
||||
}
|
||||
}
|
||||
if (points.length < 2) {
|
||||
throw "Illegal Argument. Constraint requires 2 points or 1 line."
|
||||
}
|
||||
return points;
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype._fetchTwoOrMoreArcs = function(objs) {
|
||||
var arcs = [];
|
||||
for (var i = 0; i < objs.length; ++i) {
|
||||
if (objs[i]._class == 'TCAD.TWO.Arc') {
|
||||
arcs.push(objs[i]);
|
||||
}
|
||||
}
|
||||
if (arcs.length < 2) {
|
||||
throw "Illegal Argument. Constraint requires ata least 2 arcs."
|
||||
}
|
||||
return arcs;
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype._fetchPointAndLine = function(objs) {
|
||||
|
||||
var point = null;
|
||||
var line = null;
|
||||
|
||||
for (var i = 0; i < objs.length; ++i) {
|
||||
if (objs[i]._class == 'TCAD.TWO.EndPoint') {
|
||||
point = objs[i];
|
||||
} else if (objs[i]._class == 'TCAD.TWO.Segment') {
|
||||
line = objs[i];
|
||||
}
|
||||
}
|
||||
if (point == null || line == null) {
|
||||
throw "Illegal Argument. Constraint requires point and line."
|
||||
}
|
||||
|
||||
return [point, line];
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype._fetchTwoLines = function(objs) {
|
||||
var lines = [];
|
||||
for (var i = 0; i < objs.length; ++i) {
|
||||
if (objs[i]._class == 'TCAD.TWO.Segment') {
|
||||
lines.push(objs[i]);
|
||||
}
|
||||
}
|
||||
if (lines.length < 2) {
|
||||
throw "Illegal Argument. Constraint requires 2 lines."
|
||||
}
|
||||
return lines;
|
||||
};
|
||||
|
|
@ -91,6 +91,10 @@ TCAD.App2D = function() {
|
|||
|
||||
P2PDistance : function() {
|
||||
app.viewer.parametricManager.p2pDistance(app.viewer.selected, prompt);
|
||||
},
|
||||
|
||||
"R = R" : function() {
|
||||
app.viewer.parametricManager.rr(app.viewer.selected, prompt);
|
||||
}
|
||||
|
||||
};
|
||||
|
|
@ -105,6 +109,7 @@ TCAD.App2D = function() {
|
|||
actionsF.add(actions, 'perpendicular');
|
||||
actionsF.add(actions, 'P2LDistance');
|
||||
actionsF.add(actions, 'P2PDistance');
|
||||
actionsF.add(actions, 'R = R');
|
||||
actionsF.open();
|
||||
|
||||
};
|
||||
|
|
|
|||
|
|
@ -12,55 +12,6 @@ TCAD.TWO.ParametricManager.prototype.add = function(constr) {
|
|||
this.viewer.refresh();
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype._fetchTwoPoints = function(objs) {
|
||||
var points = [];
|
||||
for (var i = 0; i < objs.length; ++i) {
|
||||
if (objs[i]._class == 'TCAD.TWO.EndPoint') {
|
||||
points.push(objs[i]);
|
||||
} else if (objs[i]._class == 'TCAD.TWO.Segment') {
|
||||
points.push(objs[i].a);
|
||||
points.push(objs[i].b);
|
||||
}
|
||||
}
|
||||
if (points.length < 2) {
|
||||
throw "Illegal Argument. Constraint requires 2 points or 1 line."
|
||||
}
|
||||
return points;
|
||||
};
|
||||
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype._fetchPointAndLine = function(objs) {
|
||||
|
||||
var point = null;
|
||||
var line = null;
|
||||
|
||||
for (var i = 0; i < objs.length; ++i) {
|
||||
if (objs[i]._class == 'TCAD.TWO.EndPoint') {
|
||||
point = objs[i];
|
||||
} else if (objs[i]._class == 'TCAD.TWO.Segment') {
|
||||
line = objs[i];
|
||||
}
|
||||
}
|
||||
if (point == null || line == null) {
|
||||
throw "Illegal Argument. Constraint requires point and line."
|
||||
}
|
||||
|
||||
return [point, line];
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype._fetchTwoLines = function(objs) {
|
||||
var lines = [];
|
||||
for (var i = 0; i < objs.length; ++i) {
|
||||
if (objs[i]._class == 'TCAD.TWO.Segment') {
|
||||
lines.push(objs[i]);
|
||||
}
|
||||
}
|
||||
if (lines.length < 2) {
|
||||
throw "Illegal Argument. Constraint requires 2 lines."
|
||||
}
|
||||
return lines;
|
||||
};
|
||||
|
||||
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));
|
||||
|
|
@ -81,6 +32,17 @@ TCAD.TWO.ParametricManager.prototype.perpendicular = function(objs) {
|
|||
this.add(new TCAD.TWO.Constraints.Perpendicular(lines[0], lines[1]));
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype.rr = function(objs) {
|
||||
var arcs = this._fetchTwoOrMoreArcs(objs);
|
||||
var prev = arcs[0].r;
|
||||
for (var i = 1; i < arcs.length; ++i) {
|
||||
this.system.push(new TCAD.TWO.Constraints.Equal(prev, arcs[i].r));
|
||||
prev = arcs[i].r;
|
||||
}
|
||||
this.solve();
|
||||
this.viewer.refresh();
|
||||
};
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype.p2lDistance = function(objs, promptCallback) {
|
||||
var pl = this._fetchPointAndLine(objs);
|
||||
|
||||
|
|
@ -119,7 +81,6 @@ TCAD.TWO.ParametricManager.prototype.p2pDistance = function(objs, promptCallback
|
|||
}
|
||||
};
|
||||
|
||||
|
||||
TCAD.TWO.ParametricManager.prototype.coincident = function(objs) {
|
||||
if (objs.length == 0) return;
|
||||
var last = objs.length - 1;
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@
|
|||
<script src="app/constr/solver.js"></script>
|
||||
|
||||
<script src="app/parametric.js"></script>
|
||||
<script src="app/fetchers.js"></script>
|
||||
<script src="app/engine.js"></script>
|
||||
<script src="app/vector.js"></script>
|
||||
<script src="app/bsp.js"></script>
|
||||
|
|
|
|||
Loading…
Reference in a new issue