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]
This commit is contained in:
Jonathan Westhues 2008-06-01 00:45:11 -08:00
parent 709b5ad80e
commit 04af0944bc
15 changed files with 147 additions and 153 deletions

View File

@ -100,10 +100,10 @@ void Constraint::MenuConstrain(int id) {
c.disp.offset = n.Cross(a.Minus(b)); c.disp.offset = n.Cross(a.Minus(b));
c.disp.offset = (c.disp.offset).WithMagnitude(50/SS.GW.scale); c.disp.offset = (c.disp.offset).WithMagnitude(50/SS.GW.scale);
} else { } 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(); c.ModifyToSatisfy();
AddConstraint(&c); AddConstraint(&c);
break; break;
@ -159,7 +159,7 @@ void Constraint::MenuConstrain(int id) {
return; return;
} }
c.exprA = Expr::FromString("0")->DeepCopyKeep(); c.exprA = Expr::From("0")->DeepCopyKeep();
c.ModifyToSatisfy(); c.ModifyToSatisfy();
AddConstraint(&c); AddConstraint(&c);
break; break;
@ -282,7 +282,7 @@ void Constraint::MenuConstrain(int id) {
c.type = ANGLE; c.type = ANGLE;
c.entityA = gs.vector[0]; c.entityA = gs.vector[0];
c.entityB = gs.vector[1]; c.entityB = gs.vector[1];
c.exprA = Expr::FromConstant(0)->DeepCopyKeep(); c.exprA = Expr::From(0.0)->DeepCopyKeep();
c.otherAngle = true; c.otherAngle = true;
} else { } else {
Error("Bad selection for angle constraint."); Error("Bad selection for angle constraint.");
@ -440,7 +440,7 @@ void Constraint::ModifyToSatisfy(void) {
double c = (a.Dot(b))/(a.Magnitude() * b.Magnitude()); double c = (a.Dot(b))/(a.Magnitude() * b.Magnitude());
double theta = acos(c)*180/PI; double theta = acos(c)*180/PI;
Expr::FreeKeep(&exprA); Expr::FreeKeep(&exprA);
exprA = Expr::FromConstant(theta)->DeepCopyKeep(); exprA = Expr::From(theta)->DeepCopyKeep();
} else { } else {
// We'll fix these ones up by looking at their symbolic equation; // We'll fix these ones up by looking at their symbolic equation;
// that means no extra work. // that means no extra work.
@ -456,7 +456,7 @@ void Constraint::ModifyToSatisfy(void) {
double v = (l.elem[0].e)->Eval(); double v = (l.elem[0].e)->Eval();
double nd = exprA->Eval() + v; double nd = exprA->Eval() + v;
Expr::FreeKeep(&exprA); Expr::FreeKeep(&exprA);
exprA = Expr::FromConstant(nd)->DeepCopyKeep(); exprA = Expr::From(nd)->DeepCopyKeep();
l.Clear(); l.Clear();
} }
@ -509,7 +509,7 @@ void Constraint::Generate(IdList<Equation,hEquation> *l) {
case DIAMETER: { case DIAMETER: {
Entity *circle = SS.GetEntity(entityA); Entity *circle = SS.GetEntity(entityA);
Expr *r = circle->CircleGetRadiusExpr(); 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; break;
} }
@ -580,7 +580,7 @@ void Constraint::Generate(IdList<Equation,hEquation> *l) {
Entity *ln = SS.GetEntity(entityA); Entity *ln = SS.GetEntity(entityA);
ExprVector a = SS.GetEntity(ln->point[0])->PointGetExprs(); ExprVector a = SS.GetEntity(ln->point[0])->PointGetExprs();
ExprVector b = SS.GetEntity(ln->point[1])->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) { if(ptA.v) {
ExprVector p = SS.GetEntity(ptA)->PointGetExprs(); ExprVector p = SS.GetEntity(ptA)->PointGetExprs();
@ -598,8 +598,8 @@ void Constraint::Generate(IdList<Equation,hEquation> *l) {
Expr *au, *av, *bu, *bv; Expr *au, *av, *bu, *bv;
a->PointGetExprsInWorkplane(workplane, &au, &av); a->PointGetExprsInWorkplane(workplane, &au, &av);
b->PointGetExprsInWorkplane(workplane, &bu, &bv); b->PointGetExprsInWorkplane(workplane, &bu, &bv);
Expr *mu = Expr::FromConstant(0.5)->Times(au->Plus(bu)); Expr *mu = Expr::From(0.5)->Times(au->Plus(bu));
Expr *mv = Expr::FromConstant(0.5)->Times(av->Plus(bv)); Expr *mv = Expr::From(0.5)->Times(av->Plus(bv));
if(ptA.v) { if(ptA.v) {
Entity *p = SS.GetEntity(ptA); 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 // The midpoint of the line connecting the symmetric points
// lies on the plane of the symmetry. // 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); AddEq(l, PointPlaneDistance(m, plane->h), 0);
// And projected into the plane of symmetry, the points are // 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; Expr *au, *av, *bu, *bv;
a->PointGetExprsInWorkplane(workplane, &au, &av); a->PointGetExprsInWorkplane(workplane, &au, &av);
b->PointGetExprsInWorkplane(workplane, &bu, &bv); b->PointGetExprsInWorkplane(workplane, &bu, &bv);
Expr *mu = Expr::FromConstant(0.5)->Times(au->Plus(bu)); Expr *mu = Expr::From(0.5)->Times(au->Plus(bu));
Expr *mv = Expr::FromConstant(0.5)->Times(av->Plus(bv)); Expr *mv = Expr::From(0.5)->Times(av->Plus(bv));
ExprVector m = PointInThreeSpace(workplane, mu, mv); ExprVector m = PointInThreeSpace(workplane, mu, mv);
AddEq(l, PointPlaneDistance(m, plane->h), 0); AddEq(l, PointPlaneDistance(m, plane->h), 0);
@ -735,7 +735,7 @@ void Constraint::Generate(IdList<Equation,hEquation> *l) {
Entity *b = SS.GetEntity(entityB); Entity *b = SS.GetEntity(entityB);
ExprVector ae = a->VectorGetExprs(); ExprVector ae = a->VectorGetExprs();
ExprVector be = b->VectorGetExprs(); ExprVector be = b->VectorGetExprs();
if(otherAngle) ae = ae.ScaledBy(Expr::FromConstant(-1)); if(otherAngle) ae = ae.ScaledBy(Expr::From(-1));
Expr *c; Expr *c;
if(workplane.v == Entity::FREE_IN_3D.v) { if(workplane.v == Entity::FREE_IN_3D.v) {
Expr *mags = (ae.Magnitude())->Times(be.Magnitude()); 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)); Expr *dot = (ua->Times(ub))->Plus(va->Times(vb));
c = dot->Div(maga->Times(magb)); 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); AddEq(l, c->Minus(rads->Cos()), 0);
break; break;
} }

8
dsc.h
View File

@ -15,8 +15,8 @@ public:
// a + (vx)*i + (vy)*j + (vz)*k // a + (vx)*i + (vy)*j + (vz)*k
double w, vx, vy, vz; double w, vx, vy, vz;
static Quaternion MakeFrom(double w, double vx, double vy, double vz); static Quaternion From(double w, double vx, double vy, double vz);
static Quaternion MakeFrom(Vector u, Vector v); static Quaternion From(Vector u, Vector v);
Quaternion Plus(Quaternion b); Quaternion Plus(Quaternion b);
Quaternion Minus(Quaternion b); Quaternion Minus(Quaternion b);
@ -40,8 +40,8 @@ class Vector {
public: public:
double x, y, z; double x, y, z;
static Vector MakeFrom(double x, double y, double z); static Vector From(double x, double y, double z);
static Vector MakeFrom(hParam x, hParam y, hParam z); static Vector From(hParam x, hParam y, hParam z);
static Vector AtIntersectionOfPlanes(Vector n1, double d1, static Vector AtIntersectionOfPlanes(Vector n1, double d1,
Vector n2, double d2); Vector n2, double d2);

View File

@ -154,9 +154,9 @@ double Entity::DistanceGetNum(void) {
} }
Expr *Entity::DistanceGetExpr(void) { Expr *Entity::DistanceGetExpr(void) {
if(type == DISTANCE) { if(type == DISTANCE) {
return Expr::FromParam(param[0]); return Expr::From(param[0]);
} else if(type == DISTANCE_N_COPY) { } else if(type == DISTANCE_N_COPY) {
return Expr::FromConstant(numDistance); return Expr::From(numDistance);
} else oops(); } else oops();
} }
void Entity::DistanceForceTo(double v) { void Entity::DistanceForceTo(double v) {
@ -298,10 +298,10 @@ ExprQuaternion Entity::NormalGetExprs(void) {
ExprQuaternion q; ExprQuaternion q;
switch(type) { switch(type) {
case NORMAL_IN_3D: case NORMAL_IN_3D:
q.w = Expr::FromParam(param[0]); q.w = Expr::From(param[0]);
q.vx = Expr::FromParam(param[1]); q.vx = Expr::From(param[1]);
q.vy = Expr::FromParam(param[2]); q.vy = Expr::From(param[2]);
q.vz = Expr::FromParam(param[3]); q.vz = Expr::From(param[3]);
break; break;
case NORMAL_IN_2D: { case NORMAL_IN_2D: {
@ -311,34 +311,31 @@ ExprQuaternion Entity::NormalGetExprs(void) {
break; break;
} }
case NORMAL_N_COPY: case NORMAL_N_COPY:
q.w = Expr::FromConstant(numNormal.w); q = ExprQuaternion::From(numNormal);
q.vx = Expr::FromConstant(numNormal.vx);
q.vy = Expr::FromConstant(numNormal.vy);
q.vz = Expr::FromConstant(numNormal.vz);
break; break;
case NORMAL_N_ROT: { case NORMAL_N_ROT: {
ExprQuaternion orig = ExprQuaternion::FromNum(numNormal); ExprQuaternion orig = ExprQuaternion::From(numNormal);
q.w = Expr::FromParam(param[0]); q.w = Expr::From(param[0]);
q.vx = Expr::FromParam(param[1]); q.vx = Expr::From(param[1]);
q.vy = Expr::FromParam(param[2]); q.vy = Expr::From(param[2]);
q.vz = Expr::FromParam(param[3]); q.vz = Expr::From(param[3]);
q = q.Times(orig); q = q.Times(orig);
break; break;
} }
case NORMAL_N_ROT_AA: { case NORMAL_N_ROT_AA: {
ExprQuaternion orig = ExprQuaternion::FromNum(numNormal); ExprQuaternion orig = ExprQuaternion::From(numNormal);
Expr *theta = Expr::FromConstant(timesApplied)->Times( Expr *theta = Expr::From(timesApplied)->Times(
Expr::FromParam(param[0])); Expr::From(param[0]));
Expr *c = theta->Cos(), *s = theta->Sin(); Expr *c = theta->Cos(), *s = theta->Sin();
q.w = c; q.w = c;
q.vx = s->Times(Expr::FromParam(param[1])); q.vx = s->Times(Expr::From(param[1]));
q.vy = s->Times(Expr::FromParam(param[2])); q.vy = s->Times(Expr::From(param[2]));
q.vz = s->Times(Expr::FromParam(param[3])); q.vz = s->Times(Expr::From(param[3]));
q = q.Times(orig); q = q.Times(orig);
break; break;
@ -391,8 +388,8 @@ void Entity::PointForceTo(Vector p) {
case POINT_N_ROT_AA: { case POINT_N_ROT_AA: {
// Force only the angle; the axis and center of rotation stay // Force only the angle; the axis and center of rotation stay
Vector offset = Vector::MakeFrom(param[0], param[1], param[2]); Vector offset = Vector::From(param[0], param[1], param[2]);
Vector normal = Vector::MakeFrom(param[4], param[5], param[6]); Vector normal = Vector::From(param[4], param[5], param[6]);
Vector u = normal.Normal(0), v = normal.Normal(1); Vector u = normal.Normal(0), v = normal.Normal(1);
Vector po = p.Minus(offset), numo = numPoint.Minus(offset); Vector po = p.Minus(offset), numo = numPoint.Minus(offset);
double thetap = atan2(v.Dot(po), u.Dot(po)); double thetap = atan2(v.Dot(po), u.Dot(po));
@ -444,7 +441,7 @@ Vector Entity::PointGetNum(void) {
} }
case POINT_N_ROT_TRANS: { case POINT_N_ROT_TRANS: {
Vector offset = Vector::MakeFrom( Vector offset = Vector::From(
SS.GetParam(param[0])->val, SS.GetParam(param[0])->val,
SS.GetParam(param[1])->val, SS.GetParam(param[1])->val,
SS.GetParam(param[2])->val); SS.GetParam(param[2])->val);
@ -455,7 +452,7 @@ Vector Entity::PointGetNum(void) {
} }
case POINT_N_ROT_AA: { case POINT_N_ROT_AA: {
Vector offset = Vector::MakeFrom( Vector offset = Vector::From(
SS.GetParam(param[0])->val, SS.GetParam(param[0])->val,
SS.GetParam(param[1])->val, SS.GetParam(param[1])->val,
SS.GetParam(param[2])->val); SS.GetParam(param[2])->val);
@ -479,9 +476,9 @@ ExprVector Entity::PointGetExprs(void) {
ExprVector r; ExprVector r;
switch(type) { switch(type) {
case POINT_IN_3D: case POINT_IN_3D:
r.x = Expr::FromParam(param[0]); r.x = Expr::From(param[0]);
r.y = Expr::FromParam(param[1]); r.y = Expr::From(param[1]);
r.z = Expr::FromParam(param[2]); r.z = Expr::From(param[2]);
break; break;
case POINT_IN_2D: { case POINT_IN_2D: {
@ -489,56 +486,53 @@ ExprVector Entity::PointGetExprs(void) {
ExprVector u = c->Normal()->NormalExprsU(); ExprVector u = c->Normal()->NormalExprsU();
ExprVector v = c->Normal()->NormalExprsV(); ExprVector v = c->Normal()->NormalExprsV();
r = c->WorkplaneGetOffsetExprs(); r = c->WorkplaneGetOffsetExprs();
r = r.Plus(u.ScaledBy(Expr::FromParam(param[0]))); r = r.Plus(u.ScaledBy(Expr::From(param[0])));
r = r.Plus(v.ScaledBy(Expr::FromParam(param[1]))); r = r.Plus(v.ScaledBy(Expr::From(param[1])));
break; break;
} }
case POINT_N_TRANS: { case POINT_N_TRANS: {
ExprVector orig = { ExprVector orig = {
Expr::FromConstant(numPoint.x), Expr::From(numPoint.x),
Expr::FromConstant(numPoint.y), Expr::From(numPoint.y),
Expr::FromConstant(numPoint.z) }; Expr::From(numPoint.z) };
ExprVector trans; ExprVector trans;
trans.x = Expr::FromParam(param[0]); trans.x = Expr::From(param[0]);
trans.y = Expr::FromParam(param[1]); trans.y = Expr::From(param[1]);
trans.z = Expr::FromParam(param[2]); trans.z = Expr::From(param[2]);
r = orig.Plus(trans.ScaledBy(Expr::FromConstant(timesApplied))); r = orig.Plus(trans.ScaledBy(Expr::From(timesApplied)));
break; break;
} }
case POINT_N_ROT_TRANS: { case POINT_N_ROT_TRANS: {
ExprVector orig = ExprVector::FromNum(numPoint); ExprVector orig = ExprVector::From(numPoint);
ExprVector trans = ExprVector trans =
ExprVector::FromParams(param[0], param[1], param[2]); ExprVector::From(param[0], param[1], param[2]);
ExprQuaternion q = { ExprQuaternion q = {
Expr::FromParam(param[3]), Expr::From(param[3]),
Expr::FromParam(param[4]), Expr::From(param[4]),
Expr::FromParam(param[5]), Expr::From(param[5]),
Expr::FromParam(param[6]) }; Expr::From(param[6]) };
orig = q.Rotate(orig); orig = q.Rotate(orig);
r = orig.Plus(trans); r = orig.Plus(trans);
break; break;
} }
case POINT_N_ROT_AA: { case POINT_N_ROT_AA: {
ExprVector orig = ExprVector::FromNum(numPoint); ExprVector orig = ExprVector::From(numPoint);
ExprVector trans = ExprVector trans = ExprVector::From(param[0], param[1], param[2]);
ExprVector::FromParams(param[0], param[1], param[2]); Expr *theta = Expr::From(timesApplied)->Times(
Expr *theta = Expr::FromConstant(timesApplied)->Times( Expr::From(param[3]));
Expr::FromParam(param[3]));
Expr *c = theta->Cos(), *s = theta->Sin(); Expr *c = theta->Cos(), *s = theta->Sin();
ExprQuaternion q = { ExprQuaternion q = {
c, c,
s->Times(Expr::FromParam(param[4])), s->Times(Expr::From(param[4])),
s->Times(Expr::FromParam(param[5])), s->Times(Expr::From(param[5])),
s->Times(Expr::FromParam(param[6])) }; s->Times(Expr::From(param[6])) };
orig = orig.Minus(trans); orig = orig.Minus(trans);
orig = q.Rotate(orig); orig = q.Rotate(orig);
r = orig.Plus(trans); r = orig.Plus(trans);
break; break;
} }
case POINT_N_COPY: case POINT_N_COPY:
r.x = Expr::FromConstant(numPoint.x); r = ExprVector::From(numPoint);
r.y = Expr::FromConstant(numPoint.y);
r.z = Expr::FromConstant(numPoint.z);
break; break;
default: oops(); default: oops();
@ -550,8 +544,8 @@ void Entity::PointGetExprsInWorkplane(hEntity wrkpl, Expr **u, Expr **v) {
if(type == POINT_IN_2D && workplane.v == wrkpl.v) { if(type == POINT_IN_2D && workplane.v == wrkpl.v) {
// They want our coordinates in the form that we've written them, // They want our coordinates in the form that we've written them,
// very nice. // very nice.
*u = Expr::FromParam(param[0]); *u = Expr::From(param[0]);
*v = Expr::FromParam(param[1]); *v = Expr::From(param[1]);
} else { } else {
// Get the offset and basis vectors for this weird exotic csys. // Get the offset and basis vectors for this weird exotic csys.
Entity *w = SS.GetEntity(wrkpl); Entity *w = SS.GetEntity(wrkpl);
@ -931,7 +925,7 @@ void Entity::GenerateEquations(IdList<Equation,hEquation> *l) {
switch(type) { switch(type) {
case NORMAL_IN_3D: { case NORMAL_IN_3D: {
ExprQuaternion q = NormalGetExprs(); ExprQuaternion q = NormalGetExprs();
AddEq(l, (q.Magnitude())->Minus(Expr::FromConstant(1)), 0); AddEq(l, (q.Magnitude())->Minus(Expr::From(1)), 0);
break; break;
} }
case ARC_OF_CIRCLE: { case ARC_OF_CIRCLE: {

View File

@ -1,23 +1,23 @@
#include "solvespace.h" #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}; ExprVector r = { x, y, z};
return r; return r;
} }
ExprVector ExprVector::FromNum(Vector vn) { ExprVector ExprVector::From(Vector vn) {
ExprVector ve; ExprVector ve;
ve.x = Expr::FromConstant(vn.x); ve.x = Expr::From(vn.x);
ve.y = Expr::FromConstant(vn.y); ve.y = Expr::From(vn.y);
ve.z = Expr::FromConstant(vn.z); ve.z = Expr::From(vn.z);
return ve; return ve;
} }
ExprVector ExprVector::FromParams(hParam x, hParam y, hParam z) { ExprVector ExprVector::From(hParam x, hParam y, hParam z) {
ExprVector ve; ExprVector ve;
ve.x = Expr::FromParam(x); ve.x = Expr::From(x);
ve.y = Expr::FromParam(y); ve.y = Expr::From(y);
ve.z = Expr::FromParam(z); ve.z = Expr::From(z);
return ve; return ve;
} }
@ -77,7 +77,7 @@ Vector ExprVector::Eval(void) {
return r; 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; ExprQuaternion q;
q.w = w; q.w = w;
@ -87,18 +87,18 @@ ExprQuaternion ExprQuaternion::FromExprs(Expr *w, Expr *vx, Expr *vy, Expr *vz)
return q; return q;
} }
ExprQuaternion ExprQuaternion::FromNum(Quaternion qn) { ExprQuaternion ExprQuaternion::From(Quaternion qn) {
ExprQuaternion qe; ExprQuaternion qe;
qe.w = Expr::FromConstant(qn.w); qe.w = Expr::From(qn.w);
qe.vx = Expr::FromConstant(qn.vx); qe.vx = Expr::From(qn.vx);
qe.vy = Expr::FromConstant(qn.vy); qe.vy = Expr::From(qn.vy);
qe.vz = Expr::FromConstant(qn.vz); qe.vz = Expr::From(qn.vz);
return qe; return qe;
} }
ExprVector ExprQuaternion::RotationU(void) { ExprVector ExprQuaternion::RotationU(void) {
ExprVector u; ExprVector u;
Expr *two = Expr::FromConstant(2); Expr *two = Expr::From(2);
u.x = w->Square(); u.x = w->Square();
u.x = (u.x)->Plus(vx->Square()); u.x = (u.x)->Plus(vx->Square());
@ -116,7 +116,7 @@ ExprVector ExprQuaternion::RotationU(void) {
ExprVector ExprQuaternion::RotationV(void) { ExprVector ExprQuaternion::RotationV(void) {
ExprVector v; ExprVector v;
Expr *two = Expr::FromConstant(2); Expr *two = Expr::From(2);
v.x = two->Times(vx->Times(vy)); v.x = two->Times(vx->Times(vy));
v.x = (v.x)->Minus(two->Times(w->Times(vz))); v.x = (v.x)->Minus(two->Times(w->Times(vz)));
@ -134,7 +134,7 @@ ExprVector ExprQuaternion::RotationV(void) {
ExprVector ExprQuaternion::RotationN(void) { ExprVector ExprQuaternion::RotationN(void) {
ExprVector n; ExprVector n;
Expr *two = Expr::FromConstant(2); Expr *two = Expr::From(2);
n.x = two->Times( w->Times(vy)); n.x = two->Times( w->Times(vy));
n.x = (n.x)->Plus (two->Times(vx->Times(vz))); 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(); Expr *r = AllocExpr();
r->op = PARAM; r->op = PARAM;
r->x.parh = p; r->x.parh = p;
return r; return r;
} }
Expr *Expr::FromConstant(double v) { Expr *Expr::From(double v) {
Expr *r = AllocExpr(); Expr *r = AllocExpr();
r->op = CONSTANT; r->op = CONSTANT;
r->x.v = v; r->x.v = v;
@ -312,10 +312,10 @@ Expr *Expr::PartialWrt(hParam p) {
Expr *da, *db; Expr *da, *db;
switch(op) { switch(op) {
case PARAM_PTR: return FromConstant(p.v == x.parp->h.v ? 1 : 0); case PARAM_PTR: return From(p.v == x.parp->h.v ? 1 : 0);
case PARAM: return FromConstant(p.v == x.parh.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 PLUS: return (a->PartialWrt(p))->Plus(b->PartialWrt(p));
case MINUS: return (a->PartialWrt(p))->Minus(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()); return ((da->Times(b))->Minus(a->Times(db)))->Div(b->Square());
case SQRT: 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: 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 NEGATE: return (a->PartialWrt(p))->Negate();
case SIN: return (a->Cos())->Times(a->PartialWrt(p)); 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; UnparsedCnt = 0;
UnparsedP = 0; UnparsedP = 0;
OperandsP = 0; OperandsP = 0;

16
expr.h
View File

@ -56,8 +56,8 @@ public:
static inline Expr *AllocExpr(void) static inline Expr *AllocExpr(void)
{ return (Expr *)AllocTemporary(sizeof(Expr)); } { return (Expr *)AllocTemporary(sizeof(Expr)); }
static Expr *FromParam(hParam p); static Expr *From(hParam p);
static Expr *FromConstant(double v); static Expr *From(double v);
Expr *AnyOp(int op, Expr *b); Expr *AnyOp(int op, Expr *b);
inline Expr *Plus (Expr *b) { return AnyOp(PLUS, b); } inline Expr *Plus (Expr *b) { return AnyOp(PLUS, b); }
@ -99,7 +99,7 @@ public:
Expr *DeepCopyWithParamsAsPointers(IdList<Param,hParam> *firstTry, Expr *DeepCopyWithParamsAsPointers(IdList<Param,hParam> *firstTry,
IdList<Param,hParam> *thenTry); IdList<Param,hParam> *thenTry);
static Expr *FromString(char *in); static Expr *From(char *in);
static void Lex(char *in); static void Lex(char *in);
static Expr *Next(void); static Expr *Next(void);
static void Consume(void); static void Consume(void);
@ -122,9 +122,9 @@ class ExprVector {
public: public:
Expr *x, *y, *z; Expr *x, *y, *z;
static ExprVector FromExprs(Expr *x, Expr *y, Expr *z); static ExprVector From(Expr *x, Expr *y, Expr *z);
static ExprVector FromNum(Vector vn); static ExprVector From(Vector vn);
static ExprVector FromParams(hParam x, hParam y, hParam z); static ExprVector From(hParam x, hParam y, hParam z);
ExprVector Plus(ExprVector b); ExprVector Plus(ExprVector b);
ExprVector Minus(ExprVector b); ExprVector Minus(ExprVector b);
@ -140,8 +140,8 @@ class ExprQuaternion {
public: public:
Expr *w, *vx, *vy, *vz; Expr *w, *vx, *vy, *vz;
static ExprQuaternion FromExprs(Expr *w, Expr *vx, Expr *vy, Expr *vz); static ExprQuaternion From(Expr *w, Expr *vx, Expr *vy, Expr *vz);
static ExprQuaternion FromNum(Quaternion qn); static ExprQuaternion From(Quaternion qn);
ExprVector RotationU(void); ExprVector RotationU(void);
ExprVector RotationV(void); ExprVector RotationV(void);

View File

@ -42,7 +42,7 @@ void SolveSpace::NewFile(void) {
// And an empty group, for the first stuff the user draws. // And an empty group, for the first stuff the user draws.
g.type = Group::DRAWING_WORKPLANE; g.type = Group::DRAWING_WORKPLANE;
g.subtype = Group::WORKPLANE_BY_POINT_ORTHO; 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; hRequest hr = Request::HREQUEST_REFERENCE_XY;
g.predef.origin = hr.entity(1); g.predef.origin = hr.entity(1);
g.name.strcpy("draw-in-plane"); 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 'N': ((NameStr *)p)->strcpy(val); break;
case 'E': case 'E':
Expr *e; Expr *e;
e = Expr::FromString(val); e = Expr::From(val);
if(!e) e = Expr::FromConstant(0); if(!e) e = Expr::From(0.0);
*((Expr **)p) = e->DeepCopyKeep(); *((Expr **)p) = e->DeepCopyKeep();
break; break;

View File

@ -269,7 +269,7 @@ void glxDebugMesh(SMesh *m)
void glxMarkPolygonNormal(SPolygon *p) void glxMarkPolygonNormal(SPolygon *p)
{ {
Vector tail = Vector::MakeFrom(0, 0, 0); Vector tail = Vector::From(0, 0, 0);
int i, j, cnt = 0; int i, j, cnt = 0;
// Choose some reasonable center point. // Choose some reasonable center point.
for(i = 0; i < p->l.n; i++) { for(i = 0; i < p->l.n; i++) {

View File

@ -150,7 +150,7 @@ void GraphicsWindow::AnimateOntoWorkplane(void) {
Vector offsetf = (SS.GetEntity(w->point[0])->PointGetNum()).ScaledBy(-1); Vector offsetf = (SS.GetEntity(w->point[0])->PointGetNum()).ScaledBy(-1);
// Get our initial orientation and translation. // Get our initial orientation and translation.
Quaternion quat0 = Quaternion::MakeFrom(projRight, projUp); Quaternion quat0 = Quaternion::From(projRight, projUp);
Vector offset0 = offset; Vector offset0 = offset;
// Make sure we take the shorter of the two possible paths. // 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.projUp, -s*dx);
v = v.RotatedAbout(orig.projRight, s*dy); v = v.RotatedAbout(orig.projRight, s*dy);
} }
q = Quaternion::MakeFrom(u, v); q = Quaternion::From(u, v);
p->PointForceQuaternionTo(q); p->PointForceQuaternionTo(q);
// Let's rotate about the selected point; so fix up the // Let's rotate about the selected point; so fix up the
// translation so that that point didn't move. // 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); v = v.RotatedAbout(orig.projRight, s*dy);
} }
orig.mouse = mp; orig.mouse = mp;
normal->NormalForceTo(Quaternion::MakeFrom(u, v)); normal->NormalForceTo(Quaternion::From(u, v));
break; break;
} }
@ -944,7 +944,7 @@ void GraphicsWindow::MouseLeftDown(double mx, double my) {
hr = AddRequest(Request::CIRCLE); hr = AddRequest(Request::CIRCLE);
SS.GetEntity(hr.entity(1))->PointForceTo(v); SS.GetEntity(hr.entity(1))->PointForceTo(v);
SS.GetEntity(hr.entity(32))->NormalForceTo( 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)); ConstrainPointByHovered(hr.entity(1));
ClearSuper(); ClearSuper();
@ -993,7 +993,7 @@ void GraphicsWindow::MouseLeftDown(double mx, double my) {
hr = AddRequest(Request::WORKPLANE); hr = AddRequest(Request::WORKPLANE);
SS.GetEntity(hr.entity(1))->PointForceTo(v); SS.GetEntity(hr.entity(1))->PointForceTo(v);
SS.GetEntity(hr.entity(32))->NormalForceTo( 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)); ConstrainPointByHovered(hr.entity(1));
ClearSuper(); ClearSuper();
@ -1095,7 +1095,7 @@ void GraphicsWindow::MouseLeftDoubleClick(double mx, double my) {
} }
void GraphicsWindow::EditControlDone(char *s) { void GraphicsWindow::EditControlDone(char *s) {
Expr *e = Expr::FromString(s); Expr *e = Expr::From(s);
if(e) { if(e) {
Constraint *c = SS.GetConstraint(constraintBeingEdited); Constraint *c = SS.GetConstraint(constraintBeingEdited);
Expr::FreeKeep(&(c->exprA)); Expr::FreeKeep(&(c->exprA));

View File

@ -41,8 +41,8 @@ void SMesh::DoBounding(Vector v, Vector *vmax, Vector *vmin) {
} }
void SMesh::GetBounding(Vector *vmax, Vector *vmin) { void SMesh::GetBounding(Vector *vmax, Vector *vmin) {
int i; int i;
*vmin = Vector::MakeFrom( 1e12, 1e12, 1e12); *vmin = Vector::From( 1e12, 1e12, 1e12);
*vmax = Vector::MakeFrom(-1e12, -1e12, -1e12); *vmax = Vector::From(-1e12, -1e12, -1e12);
for(i = 0; i < l.n; i++) { for(i = 0; i < l.n; i++) {
STriangle *st = &(l.elem[i]); STriangle *st = &(l.elem[i]);
DoBounding(st->a, vmax, vmin); DoBounding(st->a, vmax, vmin);

View File

@ -107,7 +107,7 @@ void SContour::MakeEdgesInto(SEdgeList *el) {
} }
Vector SContour::ComputeNormal(void) { 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++) { for(int i = 0; i < l.n - 2; i++) {
Vector u = (l.elem[i+1].p).Minus(l.elem[i+0].p).WithMagnitude(1); 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) { 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(); return (l.elem[0]).ComputeNormal();
} }

View File

@ -49,7 +49,7 @@ void Group::MenuGroup(int id) {
v = v.Minus(u.ScaledBy(v.Dot(u))); v = v.Minus(u.ScaledBy(v.Dot(u)));
v = v.ClosestOrtho(); v = v.ClosestOrtho();
g.predef.q = Quaternion::MakeFrom(u, v); g.predef.q = Quaternion::From(u, v);
g.predef.origin = gs.point[0]; g.predef.origin = gs.point[0];
} else if(gs.points == 1 && gs.lineSegments == 2 && gs.n == 3) { } else if(gs.points == 1 && gs.lineSegments == 2 && gs.n == 3) {
g.subtype = WORKPLANE_BY_LINE_SEGMENTS; g.subtype = WORKPLANE_BY_LINE_SEGMENTS;
@ -100,10 +100,10 @@ void Group::MenuGroup(int id) {
return; return;
} }
n = n.WithMagnitude(1); 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.type = ROTATE;
g.opA = SS.GW.activeGroup; g.opA = SS.GW.activeGroup;
g.exprA = Expr::FromConstant(3)->DeepCopyKeep(); g.exprA = Expr::From(3)->DeepCopyKeep();
g.subtype = ONE_SIDED; g.subtype = ONE_SIDED;
g.name.strcpy("rotate"); g.name.strcpy("rotate");
SS.GW.ClearSelection(); SS.GW.ClearSelection();
@ -113,7 +113,7 @@ void Group::MenuGroup(int id) {
case GraphicsWindow::MNU_GROUP_TRANS: case GraphicsWindow::MNU_GROUP_TRANS:
g.type = TRANSLATE; g.type = TRANSLATE;
g.opA = SS.GW.activeGroup; g.opA = SS.GW.activeGroup;
g.exprA = Expr::FromConstant(3)->DeepCopyKeep(); g.exprA = Expr::From(3)->DeepCopyKeep();
g.subtype = ONE_SIDED; g.subtype = ONE_SIDED;
g.name.strcpy("translate"); g.name.strcpy("translate");
break; break;
@ -180,7 +180,7 @@ void Group::Generate(IdList<Entity,hEntity> *entity,
if(predef.swapUV) SWAP(Vector, u, v); if(predef.swapUV) SWAP(Vector, u, v);
if(predef.negateU) u = u.ScaledBy(-1); if(predef.negateU) u = u.ScaledBy(-1);
if(predef.negateV) v = v.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) { } else if(subtype == WORKPLANE_BY_POINT_ORTHO) {
// Already given, numerically. // Already given, numerically.
q = predef.q; q = predef.q;
@ -333,15 +333,15 @@ void Group::GenerateEquations(IdList<Equation,hEquation> *l) {
if(type == IMPORTED) { if(type == IMPORTED) {
// Normalize the quaternion // Normalize the quaternion
ExprQuaternion q = { ExprQuaternion q = {
Expr::FromParam(h.param(3)), Expr::From(h.param(3)),
Expr::FromParam(h.param(4)), Expr::From(h.param(4)),
Expr::FromParam(h.param(5)), Expr::From(h.param(5)),
Expr::FromParam(h.param(6)) }; Expr::From(h.param(6)) };
AddEq(l, (q.Magnitude())->Minus(Expr::FromConstant(1)), 0); AddEq(l, (q.Magnitude())->Minus(Expr::From(1)), 0);
} else if(type == ROTATE) { } else if(type == ROTATE) {
// The axis and center of rotation are specified numerically // The axis and center of rotation are specified numerically
#define EC(x) (Expr::FromConstant(x)) #define EC(x) (Expr::From(x))
#define EP(x) (Expr::FromParam(h.param(x))) #define EP(x) (Expr::From(h.param(x)))
AddEq(l, (EC(predef.p.x))->Minus(EP(0)), 0); 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.y))->Minus(EP(1)), 1);
AddEq(l, (EC(predef.p.z))->Minus(EP(2)), 2); 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 u = w->Normal()->NormalExprsU();
ExprVector v = w->Normal()->NormalExprsV(); ExprVector v = w->Normal()->NormalExprsV();
ExprVector extruden = { ExprVector extruden = {
Expr::FromParam(h.param(0)), Expr::From(h.param(0)),
Expr::FromParam(h.param(1)), Expr::From(h.param(1)),
Expr::FromParam(h.param(2)) }; Expr::From(h.param(2)) };
AddEq(l, u.Dot(extruden), 0); AddEq(l, u.Dot(extruden), 0);
AddEq(l, v.Dot(extruden), 1); AddEq(l, v.Dot(extruden), 1);
@ -561,14 +561,14 @@ void Group::MakePolygons(void) {
} else if(type == EXTRUDE) { } else if(type == EXTRUDE) {
int i; int i;
Group *src = SS.GetGroup(opA); Group *src = SS.GetGroup(opA);
Vector translate = Vector::MakeFrom( Vector translate = Vector::From(
SS.GetParam(h.param(0))->val, SS.GetParam(h.param(0))->val,
SS.GetParam(h.param(1))->val, SS.GetParam(h.param(1))->val,
SS.GetParam(h.param(2))->val SS.GetParam(h.param(2))->val
); );
Vector tbot, ttop; Vector tbot, ttop;
if(subtype == ONE_SIDED) { 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 { } else {
tbot = translate.ScaledBy(-1); ttop = translate.ScaledBy(1); tbot = translate.ScaledBy(-1); ttop = translate.ScaledBy(1);
} }

View File

@ -272,7 +272,7 @@ void SolveSpace::ForceReferences(void) {
Entity *wrkpl = GetEntity(hr.entity(0)); Entity *wrkpl = GetEntity(hr.entity(0));
// The origin for our coordinate system, always zero // The origin for our coordinate system, always zero
Entity *origin = GetEntity(wrkpl->point[0]); 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[0])->known = true;
GetParam(origin->param[1])->known = true; GetParam(origin->param[1])->known = true;
GetParam(origin->param[2])->known = true; GetParam(origin->param[2])->known = true;

View File

@ -30,7 +30,7 @@ void System::WriteJacobian(int eqTag, int paramTag) {
pd = pd->FoldConstants(); pd = pd->FoldConstants();
pd = pd->DeepCopyWithParamsAsPointers(&param, &(SS.param)); pd = pd->DeepCopyWithParamsAsPointers(&param, &(SS.param));
} else { } else {
pd = Expr::FromConstant(0); pd = Expr::From(0.0);
} }
mat.A.sym[i][j] = pd; mat.A.sym[i][j] = pd;
} }

View File

@ -702,7 +702,7 @@ void TextWindow::ShowConstraintInfo(void) {
void TextWindow::EditControlDone(char *s) { void TextWindow::EditControlDone(char *s) {
switch(edit.meaning) { switch(edit.meaning) {
case EDIT_TIMES_REPEATED: { case EDIT_TIMES_REPEATED: {
Expr *e = Expr::FromString(s); Expr *e = Expr::From(s);
if(e) { if(e) {
Group *g = SS.GetGroup(edit.group); Group *g = SS.GetGroup(edit.group);
Expr::FreeKeep(&(g->exprA)); Expr::FreeKeep(&(g->exprA));

View File

@ -23,7 +23,7 @@ void MakeMatrix(double *mat, double a11, double a12, double a13, double a14,
mat[15] = a44; 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; Quaternion q;
q.w = w; q.w = w;
q.vx = vx; q.vx = vx;
@ -32,7 +32,7 @@ Quaternion Quaternion::MakeFrom(double w, double vx, double vy, double vz) {
return q; return q;
} }
Quaternion Quaternion::MakeFrom(Vector u, Vector v) Quaternion Quaternion::From(Vector u, Vector v)
{ {
Vector n = u.Cross(v); Vector n = u.Cross(v);
@ -143,7 +143,7 @@ Quaternion Quaternion::Inverse(void) {
Quaternion Quaternion::ToThe(double p) { Quaternion Quaternion::ToThe(double p) {
Quaternion r; 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 double theta = acos(w); // okay, since magnitude is 1, so -1 <= w <= 1
theta *= p; theta *= p;
r.w = cos(theta); 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; Vector v;
v.x = x; v.y = y; v.z = z; v.x = x; v.y = y; v.z = z;
return v; return v;
} }
Vector Vector::MakeFrom(hParam x, hParam y, hParam z) { Vector Vector::From(hParam x, hParam y, hParam z) {
Vector v; Vector v;
v.x = SS.GetParam(x)->val; v.x = SS.GetParam(x)->val;
v.y = SS.GetParam(y)->val; v.y = SS.GetParam(y)->val;
@ -308,7 +308,7 @@ Vector Vector::ScaledBy(double v) {
Vector Vector::WithMagnitude(double v) { Vector Vector::WithMagnitude(double v) {
double m = Magnitude(); double m = Magnitude();
if(m == 0) { if(m == 0) {
return MakeFrom(v, 0, 0); return From(v, 0, 0);
} else { } else {
return ScaledBy(v/m); return ScaledBy(v/m);
} }
@ -357,11 +357,11 @@ Vector Vector::ClosestOrtho(void) {
double m = max(fabs(x), max(fabs(y), fabs(z))); double m = max(fabs(x), max(fabs(y), fabs(z)));
if(m == fabs(x)) { 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)) { } 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)) { } else if(m == fabs(z)) {
return MakeFrom(0, 0, (z > 0) ? 1 : -1); return From(0, 0, (z > 0) ? 1 : -1);
} else oops(); } else oops();
} }