Skip to content

Commit 81782ee

Browse files
committed
NFC: Remove Vector::From and replace it with aggregate initialization {}
...in all places where it is possible. The 34 remaining places either initialize a vector from handles or call a method of the resulting vector object. For example `Vector::From(x, y, z).WithMagnitude(1.0)`
1 parent 5b2e41d commit 81782ee

38 files changed

Lines changed: 204 additions & 204 deletions

src/clipboard.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ void GraphicsWindow::PasteClipboard(Vector trans, double theta, double scale) {
209209
// Likewise the scale, which could otherwise take us out of the
210210
// workplane.
211211
pt = pt.ScaledBy(fabs(scale));
212-
pt = pt.ScaleOutOfCsys(u, v, Vector::From(0, 0, 0));
212+
pt = pt.ScaleOutOfCsys(u, v, {}/*{0, 0, 0}*/);
213213
pt = pt.Plus(p);
214214
pt = pt.RotatedAbout(n, theta);
215215
pt = pt.Plus(trans);
@@ -338,7 +338,7 @@ void GraphicsWindow::MenuClipboard(Command id) {
338338
Entity *wrkpl = SK.GetEntity(SS.GW.ActiveWorkplane());
339339
Vector p = SK.GetEntity(wrkpl->point[0])->PointGetNum();
340340
SS.TW.shown.paste.times = 1;
341-
SS.TW.shown.paste.trans = Vector::From(0, 0, 0);
341+
SS.TW.shown.paste.trans = {}; // {0, 0, 0}
342342
SS.TW.shown.paste.theta = 0;
343343
SS.TW.shown.paste.origin = p;
344344
SS.TW.shown.paste.scale = 1;

src/confscreen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void TextWindow::ScreenChangeTurntableNav(int link, uint32_t v) {
9898
SS.turntableNav = !SS.turntableNav;
9999
if(SS.turntableNav) {
100100
// If turntable nav is being turned on, align view so Z is vertical
101-
SS.GW.AnimateOnto(Quaternion::From(Vector::From(-1, 0, 0), Vector::From(0, 0, 1)),
101+
SS.GW.AnimateOnto(Quaternion::From({-1, 0, 0}, {0, 0, 1}),
102102
SS.GW.offset);
103103
}
104104
}
@@ -406,7 +406,7 @@ bool TextWindow::EditControlDoneForConfiguration(const std::string &s) {
406406
case Edit::LIGHT_DIRECTION: {
407407
double x, y, z;
408408
if(sscanf(s.c_str(), "%lf, %lf, %lf", &x, &y, &z)==3) {
409-
SS.lightDir[edit.i] = Vector::From(x, y, z);
409+
SS.lightDir[edit.i] = {x, y, z};
410410
SS.GW.Invalidate();
411411
} else {
412412
Error(_("Bad format: specify coordinates as x, y, z"));

src/constraint.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ void Constraint::MenuConstrain(Command id) {
320320
c.disp.offset = n.Cross(a.Minus(b));
321321
c.disp.offset = (c.disp.offset).WithMagnitude(50/SS.GW.scale);
322322
} else {
323-
c.disp.offset = Vector::From(0, 0, 0);
323+
c.disp.offset = {}; // {0, 0, 0}
324324
}
325325

326326
if(id == Command::REF_DISTANCE) {

src/constrainteq.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ void ConstraintBase::GenerateEquations(IdList<Equation,hEquation> *l,
10231023
} else {
10241024
// We use expressions written in workplane csys, so we can assume the workplane
10251025
// normal is (0, 0, 1). We can write the equation as:
1026-
// Expr *eq = a.Cross(b).Dot(ExprVector::From(0.0, 0.0, 1.0));
1026+
// Expr *eq = a.Cross(b).Dot(Expr{0.0, 0.0, 1.0});
10271027
// but this will just result in elimination of x and y terms after dot product.
10281028
// We can only use the z expression:
10291029
// Expr *eq = a.Cross(b).z;

src/draw.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ void GraphicsWindow::MakeSelected(Selection *stog) {
211211
//-----------------------------------------------------------------------------
212212
void GraphicsWindow::SelectByMarquee() {
213213
Point2d marqueePoint = ProjectPoint(orig.marqueePoint);
214-
BBox marqueeBBox = BBox::From(Vector::From(marqueePoint.x, marqueePoint.y, VERY_NEGATIVE),
215-
Vector::From(orig.mouse.x, orig.mouse.y, VERY_POSITIVE));
214+
BBox marqueeBBox = BBox::From({marqueePoint.x, marqueePoint.y, VERY_NEGATIVE},
215+
{orig.mouse.x, orig.mouse.y, VERY_POSITIVE});
216216

217217
for(Entity &e : SK.entity) {
218218
if(e.group != SS.GW.activeGroup) continue;
@@ -583,7 +583,7 @@ Vector GraphicsWindow::UnProjectPoint3(Vector p) {
583583

584584
void GraphicsWindow::NormalizeProjectionVectors() {
585585
if(projRight.Magnitude() < LENGTH_EPS) {
586-
projRight = Vector::From(1, 0, 0);
586+
projRight = {1, 0, 0};
587587
}
588588

589589
Vector norm = projRight.Cross(projUp);

src/drawconstraint.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,8 @@ void Constraint::DoLayout(DrawAs how, Canvas *canvas,
742742
RgbaColor cd = Style::Color(Style::DATUM),
743743
cc = Style::Color(Style::CONSTRAINT);
744744
// convert from 8-bit color to a vector
745-
Vector vd = Vector::From(cd.redF(), cd.greenF(), cd.blueF()),
746-
vc = Vector::From(cc.redF(), cc.greenF(), cc.blueF());
745+
Vector vd = {cd.redF(), cd.greenF(), cd.blueF()},
746+
vc = {cc.redF(), cc.greenF(), cc.blueF()};
747747
// and scale the constraint color to have the same magnitude as
748748
// the datum color, maybe a bit dimmer
749749
vc = vc.WithMagnitude(vd.Magnitude()*0.9);
@@ -886,7 +886,7 @@ void Constraint::DoLayout(DrawAs how, Canvas *canvas,
886886
}
887887

888888
case Type::PERPENDICULAR: {
889-
Vector u = Vector::From(0, 0, 0), v = Vector::From(0, 0, 0);
889+
Vector u{}, v{}; // {0, 0, 0}
890890
Vector rn, ru;
891891
if(workplane == Entity::FREE_IN_3D) {
892892
rn = gn;
@@ -1043,7 +1043,7 @@ void Constraint::DoLayout(DrawAs how, Canvas *canvas,
10431043
case Type::LENGTH_RATIO:
10441044
case Type::LENGTH_DIFFERENCE:
10451045
case Type::EQUAL_LENGTH_LINES: {
1046-
Vector a, b = Vector::From(0, 0, 0);
1046+
Vector a, b;
10471047
for(int i = 0; i < 2; i++) {
10481048
Entity *e = SK.GetEntity(i == 0 ? entityA : entityB);
10491049
a = SK.GetEntity(e->point[0])->PointGetNum();
@@ -1092,7 +1092,7 @@ void Constraint::DoLayout(DrawAs how, Canvas *canvas,
10921092
}
10931093
case Type::ARC_LINE_LEN_RATIO:
10941094
case Type::ARC_LINE_DIFFERENCE: {
1095-
Vector a, b = Vector::From(0, 0, 0);
1095+
Vector a, b;
10961096
Vector ref;
10971097
Entity *e = SK.GetEntity(entityA);
10981098
a = SK.GetEntity(e->point[0])->PointGetNum();

src/drawentity.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ void Entity::ComputeInterpolatingSpline(SBezierList *sbl, bool periodic) const {
263263

264264
// The starting and finishing control points that define our end tangents
265265
// (if the spline isn't periodic), and the on-curve points.
266-
Vector ctrl_s = Vector::From(0, 0, 0);
267-
Vector ctrl_f = Vector::From(0, 0, 0);
266+
Vector ctrl_s{}; // {0, 0, 0}
267+
Vector ctrl_f{}; // {0, 0, 0}
268268
Vector pt[MAX_N+4];
269269
if(periodic) {
270270
for(i = 0; i < ep + 3; i++) {
@@ -362,24 +362,24 @@ void Entity::ComputeInterpolatingSpline(SBezierList *sbl, bool periodic) const {
362362
if(periodic) {
363363
p0 = pt[i];
364364
int iw = WRAP(i - 1, n);
365-
p1 = p0.Plus(Vector::From(Xx[iw], Xy[iw], Xz[iw]));
365+
p1 = p0.Plus({Xx[iw], Xy[iw], Xz[iw]});
366366
} else if(i == 0) {
367367
p0 = pt[0];
368368
p1 = ctrl_s;
369369
} else {
370370
p0 = pt[i];
371-
p1 = p0.Plus(Vector::From(Xx[i-1], Xy[i-1], Xz[i-1]));
371+
p1 = p0.Plus({Xx[i-1], Xy[i-1], Xz[i-1]});
372372
}
373373
if(periodic) {
374374
p3 = pt[i+1];
375375
int iw = WRAP(i, n);
376-
p2 = p3.Minus(Vector::From(Xx[iw], Xy[iw], Xz[iw]));
376+
p2 = p3.Minus({Xx[iw], Xy[iw], Xz[iw]});
377377
} else if(i == (pts - 2)) {
378378
p3 = pt[pts-1];
379379
p2 = ctrl_f;
380380
} else {
381381
p3 = pt[i+1];
382-
p2 = p3.Minus(Vector::From(Xx[i], Xy[i], Xz[i]));
382+
p2 = p3.Minus({Xx[i], Xy[i], Xz[i]});
383383
}
384384
SBezier sb = SBezier::From(p0, p1, p2, p3);
385385
sbl->l.Add(&sb);
@@ -503,7 +503,7 @@ Vector Entity::ExplodeOffset() const {
503503
double offset = SS.explodeDistance * (requestIdx + 1);
504504
return SK.GetEntity(workplane)->Normal()->NormalN().ScaledBy(offset);
505505
} else {
506-
return Vector::From(0, 0, 0);
506+
return {}; // {0, 0, 0}
507507
}
508508
}
509509

src/entity.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -723,7 +723,7 @@ bool EntityBase::IsFace() const {
723723
ExprVector EntityBase::FaceGetNormalExprs() const {
724724
ExprVector r;
725725
if(type == Type::FACE_NORMAL_PT) {
726-
Vector v = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz);
726+
Vector v = {numNormal.vx, numNormal.vy, numNormal.vz};
727727
r = ExprVector::From(v.WithMagnitude(1));
728728
} else if(type == Type::FACE_XPROD) {
729729
ExprVector vc = ExprVector::From(param[0], param[1], param[2]);
@@ -752,20 +752,20 @@ ExprVector EntityBase::FaceGetNormalExprs() const {
752752
Vector EntityBase::FaceGetNormalNum() const {
753753
Vector r;
754754
if(type == Type::FACE_NORMAL_PT) {
755-
r = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz);
755+
r = {numNormal.vx, numNormal.vy, numNormal.vz};
756756
} else if(type == Type::FACE_XPROD) {
757757
Vector vc = Vector::From(param[0], param[1], param[2]);
758-
Vector vn = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz);
758+
Vector vn = {numNormal.vx, numNormal.vy, numNormal.vz};
759759
r = vc.Cross(vn);
760760
} else if(type == Type::FACE_N_ROT_TRANS) {
761761
// The numerical normal vector gets the rotation
762-
r = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz);
762+
r = {numNormal.vx, numNormal.vy, numNormal.vz};
763763
Quaternion q = Quaternion::From(param[3], param[4], param[5], param[6]);
764764
r = q.Rotate(r);
765765
} else if(type == Type::FACE_N_TRANS) {
766-
r = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz);
766+
r = {numNormal.vx, numNormal.vy, numNormal.vz};
767767
} else if((type == Type::FACE_N_ROT_AA) || (type == Type::FACE_ROT_NORMAL_PT)) {
768-
r = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz);
768+
r = {numNormal.vx, numNormal.vy, numNormal.vz};
769769
Quaternion q = GetAxisAngleQuaternion(3);
770770
r = q.Rotate(r);
771771
} else ssassert(false, "Unexpected entity type");

src/export.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,10 @@ void SolveSpaceUI::ExportViewOrWireframeTo(const Platform::Path &filename, bool
246246
}
247247

248248
if(exportWireframe) {
249-
Vector u = Vector::From(1.0, 0.0, 0.0),
250-
v = Vector::From(0.0, 1.0, 0.0),
251-
n = Vector::From(0.0, 0.0, 1.0),
252-
origin = Vector::From(0.0, 0.0, 0.0);
249+
Vector u{1.0, 0.0, 0.0},
250+
v{0.0, 1.0, 0.0},
251+
n{0.0, 0.0, 1.0},
252+
origin{}; // {0, 0, 0}
253253
double cameraTan = 0.0,
254254
scale = 1.0;
255255

@@ -344,7 +344,7 @@ void SolveSpaceUI::ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *s
344344
sel->Clear();
345345

346346
SPolygon compd = {};
347-
sp.normal = Vector::From(0, 0, -1);
347+
sp.normal = {0, 0, -1};
348348
sp.FixContourDirections();
349349
sp.OffsetInto(&compd, SS.exportOffset*s);
350350
sp.Clear();
@@ -591,9 +591,9 @@ void SolveSpaceUI::ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *s
591591
// will then get exported as closed paths.
592592
SBezierLoopSetSet sblss = {};
593593
SBezierLoopSet leftovers = {};
594-
SSurface srf = SSurface::FromPlane(Vector::From(0, 0, 0),
595-
Vector::From(1, 0, 0),
596-
Vector::From(0, 1, 0));
594+
SSurface srf = SSurface::FromPlane({0, 0, 0},
595+
{1, 0, 0},
596+
{0, 1, 0});
597597
SPolygon spxyz = {};
598598
bool allClosed;
599599
SEdge notClosedAt;
@@ -685,8 +685,8 @@ void VectorFileWriter::OutputLinesAndMesh(SBezierLoopSetSet *sblss, SMesh *sm) {
685685
SBezier *b;
686686

687687
// First calculate the bounding box.
688-
ptMin = Vector::From(VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE);
689-
ptMax = Vector::From(VERY_NEGATIVE, VERY_NEGATIVE, VERY_NEGATIVE);
688+
ptMin = {VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE};
689+
ptMax = {VERY_NEGATIVE, VERY_NEGATIVE, VERY_NEGATIVE};
690690
if(sm) {
691691
for(tr = sm->l.First(); tr; tr = sm->l.NextAfter(tr)) {
692692
(tr->a).MakeMaxMin(&ptMax, &ptMin);

src/exportvector.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,10 @@ class DxfWriteInterface : public DRW_Interface {
311311
int findDxfColor(const RgbaColor &src) {
312312
int best = 0;
313313
double minDist = VERY_POSITIVE;
314-
Vector srcv = Vector::From(src.redF(), src.greenF(), src.blueF());
314+
Vector srcv = {src.redF(), src.greenF(), src.blueF()};
315315
for(int i = 1; i < 256; i++) {
316316
RgbaColor dst = RGBi(DRW::dxfColors[i][0], DRW::dxfColors[i][1], DRW::dxfColors[i][2]);
317-
Vector dstv = Vector::From(dst.redF(), dst.greenF(), dst.blueF());
317+
Vector dstv = {dst.redF(), dst.greenF(), dst.blueF()};
318318
double dist = srcv.Minus(dstv).Magnitude();
319319
if(dist < minDist || best == 0) {
320320
best = i;
@@ -421,7 +421,7 @@ class DxfWriteInterface : public DRW_Interface {
421421
void writeBezier(SBezier *sb) {
422422
hStyle hs = { (uint32_t)sb->auxA };
423423
Vector c;
424-
Vector n = Vector::From(0.0, 0.0, 1.0);
424+
Vector n = {0.0, 0.0, 1.0};
425425
double r;
426426

427427
if(sb->deg == 1) {
@@ -732,7 +732,7 @@ void EpsFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
732732
bool filled, RgbaColor fillRgb, hStyle hs)
733733
{
734734
fprintf(f, "newpath\r\n");
735-
prevPt = Vector::From(VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE);
735+
prevPt = {VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE};
736736
}
737737
void EpsFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth,
738738
bool filled, RgbaColor fillRgb, hStyle hs)
@@ -789,7 +789,7 @@ void EpsFileWriter::Triangle(STriangle *tr) {
789789
}
790790

791791
void EpsFileWriter::Bezier(SBezier *sb) {
792-
Vector c, n = Vector::From(0, 0, 1);
792+
Vector c, n = {0, 0, 1};
793793
double r;
794794
if(sb->deg == 1) {
795795
MaybeMoveTo(sb->ctrl[0], sb->ctrl[1]);
@@ -999,7 +999,7 @@ void PdfFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
999999
fillRgb.redF(), fillRgb.greenF(), fillRgb.blueF());
10001000
}
10011001

1002-
prevPt = Vector::From(VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE);
1002+
prevPt = {VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE};
10031003
}
10041004
void PdfFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth,
10051005
bool filled, RgbaColor fillRgb, hStyle hs)
@@ -1133,7 +1133,7 @@ void SvgFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
11331133
bool filled, RgbaColor fillRgb, hStyle hs)
11341134
{
11351135
fprintf(f, "<path d='");
1136-
prevPt = Vector::From(VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE);
1136+
prevPt = {VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE};
11371137
}
11381138
void SvgFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth,
11391139
bool filled, RgbaColor fillRgb, hStyle hs)
@@ -1168,7 +1168,7 @@ void SvgFileWriter::Triangle(STriangle *tr) {
11681168
}
11691169

11701170
void SvgFileWriter::Bezier(SBezier *sb) {
1171-
Vector c, n = Vector::From(0, 0, 1);
1171+
Vector c, n = {0, 0, 1};
11721172
double r;
11731173
if(sb->deg == 1) {
11741174
MaybeMoveTo(sb->ctrl[0], sb->ctrl[1]);

0 commit comments

Comments
 (0)