Standardize naming of FromXxx (and XxxFrom) static methods to
create a `new' stack-allocated instance of an object; just From, possibly different versions with different arg types. [git-p4: depot-paths = "//depot/solvespace/": change = 1763]solver
parent
709b5ad80e
commit
04af0944bc
|
@ -100,10 +100,10 @@ void Constraint::MenuConstrain(int id) {
|
|||
c.disp.offset = n.Cross(a.Minus(b));
|
||||
c.disp.offset = (c.disp.offset).WithMagnitude(50/SS.GW.scale);
|
||||
} else {
|
||||
c.disp.offset = Vector::MakeFrom(0, 0, 0);
|
||||
c.disp.offset = Vector::From(0, 0, 0);
|
||||
}
|
||||
|
||||
c.exprA = Expr::FromString("0")->DeepCopyKeep();
|
||||
c.exprA = Expr::From("0")->DeepCopyKeep();
|
||||
c.ModifyToSatisfy();
|
||||
AddConstraint(&c);
|
||||
break;
|
||||
|
@ -159,7 +159,7 @@ void Constraint::MenuConstrain(int id) {
|
|||
return;
|
||||
}
|
||||
|
||||
c.exprA = Expr::FromString("0")->DeepCopyKeep();
|
||||
c.exprA = Expr::From("0")->DeepCopyKeep();
|
||||
c.ModifyToSatisfy();
|
||||
AddConstraint(&c);
|
||||
break;
|
||||
|
@ -282,7 +282,7 @@ void Constraint::MenuConstrain(int id) {
|
|||
c.type = ANGLE;
|
||||
c.entityA = gs.vector[0];
|
||||
c.entityB = gs.vector[1];
|
||||
c.exprA = Expr::FromConstant(0)->DeepCopyKeep();
|
||||
c.exprA = Expr::From(0.0)->DeepCopyKeep();
|
||||
c.otherAngle = true;
|
||||
} else {
|
||||
Error("Bad selection for angle constraint.");
|
||||
|
@ -440,7 +440,7 @@ void Constraint::ModifyToSatisfy(void) {
|
|||
double c = (a.Dot(b))/(a.Magnitude() * b.Magnitude());
|
||||
double theta = acos(c)*180/PI;
|
||||
Expr::FreeKeep(&exprA);
|
||||
exprA = Expr::FromConstant(theta)->DeepCopyKeep();
|
||||
exprA = Expr::From(theta)->DeepCopyKeep();
|
||||
} else {
|
||||
// We'll fix these ones up by looking at their symbolic equation;
|
||||
// that means no extra work.
|
||||
|
@ -456,7 +456,7 @@ void Constraint::ModifyToSatisfy(void) {
|
|||
double v = (l.elem[0].e)->Eval();
|
||||
double nd = exprA->Eval() + v;
|
||||
Expr::FreeKeep(&exprA);
|
||||
exprA = Expr::FromConstant(nd)->DeepCopyKeep();
|
||||
exprA = Expr::From(nd)->DeepCopyKeep();
|
||||
|
||||
l.Clear();
|
||||
}
|
||||
|
@ -509,7 +509,7 @@ void Constraint::Generate(IdList<Equation,hEquation> *l) {
|
|||
case DIAMETER: {
|
||||
Entity *circle = SS.GetEntity(entityA);
|
||||
Expr *r = circle->CircleGetRadiusExpr();
|
||||
AddEq(l, (r->Times(Expr::FromConstant(2)))->Minus(exA), 0);
|
||||
AddEq(l, (r->Times(Expr::From(2)))->Minus(exA), 0);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -580,7 +580,7 @@ void Constraint::Generate(IdList<Equation,hEquation> *l) {
|
|||
Entity *ln = SS.GetEntity(entityA);
|
||||
ExprVector a = SS.GetEntity(ln->point[0])->PointGetExprs();
|
||||
ExprVector b = SS.GetEntity(ln->point[1])->PointGetExprs();
|
||||
ExprVector m = (a.Plus(b)).ScaledBy(Expr::FromConstant(0.5));
|
||||
ExprVector m = (a.Plus(b)).ScaledBy(Expr::From(0.5));
|
||||
|
||||
if(ptA.v) {
|
||||
ExprVector p = SS.GetEntity(ptA)->PointGetExprs();
|
||||
|
@ -598,8 +598,8 @@ void Constraint::Generate(IdList<Equation,hEquation> *l) {
|
|||
Expr *au, *av, *bu, *bv;
|
||||
a->PointGetExprsInWorkplane(workplane, &au, &av);
|
||||
b->PointGetExprsInWorkplane(workplane, &bu, &bv);
|
||||
Expr *mu = Expr::FromConstant(0.5)->Times(au->Plus(bu));
|
||||
Expr *mv = Expr::FromConstant(0.5)->Times(av->Plus(bv));
|
||||
Expr *mu = Expr::From(0.5)->Times(au->Plus(bu));
|
||||
Expr *mv = Expr::From(0.5)->Times(av->Plus(bv));
|
||||
|
||||
if(ptA.v) {
|
||||
Entity *p = SS.GetEntity(ptA);
|
||||
|
@ -624,7 +624,7 @@ void Constraint::Generate(IdList<Equation,hEquation> *l) {
|
|||
|
||||
// The midpoint of the line connecting the symmetric points
|
||||
// lies on the plane of the symmetry.
|
||||
ExprVector m = (a.Plus(b)).ScaledBy(Expr::FromConstant(0.5));
|
||||
ExprVector m = (a.Plus(b)).ScaledBy(Expr::From(0.5));
|
||||
AddEq(l, PointPlaneDistance(m, plane->h), 0);
|
||||
|
||||
// And projected into the plane of symmetry, the points are
|
||||
|
@ -642,8 +642,8 @@ void Constraint::Generate(IdList<Equation,hEquation> *l) {
|
|||
Expr *au, *av, *bu, *bv;
|
||||
a->PointGetExprsInWorkplane(workplane, &au, &av);
|
||||
b->PointGetExprsInWorkplane(workplane, &bu, &bv);
|
||||
Expr *mu = Expr::FromConstant(0.5)->Times(au->Plus(bu));
|
||||
Expr *mv = Expr::FromConstant(0.5)->Times(av->Plus(bv));
|
||||
Expr *mu = Expr::From(0.5)->Times(au->Plus(bu));
|
||||
Expr *mv = Expr::From(0.5)->Times(av->Plus(bv));
|
||||
|
||||
ExprVector m = PointInThreeSpace(workplane, mu, mv);
|
||||
AddEq(l, PointPlaneDistance(m, plane->h), 0);
|
||||
|
@ -735,7 +735,7 @@ void Constraint::Generate(IdList<Equation,hEquation> *l) {
|
|||
Entity *b = SS.GetEntity(entityB);
|
||||
ExprVector ae = a->VectorGetExprs();
|
||||
ExprVector be = b->VectorGetExprs();
|
||||
if(otherAngle) ae = ae.ScaledBy(Expr::FromConstant(-1));
|
||||
if(otherAngle) ae = ae.ScaledBy(Expr::From(-1));
|
||||
Expr *c;
|
||||
if(workplane.v == Entity::FREE_IN_3D.v) {
|
||||
Expr *mags = (ae.Magnitude())->Times(be.Magnitude());
|
||||
|
@ -753,7 +753,7 @@ void Constraint::Generate(IdList<Equation,hEquation> *l) {
|
|||
Expr *dot = (ua->Times(ub))->Plus(va->Times(vb));
|
||||
c = dot->Div(maga->Times(magb));
|
||||
}
|
||||
Expr *rads = exA->Times(Expr::FromConstant(PI/180));
|
||||
Expr *rads = exA->Times(Expr::From(PI/180));
|
||||
AddEq(l, c->Minus(rads->Cos()), 0);
|
||||
break;
|
||||
}
|
||||
|
|
8
dsc.h
8
dsc.h
|
@ -15,8 +15,8 @@ public:
|
|||
// a + (vx)*i + (vy)*j + (vz)*k
|
||||
double w, vx, vy, vz;
|
||||
|
||||
static Quaternion MakeFrom(double w, double vx, double vy, double vz);
|
||||
static Quaternion MakeFrom(Vector u, Vector v);
|
||||
static Quaternion From(double w, double vx, double vy, double vz);
|
||||
static Quaternion From(Vector u, Vector v);
|
||||
|
||||
Quaternion Plus(Quaternion b);
|
||||
Quaternion Minus(Quaternion b);
|
||||
|
@ -40,8 +40,8 @@ class Vector {
|
|||
public:
|
||||
double x, y, z;
|
||||
|
||||
static Vector MakeFrom(double x, double y, double z);
|
||||
static Vector MakeFrom(hParam x, hParam y, hParam z);
|
||||
static Vector From(double x, double y, double z);
|
||||
static Vector From(hParam x, hParam y, hParam z);
|
||||
static Vector AtIntersectionOfPlanes(Vector n1, double d1,
|
||||
Vector n2, double d2);
|
||||
|
||||
|
|
108
entity.cpp
108
entity.cpp
|
@ -154,9 +154,9 @@ double Entity::DistanceGetNum(void) {
|
|||
}
|
||||
Expr *Entity::DistanceGetExpr(void) {
|
||||
if(type == DISTANCE) {
|
||||
return Expr::FromParam(param[0]);
|
||||
return Expr::From(param[0]);
|
||||
} else if(type == DISTANCE_N_COPY) {
|
||||
return Expr::FromConstant(numDistance);
|
||||
return Expr::From(numDistance);
|
||||
} else oops();
|
||||
}
|
||||
void Entity::DistanceForceTo(double v) {
|
||||
|
@ -298,10 +298,10 @@ ExprQuaternion Entity::NormalGetExprs(void) {
|
|||
ExprQuaternion q;
|
||||
switch(type) {
|
||||
case NORMAL_IN_3D:
|
||||
q.w = Expr::FromParam(param[0]);
|
||||
q.vx = Expr::FromParam(param[1]);
|
||||
q.vy = Expr::FromParam(param[2]);
|
||||
q.vz = Expr::FromParam(param[3]);
|
||||
q.w = Expr::From(param[0]);
|
||||
q.vx = Expr::From(param[1]);
|
||||
q.vy = Expr::From(param[2]);
|
||||
q.vz = Expr::From(param[3]);
|
||||
break;
|
||||
|
||||
case NORMAL_IN_2D: {
|
||||
|
@ -311,34 +311,31 @@ ExprQuaternion Entity::NormalGetExprs(void) {
|
|||
break;
|
||||
}
|
||||
case NORMAL_N_COPY:
|
||||
q.w = Expr::FromConstant(numNormal.w);
|
||||
q.vx = Expr::FromConstant(numNormal.vx);
|
||||
q.vy = Expr::FromConstant(numNormal.vy);
|
||||
q.vz = Expr::FromConstant(numNormal.vz);
|
||||
q = ExprQuaternion::From(numNormal);
|
||||
break;
|
||||
|
||||
case NORMAL_N_ROT: {
|
||||
ExprQuaternion orig = ExprQuaternion::FromNum(numNormal);
|
||||
ExprQuaternion orig = ExprQuaternion::From(numNormal);
|
||||
|
||||
q.w = Expr::FromParam(param[0]);
|
||||
q.vx = Expr::FromParam(param[1]);
|
||||
q.vy = Expr::FromParam(param[2]);
|
||||
q.vz = Expr::FromParam(param[3]);
|
||||
q.w = Expr::From(param[0]);
|
||||
q.vx = Expr::From(param[1]);
|
||||
q.vy = Expr::From(param[2]);
|
||||
q.vz = Expr::From(param[3]);
|
||||
|
||||
q = q.Times(orig);
|
||||
break;
|
||||
}
|
||||
|
||||
case NORMAL_N_ROT_AA: {
|
||||
ExprQuaternion orig = ExprQuaternion::FromNum(numNormal);
|
||||
ExprQuaternion orig = ExprQuaternion::From(numNormal);
|
||||
|
||||
Expr *theta = Expr::FromConstant(timesApplied)->Times(
|
||||
Expr::FromParam(param[0]));
|
||||
Expr *theta = Expr::From(timesApplied)->Times(
|
||||
Expr::From(param[0]));
|
||||
Expr *c = theta->Cos(), *s = theta->Sin();
|
||||
q.w = c;
|
||||
q.vx = s->Times(Expr::FromParam(param[1]));
|
||||
q.vy = s->Times(Expr::FromParam(param[2]));
|
||||
q.vz = s->Times(Expr::FromParam(param[3]));
|
||||
q.vx = s->Times(Expr::From(param[1]));
|
||||
q.vy = s->Times(Expr::From(param[2]));
|
||||
q.vz = s->Times(Expr::From(param[3]));
|
||||
|
||||
q = q.Times(orig);
|
||||
break;
|
||||
|
@ -391,8 +388,8 @@ void Entity::PointForceTo(Vector p) {
|
|||
|
||||
case POINT_N_ROT_AA: {
|
||||
// Force only the angle; the axis and center of rotation stay
|
||||
Vector offset = Vector::MakeFrom(param[0], param[1], param[2]);
|
||||
Vector normal = Vector::MakeFrom(param[4], param[5], param[6]);
|
||||
Vector offset = Vector::From(param[0], param[1], param[2]);
|
||||
Vector normal = Vector::From(param[4], param[5], param[6]);
|
||||
Vector u = normal.Normal(0), v = normal.Normal(1);
|
||||
Vector po = p.Minus(offset), numo = numPoint.Minus(offset);
|
||||
double thetap = atan2(v.Dot(po), u.Dot(po));
|
||||
|
@ -444,7 +441,7 @@ Vector Entity::PointGetNum(void) {
|
|||
}
|
||||
|
||||
case POINT_N_ROT_TRANS: {
|
||||
Vector offset = Vector::MakeFrom(
|
||||
Vector offset = Vector::From(
|
||||
SS.GetParam(param[0])->val,
|
||||
SS.GetParam(param[1])->val,
|
||||
SS.GetParam(param[2])->val);
|
||||
|
@ -455,7 +452,7 @@ Vector Entity::PointGetNum(void) {
|
|||
}
|
||||
|
||||
case POINT_N_ROT_AA: {
|
||||
Vector offset = Vector::MakeFrom(
|
||||
Vector offset = Vector::From(
|
||||
SS.GetParam(param[0])->val,
|
||||
SS.GetParam(param[1])->val,
|
||||
SS.GetParam(param[2])->val);
|
||||
|
@ -479,9 +476,9 @@ ExprVector Entity::PointGetExprs(void) {
|
|||
ExprVector r;
|
||||
switch(type) {
|
||||
case POINT_IN_3D:
|
||||
r.x = Expr::FromParam(param[0]);
|
||||
r.y = Expr::FromParam(param[1]);
|
||||
r.z = Expr::FromParam(param[2]);
|
||||
r.x = Expr::From(param[0]);
|
||||
r.y = Expr::From(param[1]);
|
||||
r.z = Expr::From(param[2]);
|
||||
break;
|
||||
|
||||
case POINT_IN_2D: {
|
||||
|
@ -489,56 +486,53 @@ ExprVector Entity::PointGetExprs(void) {
|
|||
ExprVector u = c->Normal()->NormalExprsU();
|
||||
ExprVector v = c->Normal()->NormalExprsV();
|
||||
r = c->WorkplaneGetOffsetExprs();
|
||||
r = r.Plus(u.ScaledBy(Expr::FromParam(param[0])));
|
||||
r = r.Plus(v.ScaledBy(Expr::FromParam(param[1])));
|
||||
r = r.Plus(u.ScaledBy(Expr::From(param[0])));
|
||||
r = r.Plus(v.ScaledBy(Expr::From(param[1])));
|
||||
break;
|
||||
}
|
||||
case POINT_N_TRANS: {
|
||||
ExprVector orig = {
|
||||
Expr::FromConstant(numPoint.x),
|
||||
Expr::FromConstant(numPoint.y),
|
||||
Expr::FromConstant(numPoint.z) };
|
||||
Expr::From(numPoint.x),
|
||||
Expr::From(numPoint.y),
|
||||
Expr::From(numPoint.z) };
|
||||
ExprVector trans;
|
||||
trans.x = Expr::FromParam(param[0]);
|
||||
trans.y = Expr::FromParam(param[1]);
|
||||
trans.z = Expr::FromParam(param[2]);
|
||||
r = orig.Plus(trans.ScaledBy(Expr::FromConstant(timesApplied)));
|
||||
trans.x = Expr::From(param[0]);
|
||||
trans.y = Expr::From(param[1]);
|
||||
trans.z = Expr::From(param[2]);
|
||||
r = orig.Plus(trans.ScaledBy(Expr::From(timesApplied)));
|
||||
break;
|
||||
}
|
||||
case POINT_N_ROT_TRANS: {
|
||||
ExprVector orig = ExprVector::FromNum(numPoint);
|
||||
ExprVector orig = ExprVector::From(numPoint);
|
||||
ExprVector trans =
|
||||
ExprVector::FromParams(param[0], param[1], param[2]);
|
||||
ExprVector::From(param[0], param[1], param[2]);
|
||||
ExprQuaternion q = {
|
||||
Expr::FromParam(param[3]),
|
||||
Expr::FromParam(param[4]),
|
||||
Expr::FromParam(param[5]),
|
||||
Expr::FromParam(param[6]) };
|
||||
Expr::From(param[3]),
|
||||
Expr::From(param[4]),
|
||||
Expr::From(param[5]),
|
||||
Expr::From(param[6]) };
|
||||
orig = q.Rotate(orig);
|
||||
r = orig.Plus(trans);
|
||||
break;
|
||||
}
|
||||
case POINT_N_ROT_AA: {
|
||||
ExprVector orig = ExprVector::FromNum(numPoint);
|
||||
ExprVector trans =
|
||||
ExprVector::FromParams(param[0], param[1], param[2]);
|
||||
Expr *theta = Expr::FromConstant(timesApplied)->Times(
|
||||
Expr::FromParam(param[3]));
|
||||
ExprVector orig = ExprVector::From(numPoint);
|
||||
ExprVector trans = ExprVector::From(param[0], param[1], param[2]);
|
||||
Expr *theta = Expr::From(timesApplied)->Times(
|
||||
Expr::From(param[3]));
|
||||
Expr *c = theta->Cos(), *s = theta->Sin();
|
||||
ExprQuaternion q = {
|
||||
c,
|
||||
s->Times(Expr::FromParam(param[4])),
|
||||
s->Times(Expr::FromParam(param[5])),
|
||||
s->Times(Expr::FromParam(param[6])) };
|
||||
s->Times(Expr::From(param[4])),
|
||||
s->Times(Expr::From(param[5])),
|
||||
s->Times(Expr::From(param[6])) };
|
||||
orig = orig.Minus(trans);
|
||||
orig = q.Rotate(orig);
|
||||
r = orig.Plus(trans);
|
||||
break;
|
||||
}
|
||||
case POINT_N_COPY:
|
||||
r.x = Expr::FromConstant(numPoint.x);
|
||||
r.y = Expr::FromConstant(numPoint.y);
|
||||
r.z = Expr::FromConstant(numPoint.z);
|
||||
r = ExprVector::From(numPoint);
|
||||
break;
|
||||
|
||||
default: oops();
|
||||
|
@ -550,8 +544,8 @@ void Entity::PointGetExprsInWorkplane(hEntity wrkpl, Expr **u, Expr **v) {
|
|||
if(type == POINT_IN_2D && workplane.v == wrkpl.v) {
|
||||
// They want our coordinates in the form that we've written them,
|
||||
// very nice.
|
||||
*u = Expr::FromParam(param[0]);
|
||||
*v = Expr::FromParam(param[1]);
|
||||
*u = Expr::From(param[0]);
|
||||
*v = Expr::From(param[1]);
|
||||
} else {
|
||||
// Get the offset and basis vectors for this weird exotic csys.
|
||||
Entity *w = SS.GetEntity(wrkpl);
|
||||
|
@ -931,7 +925,7 @@ void Entity::GenerateEquations(IdList<Equation,hEquation> *l) {
|
|||
switch(type) {
|
||||
case NORMAL_IN_3D: {
|
||||
ExprQuaternion q = NormalGetExprs();
|
||||
AddEq(l, (q.Magnitude())->Minus(Expr::FromConstant(1)), 0);
|
||||
AddEq(l, (q.Magnitude())->Minus(Expr::From(1)), 0);
|
||||
break;
|
||||
}
|
||||
case ARC_OF_CIRCLE: {
|
||||
|
|
52
expr.cpp
52
expr.cpp
|
@ -1,23 +1,23 @@
|
|||
#include "solvespace.h"
|
||||
|
||||
ExprVector ExprVector::FromExprs(Expr *x, Expr *y, Expr *z) {
|
||||
ExprVector ExprVector::From(Expr *x, Expr *y, Expr *z) {
|
||||
ExprVector r = { x, y, z};
|
||||
return r;
|
||||
}
|
||||
|
||||
ExprVector ExprVector::FromNum(Vector vn) {
|
||||
ExprVector ExprVector::From(Vector vn) {
|
||||
ExprVector ve;
|
||||
ve.x = Expr::FromConstant(vn.x);
|
||||
ve.y = Expr::FromConstant(vn.y);
|
||||
ve.z = Expr::FromConstant(vn.z);
|
||||
ve.x = Expr::From(vn.x);
|
||||
ve.y = Expr::From(vn.y);
|
||||
ve.z = Expr::From(vn.z);
|
||||
return ve;
|
||||
}
|
||||
|
||||
ExprVector ExprVector::FromParams(hParam x, hParam y, hParam z) {
|
||||
ExprVector ExprVector::From(hParam x, hParam y, hParam z) {
|
||||
ExprVector ve;
|
||||
ve.x = Expr::FromParam(x);
|
||||
ve.y = Expr::FromParam(y);
|
||||
ve.z = Expr::FromParam(z);
|
||||
ve.x = Expr::From(x);
|
||||
ve.y = Expr::From(y);
|
||||
ve.z = Expr::From(z);
|
||||
return ve;
|
||||
}
|
||||
|
||||
|
@ -77,7 +77,7 @@ Vector ExprVector::Eval(void) {
|
|||
return r;
|
||||
}
|
||||
|
||||
ExprQuaternion ExprQuaternion::FromExprs(Expr *w, Expr *vx, Expr *vy, Expr *vz)
|
||||
ExprQuaternion ExprQuaternion::From(Expr *w, Expr *vx, Expr *vy, Expr *vz)
|
||||
{
|
||||
ExprQuaternion q;
|
||||
q.w = w;
|
||||
|
@ -87,18 +87,18 @@ ExprQuaternion ExprQuaternion::FromExprs(Expr *w, Expr *vx, Expr *vy, Expr *vz)
|
|||
return q;
|
||||
}
|
||||
|
||||
ExprQuaternion ExprQuaternion::FromNum(Quaternion qn) {
|
||||
ExprQuaternion ExprQuaternion::From(Quaternion qn) {
|
||||
ExprQuaternion qe;
|
||||
qe.w = Expr::FromConstant(qn.w);
|
||||
qe.vx = Expr::FromConstant(qn.vx);
|
||||
qe.vy = Expr::FromConstant(qn.vy);
|
||||
qe.vz = Expr::FromConstant(qn.vz);
|
||||
qe.w = Expr::From(qn.w);
|
||||
qe.vx = Expr::From(qn.vx);
|
||||
qe.vy = Expr::From(qn.vy);
|
||||
qe.vz = Expr::From(qn.vz);
|
||||
return qe;
|
||||
}
|
||||
|
||||
ExprVector ExprQuaternion::RotationU(void) {
|
||||
ExprVector u;
|
||||
Expr *two = Expr::FromConstant(2);
|
||||
Expr *two = Expr::From(2);
|
||||
|
||||
u.x = w->Square();
|
||||
u.x = (u.x)->Plus(vx->Square());
|
||||
|
@ -116,7 +116,7 @@ ExprVector ExprQuaternion::RotationU(void) {
|
|||
|
||||
ExprVector ExprQuaternion::RotationV(void) {
|
||||
ExprVector v;
|
||||
Expr *two = Expr::FromConstant(2);
|
||||
Expr *two = Expr::From(2);
|
||||
|
||||
v.x = two->Times(vx->Times(vy));
|
||||
v.x = (v.x)->Minus(two->Times(w->Times(vz)));
|
||||
|
@ -134,7 +134,7 @@ ExprVector ExprQuaternion::RotationV(void) {
|
|||
|
||||
ExprVector ExprQuaternion::RotationN(void) {
|
||||
ExprVector n;
|
||||
Expr *two = Expr::FromConstant(2);
|
||||
Expr *two = Expr::From(2);
|
||||
|
||||
n.x = two->Times( w->Times(vy));
|
||||
n.x = (n.x)->Plus (two->Times(vx->Times(vz)));
|
||||
|
@ -181,14 +181,14 @@ Expr *ExprQuaternion::Magnitude(void) {
|
|||
}
|
||||
|
||||
|
||||
Expr *Expr::FromParam(hParam p) {
|
||||
Expr *Expr::From(hParam p) {
|
||||
Expr *r = AllocExpr();
|
||||
r->op = PARAM;
|
||||
r->x.parh = p;
|
||||
return r;
|
||||
}
|
||||
|
||||
Expr *Expr::FromConstant(double v) {
|
||||
Expr *Expr::From(double v) {
|
||||
Expr *r = AllocExpr();
|
||||
r->op = CONSTANT;
|
||||
r->x.v = v;
|
||||
|
@ -312,10 +312,10 @@ Expr *Expr::PartialWrt(hParam p) {
|
|||
Expr *da, *db;
|
||||
|
||||
switch(op) {
|
||||
case PARAM_PTR: return FromConstant(p.v == x.parp->h.v ? 1 : 0);
|
||||
case PARAM: return FromConstant(p.v == x.parh.v ? 1 : 0);
|
||||
case PARAM_PTR: return From(p.v == x.parp->h.v ? 1 : 0);
|
||||
case PARAM: return From(p.v == x.parh.v ? 1 : 0);
|
||||
|
||||
case CONSTANT: return FromConstant(0);
|
||||
case CONSTANT: return From(0.0);
|
||||
|
||||
case PLUS: return (a->PartialWrt(p))->Plus(b->PartialWrt(p));
|
||||
case MINUS: return (a->PartialWrt(p))->Minus(b->PartialWrt(p));
|
||||
|
@ -331,10 +331,10 @@ Expr *Expr::PartialWrt(hParam p) {
|
|||
return ((da->Times(b))->Minus(a->Times(db)))->Div(b->Square());
|
||||
|
||||
case SQRT:
|
||||
return (FromConstant(0.5)->Div(a->Sqrt()))->Times(a->PartialWrt(p));
|
||||
return (From(0.5)->Div(a->Sqrt()))->Times(a->PartialWrt(p));
|
||||
|
||||
case SQUARE:
|
||||
return (FromConstant(2.0)->Times(a))->Times(a->PartialWrt(p));
|
||||
return (From(2.0)->Times(a))->Times(a->PartialWrt(p));
|
||||
|
||||
case NEGATE: return (a->PartialWrt(p))->Negate();
|
||||
case SIN: return (a->Cos())->Times(a->PartialWrt(p));
|
||||
|
@ -670,7 +670,7 @@ void Expr::Lex(char *in) {
|
|||
}
|
||||
}
|
||||
|
||||
Expr *Expr::FromString(char *in) {
|
||||
Expr *Expr::From(char *in) {
|
||||
UnparsedCnt = 0;
|
||||
UnparsedP = 0;
|
||||
OperandsP = 0;
|
||||
|
|
16
expr.h
16
expr.h
|
@ -56,8 +56,8 @@ public:
|
|||
static inline Expr *AllocExpr(void)
|
||||
{ return (Expr *)AllocTemporary(sizeof(Expr)); }
|
||||
|
||||
static Expr *FromParam(hParam p);
|
||||
static Expr *FromConstant(double v);
|
||||
static Expr *From(hParam p);
|
||||
static Expr *From(double v);
|
||||
|
||||
Expr *AnyOp(int op, Expr *b);
|
||||
inline Expr *Plus (Expr *b) { return AnyOp(PLUS, b); }
|
||||
|
@ -99,7 +99,7 @@ public:
|
|||
Expr *DeepCopyWithParamsAsPointers(IdList<Param,hParam> *firstTry,
|
||||
IdList<Param,hParam> *thenTry);
|
||||
|
||||
static Expr *FromString(char *in);
|
||||
static Expr *From(char *in);
|
||||
static void Lex(char *in);
|
||||
static Expr *Next(void);
|
||||
static void Consume(void);
|
||||
|
@ -122,9 +122,9 @@ class ExprVector {
|
|||
public:
|
||||
Expr *x, *y, *z;
|
||||
|
||||
static ExprVector FromExprs(Expr *x, Expr *y, Expr *z);
|
||||
static ExprVector FromNum(Vector vn);
|
||||
static ExprVector FromParams(hParam x, hParam y, hParam z);
|
||||
static ExprVector From(Expr *x, Expr *y, Expr *z);
|
||||
static ExprVector From(Vector vn);
|
||||
static ExprVector From(hParam x, hParam y, hParam z);
|
||||
|
||||
ExprVector Plus(ExprVector b);
|
||||
ExprVector Minus(ExprVector b);
|
||||
|
@ -140,8 +140,8 @@ class ExprQuaternion {
|
|||
public:
|
||||
Expr *w, *vx, *vy, *vz;
|
||||
|
||||
static ExprQuaternion FromExprs(Expr *w, Expr *vx, Expr *vy, Expr *vz);
|
||||
static ExprQuaternion FromNum(Quaternion qn);
|
||||
static ExprQuaternion From(Expr *w, Expr *vx, Expr *vy, Expr *vz);
|
||||
static ExprQuaternion From(Quaternion qn);
|
||||
|
||||
ExprVector RotationU(void);
|
||||
ExprVector RotationV(void);
|
||||
|
|
6
file.cpp
6
file.cpp
|
@ -42,7 +42,7 @@ void SolveSpace::NewFile(void) {
|
|||
// And an empty group, for the first stuff the user draws.
|
||||
g.type = Group::DRAWING_WORKPLANE;
|
||||
g.subtype = Group::WORKPLANE_BY_POINT_ORTHO;
|
||||
g.predef.q = Quaternion::MakeFrom(1, 0, 0, 0);
|
||||
g.predef.q = Quaternion::From(1, 0, 0, 0);
|
||||
hRequest hr = Request::HREQUEST_REFERENCE_XY;
|
||||
g.predef.origin = hr.entity(1);
|
||||
g.name.strcpy("draw-in-plane");
|
||||
|
@ -251,8 +251,8 @@ void SolveSpace::LoadUsingTable(char *key, char *val) {
|
|||
case 'N': ((NameStr *)p)->strcpy(val); break;
|
||||
case 'E':
|
||||
Expr *e;
|
||||
e = Expr::FromString(val);
|
||||
if(!e) e = Expr::FromConstant(0);
|
||||
e = Expr::From(val);
|
||||
if(!e) e = Expr::From(0.0);
|
||||
*((Expr **)p) = e->DeepCopyKeep();
|
||||
break;
|
||||
|
||||
|
|
|
@ -269,7 +269,7 @@ void glxDebugMesh(SMesh *m)
|
|||
|
||||
void glxMarkPolygonNormal(SPolygon *p)
|
||||
{
|
||||
Vector tail = Vector::MakeFrom(0, 0, 0);
|
||||
Vector tail = Vector::From(0, 0, 0);
|
||||
int i, j, cnt = 0;
|
||||
// Choose some reasonable center point.
|
||||
for(i = 0; i < p->l.n; i++) {
|
||||
|
|
|
@ -150,7 +150,7 @@ void GraphicsWindow::AnimateOntoWorkplane(void) {
|
|||
Vector offsetf = (SS.GetEntity(w->point[0])->PointGetNum()).ScaledBy(-1);
|
||||
|
||||
// Get our initial orientation and translation.
|
||||
Quaternion quat0 = Quaternion::MakeFrom(projRight, projUp);
|
||||
Quaternion quat0 = Quaternion::From(projRight, projUp);
|
||||
Vector offset0 = offset;
|
||||
|
||||
// Make sure we take the shorter of the two possible paths.
|
||||
|
@ -577,7 +577,7 @@ void GraphicsWindow::MouseMoved(double x, double y, bool leftDown,
|
|||
v = v.RotatedAbout(orig.projUp, -s*dx);
|
||||
v = v.RotatedAbout(orig.projRight, s*dy);
|
||||
}
|
||||
q = Quaternion::MakeFrom(u, v);
|
||||
q = Quaternion::From(u, v);
|
||||
p->PointForceQuaternionTo(q);
|
||||
// Let's rotate about the selected point; so fix up the
|
||||
// translation so that that point didn't move.
|
||||
|
@ -649,7 +649,7 @@ void GraphicsWindow::MouseMoved(double x, double y, bool leftDown,
|
|||
v = v.RotatedAbout(orig.projRight, s*dy);
|
||||
}
|
||||
orig.mouse = mp;
|
||||
normal->NormalForceTo(Quaternion::MakeFrom(u, v));
|
||||
normal->NormalForceTo(Quaternion::From(u, v));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -944,7 +944,7 @@ void GraphicsWindow::MouseLeftDown(double mx, double my) {
|
|||
hr = AddRequest(Request::CIRCLE);
|
||||
SS.GetEntity(hr.entity(1))->PointForceTo(v);
|
||||
SS.GetEntity(hr.entity(32))->NormalForceTo(
|
||||
Quaternion::MakeFrom(SS.GW.projRight, SS.GW.projUp));
|
||||
Quaternion::From(SS.GW.projRight, SS.GW.projUp));
|
||||
ConstrainPointByHovered(hr.entity(1));
|
||||
|
||||
ClearSuper();
|
||||
|
@ -993,7 +993,7 @@ void GraphicsWindow::MouseLeftDown(double mx, double my) {
|
|||
hr = AddRequest(Request::WORKPLANE);
|
||||
SS.GetEntity(hr.entity(1))->PointForceTo(v);
|
||||
SS.GetEntity(hr.entity(32))->NormalForceTo(
|
||||
Quaternion::MakeFrom(SS.GW.projRight, SS.GW.projUp));
|
||||
Quaternion::From(SS.GW.projRight, SS.GW.projUp));
|
||||
ConstrainPointByHovered(hr.entity(1));
|
||||
|
||||
ClearSuper();
|
||||
|
@ -1095,7 +1095,7 @@ void GraphicsWindow::MouseLeftDoubleClick(double mx, double my) {
|
|||
}
|
||||
|
||||
void GraphicsWindow::EditControlDone(char *s) {
|
||||
Expr *e = Expr::FromString(s);
|
||||
Expr *e = Expr::From(s);
|
||||
if(e) {
|
||||
Constraint *c = SS.GetConstraint(constraintBeingEdited);
|
||||
Expr::FreeKeep(&(c->exprA));
|
||||
|
|
4
mesh.cpp
4
mesh.cpp
|
@ -41,8 +41,8 @@ void SMesh::DoBounding(Vector v, Vector *vmax, Vector *vmin) {
|
|||
}
|
||||
void SMesh::GetBounding(Vector *vmax, Vector *vmin) {
|
||||
int i;
|
||||
*vmin = Vector::MakeFrom( 1e12, 1e12, 1e12);
|
||||
*vmax = Vector::MakeFrom(-1e12, -1e12, -1e12);
|
||||
*vmin = Vector::From( 1e12, 1e12, 1e12);
|
||||
*vmax = Vector::From(-1e12, -1e12, -1e12);
|
||||
for(i = 0; i < l.n; i++) {
|
||||
STriangle *st = &(l.elem[i]);
|
||||
DoBounding(st->a, vmax, vmin);
|
||||
|
|
|
@ -107,7 +107,7 @@ void SContour::MakeEdgesInto(SEdgeList *el) {
|
|||
}
|
||||
|
||||
Vector SContour::ComputeNormal(void) {
|
||||
Vector n = Vector::MakeFrom(0, 0, 0);
|
||||
Vector n = Vector::From(0, 0, 0);
|
||||
|
||||
for(int i = 0; i < l.n - 2; i++) {
|
||||
Vector u = (l.elem[i+1].p).Minus(l.elem[i+0].p).WithMagnitude(1);
|
||||
|
@ -212,7 +212,7 @@ void SPolygon::MakeEdgesInto(SEdgeList *el) {
|
|||
}
|
||||
|
||||
Vector SPolygon::ComputeNormal(void) {
|
||||
if(l.n < 1) return Vector::MakeFrom(0, 0, 0);
|
||||
if(l.n < 1) return Vector::From(0, 0, 0);
|
||||
return (l.elem[0]).ComputeNormal();
|
||||
}
|
||||
|
||||
|
|
34
sketch.cpp
34
sketch.cpp
|
@ -49,7 +49,7 @@ void Group::MenuGroup(int id) {
|
|||
v = v.Minus(u.ScaledBy(v.Dot(u)));
|
||||
v = v.ClosestOrtho();
|
||||
|
||||
g.predef.q = Quaternion::MakeFrom(u, v);
|
||||
g.predef.q = Quaternion::From(u, v);
|
||||
g.predef.origin = gs.point[0];
|
||||
} else if(gs.points == 1 && gs.lineSegments == 2 && gs.n == 3) {
|
||||
g.subtype = WORKPLANE_BY_LINE_SEGMENTS;
|
||||
|
@ -100,10 +100,10 @@ void Group::MenuGroup(int id) {
|
|||
return;
|
||||
}
|
||||
n = n.WithMagnitude(1);
|
||||
g.predef.q = Quaternion::MakeFrom(0, n.x, n.y, n.z);
|
||||
g.predef.q = Quaternion::From(0, n.x, n.y, n.z);
|
||||
g.type = ROTATE;
|
||||
g.opA = SS.GW.activeGroup;
|
||||
g.exprA = Expr::FromConstant(3)->DeepCopyKeep();
|
||||
g.exprA = Expr::From(3)->DeepCopyKeep();
|
||||
g.subtype = ONE_SIDED;
|
||||
g.name.strcpy("rotate");
|
||||
SS.GW.ClearSelection();
|
||||
|
@ -113,7 +113,7 @@ void Group::MenuGroup(int id) {
|
|||
case GraphicsWindow::MNU_GROUP_TRANS:
|
||||
g.type = TRANSLATE;
|
||||
g.opA = SS.GW.activeGroup;
|
||||
g.exprA = Expr::FromConstant(3)->DeepCopyKeep();
|
||||
g.exprA = Expr::From(3)->DeepCopyKeep();
|
||||
g.subtype = ONE_SIDED;
|
||||
g.name.strcpy("translate");
|
||||
break;
|
||||
|
@ -180,7 +180,7 @@ void Group::Generate(IdList<Entity,hEntity> *entity,
|
|||
if(predef.swapUV) SWAP(Vector, u, v);
|
||||
if(predef.negateU) u = u.ScaledBy(-1);
|
||||
if(predef.negateV) v = v.ScaledBy(-1);
|
||||
q = Quaternion::MakeFrom(u, v);
|
||||
q = Quaternion::From(u, v);
|
||||
} else if(subtype == WORKPLANE_BY_POINT_ORTHO) {
|
||||
// Already given, numerically.
|
||||
q = predef.q;
|
||||
|
@ -333,15 +333,15 @@ void Group::GenerateEquations(IdList<Equation,hEquation> *l) {
|
|||
if(type == IMPORTED) {
|
||||
// Normalize the quaternion
|
||||
ExprQuaternion q = {
|
||||
Expr::FromParam(h.param(3)),
|
||||
Expr::FromParam(h.param(4)),
|
||||
Expr::FromParam(h.param(5)),
|
||||
Expr::FromParam(h.param(6)) };
|
||||
AddEq(l, (q.Magnitude())->Minus(Expr::FromConstant(1)), 0);
|
||||
Expr::From(h.param(3)),
|
||||
Expr::From(h.param(4)),
|
||||
Expr::From(h.param(5)),
|
||||
Expr::From(h.param(6)) };
|
||||
AddEq(l, (q.Magnitude())->Minus(Expr::From(1)), 0);
|
||||
} else if(type == ROTATE) {
|
||||
// The axis and center of rotation are specified numerically
|
||||
#define EC(x) (Expr::FromConstant(x))
|
||||
#define EP(x) (Expr::FromParam(h.param(x)))
|
||||
#define EC(x) (Expr::From(x))
|
||||
#define EP(x) (Expr::From(h.param(x)))
|
||||
AddEq(l, (EC(predef.p.x))->Minus(EP(0)), 0);
|
||||
AddEq(l, (EC(predef.p.y))->Minus(EP(1)), 1);
|
||||
AddEq(l, (EC(predef.p.z))->Minus(EP(2)), 2);
|
||||
|
@ -357,9 +357,9 @@ void Group::GenerateEquations(IdList<Equation,hEquation> *l) {
|
|||
ExprVector u = w->Normal()->NormalExprsU();
|
||||
ExprVector v = w->Normal()->NormalExprsV();
|
||||
ExprVector extruden = {
|
||||
Expr::FromParam(h.param(0)),
|
||||
Expr::FromParam(h.param(1)),
|
||||
Expr::FromParam(h.param(2)) };
|
||||
Expr::From(h.param(0)),
|
||||
Expr::From(h.param(1)),
|
||||
Expr::From(h.param(2)) };
|
||||
|
||||
AddEq(l, u.Dot(extruden), 0);
|
||||
AddEq(l, v.Dot(extruden), 1);
|
||||
|
@ -561,14 +561,14 @@ void Group::MakePolygons(void) {
|
|||
} else if(type == EXTRUDE) {
|
||||
int i;
|
||||
Group *src = SS.GetGroup(opA);
|
||||
Vector translate = Vector::MakeFrom(
|
||||
Vector translate = Vector::From(
|
||||
SS.GetParam(h.param(0))->val,
|
||||
SS.GetParam(h.param(1))->val,
|
||||
SS.GetParam(h.param(2))->val
|
||||
);
|
||||
Vector tbot, ttop;
|
||||
if(subtype == ONE_SIDED) {
|
||||
tbot = Vector::MakeFrom(0, 0, 0); ttop = translate.ScaledBy(2);
|
||||
tbot = Vector::From(0, 0, 0); ttop = translate.ScaledBy(2);
|
||||
} else {
|
||||
tbot = translate.ScaledBy(-1); ttop = translate.ScaledBy(1);
|
||||
}
|
||||
|
|
|
@ -272,7 +272,7 @@ void SolveSpace::ForceReferences(void) {
|
|||
Entity *wrkpl = GetEntity(hr.entity(0));
|
||||
// The origin for our coordinate system, always zero
|
||||
Entity *origin = GetEntity(wrkpl->point[0]);
|
||||
origin->PointForceTo(Vector::MakeFrom(0, 0, 0));
|
||||
origin->PointForceTo(Vector::From(0, 0, 0));
|
||||
GetParam(origin->param[0])->known = true;
|
||||
GetParam(origin->param[1])->known = true;
|
||||
GetParam(origin->param[2])->known = true;
|
||||
|
|
|
@ -30,7 +30,7 @@ void System::WriteJacobian(int eqTag, int paramTag) {
|
|||
pd = pd->FoldConstants();
|
||||
pd = pd->DeepCopyWithParamsAsPointers(¶m, &(SS.param));
|
||||
} else {
|
||||
pd = Expr::FromConstant(0);
|
||||
pd = Expr::From(0.0);
|
||||
}
|
||||
mat.A.sym[i][j] = pd;
|
||||
}
|
||||
|
|
|
@ -702,7 +702,7 @@ void TextWindow::ShowConstraintInfo(void) {
|
|||
void TextWindow::EditControlDone(char *s) {
|
||||
switch(edit.meaning) {
|
||||
case EDIT_TIMES_REPEATED: {
|
||||
Expr *e = Expr::FromString(s);
|
||||
Expr *e = Expr::From(s);
|
||||
if(e) {
|
||||
Group *g = SS.GetGroup(edit.group);
|
||||
Expr::FreeKeep(&(g->exprA));
|
||||
|
|
18
util.cpp
18
util.cpp
|
@ -23,7 +23,7 @@ void MakeMatrix(double *mat, double a11, double a12, double a13, double a14,
|
|||
mat[15] = a44;
|
||||
}
|
||||
|
||||
Quaternion Quaternion::MakeFrom(double w, double vx, double vy, double vz) {
|
||||
Quaternion Quaternion::From(double w, double vx, double vy, double vz) {
|
||||
Quaternion q;
|
||||
q.w = w;
|
||||
q.vx = vx;
|
||||
|
@ -32,7 +32,7 @@ Quaternion Quaternion::MakeFrom(double w, double vx, double vy, double vz) {
|
|||
return q;
|
||||
}
|
||||
|
||||
Quaternion Quaternion::MakeFrom(Vector u, Vector v)
|
||||
Quaternion Quaternion::From(Vector u, Vector v)
|
||||
{
|
||||
Vector n = u.Cross(v);
|
||||
|
||||
|
@ -143,7 +143,7 @@ Quaternion Quaternion::Inverse(void) {
|
|||
|
||||
Quaternion Quaternion::ToThe(double p) {
|
||||
Quaternion r;
|
||||
Vector axis = Vector::MakeFrom(vx, vy, vz);
|
||||
Vector axis = Vector::From(vx, vy, vz);
|
||||
double theta = acos(w); // okay, since magnitude is 1, so -1 <= w <= 1
|
||||
theta *= p;
|
||||
r.w = cos(theta);
|
||||
|
@ -171,13 +171,13 @@ Quaternion Quaternion::Times(Quaternion b) {
|
|||
}
|
||||
|
||||
|
||||
Vector Vector::MakeFrom(double x, double y, double z) {
|
||||
Vector Vector::From(double x, double y, double z) {
|
||||
Vector v;
|
||||
v.x = x; v.y = y; v.z = z;
|
||||
return v;
|
||||
}
|
||||
|
||||
Vector Vector::MakeFrom(hParam x, hParam y, hParam z) {
|
||||
Vector Vector::From(hParam x, hParam y, hParam z) {
|
||||
Vector v;
|
||||
v.x = SS.GetParam(x)->val;
|
||||
v.y = SS.GetParam(y)->val;
|
||||
|
@ -308,7 +308,7 @@ Vector Vector::ScaledBy(double v) {
|
|||
Vector Vector::WithMagnitude(double v) {
|
||||
double m = Magnitude();
|
||||
if(m == 0) {
|
||||
return MakeFrom(v, 0, 0);
|
||||
return From(v, 0, 0);
|
||||
} else {
|
||||
return ScaledBy(v/m);
|
||||
}
|
||||
|
@ -357,11 +357,11 @@ Vector Vector::ClosestOrtho(void) {
|
|||
double m = max(fabs(x), max(fabs(y), fabs(z)));
|
||||
|
||||
if(m == fabs(x)) {
|
||||
return MakeFrom((x > 0) ? 1 : -1, 0, 0);
|
||||
return From((x > 0) ? 1 : -1, 0, 0);
|
||||
} else if(m == fabs(y)) {
|
||||
return MakeFrom(0, (y > 0) ? 1 : -1, 0);
|
||||
return From(0, (y > 0) ? 1 : -1, 0);
|
||||
} else if(m == fabs(z)) {
|
||||
return MakeFrom(0, 0, (z > 0) ? 1 : -1);
|
||||
return From(0, 0, (z > 0) ? 1 : -1);
|
||||
} else oops();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue