jsketcher/web/app/fetchers.js
2014-10-15 00:08:14 -07:00

95 lines
2.4 KiB
JavaScript

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._fetchPoints = function(objs) {
var points = [];
for (var i = 0; i < objs.length; ++i) {
objs[i].visit(false, function(o) {
if (o._class === 'TCAD.TWO.EndPoint') {
points.push(o);
}
return true;
});
}
if (points.length == 0) {
throw "Illegal Argument. Constraint requires at least 1 point/line/arc."
}
return points;
};
TCAD.TWO.ParametricManager.prototype._fetchArcs = function(objs, min) {
var arcs = [];
for (var i = 0; i < objs.length; ++i) {
if (objs[i]._class == 'TCAD.TWO.Arc') {
arcs.push(objs[i]);
}
}
if (arcs.length < min) {
throw "Illegal Argument. Constraint requires at least " + min + " 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._fetchArcAndLine = function(objs) {
var arc = null;
var line = null;
for (var i = 0; i < objs.length; ++i) {
if (objs[i]._class == 'TCAD.TWO.Arc') {
arc = objs[i];
} else if (objs[i]._class == 'TCAD.TWO.Segment') {
line = objs[i];
}
}
if (arc == null || line == null) {
throw "Illegal Argument. Constraint requires arc and line."
}
return [arc, 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;
};