Skip to content

Commit 09a36cd

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 2fd3989 commit 09a36cd

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
@@ -207,7 +207,7 @@ void GraphicsWindow::PasteClipboard(Vector trans, double theta, double scale) {
207207
// Likewise the scale, which could otherwise take us out of the
208208
// workplane.
209209
pt = pt.ScaledBy(fabs(scale));
210-
pt = pt.ScaleOutOfCsys(u, v, Vector::From(0, 0, 0));
210+
pt = pt.ScaleOutOfCsys(u, v, {}/*{0, 0, 0}*/);
211211
pt = pt.Plus(p);
212212
pt = pt.RotatedAbout(n, theta);
213213
pt = pt.Plus(trans);
@@ -336,7 +336,7 @@ void GraphicsWindow::MenuClipboard(Command id) {
336336
Entity *wrkpl = SK.GetEntity(SS.GW.ActiveWorkplane());
337337
Vector p = SK.GetEntity(wrkpl->point[0])->PointGetNum();
338338
SS.TW.shown.paste.times = 1;
339-
SS.TW.shown.paste.trans = Vector::From(0, 0, 0);
339+
SS.TW.shown.paste.trans = {}; // {0, 0, 0}
340340
SS.TW.shown.paste.theta = 0;
341341
SS.TW.shown.paste.origin = p;
342342
SS.TW.shown.paste.scale = 1;

src/confscreen.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ void TextWindow::ScreenChangeTurntableNav(int link, uint32_t v) {
9696
SS.turntableNav = !SS.turntableNav;
9797
if(SS.turntableNav) {
9898
// If turntable nav is being turned on, align view so Z is vertical
99-
SS.GW.AnimateOnto(Quaternion::From(Vector::From(-1, 0, 0), Vector::From(0, 0, 1)),
99+
SS.GW.AnimateOnto(Quaternion::From({-1, 0, 0}, {0, 0, 1}),
100100
SS.GW.offset);
101101
}
102102
}
@@ -404,7 +404,7 @@ bool TextWindow::EditControlDoneForConfiguration(const std::string &s) {
404404
case Edit::LIGHT_DIRECTION: {
405405
double x, y, z;
406406
if(sscanf(s.c_str(), "%lf, %lf, %lf", &x, &y, &z)==3) {
407-
SS.lightDir[edit.i] = Vector::From(x, y, z);
407+
SS.lightDir[edit.i] = {x, y, z};
408408
SS.GW.Invalidate();
409409
} else {
410410
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
@@ -318,7 +318,7 @@ void Constraint::MenuConstrain(Command id) {
318318
c.disp.offset = n.Cross(a.Minus(b));
319319
c.disp.offset = (c.disp.offset).WithMagnitude(50/SS.GW.scale);
320320
} else {
321-
c.disp.offset = Vector::From(0, 0, 0);
321+
c.disp.offset = {}; // {0, 0, 0}
322322
}
323323

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

src/constrainteq.cpp

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

src/draw.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,8 @@ void GraphicsWindow::MakeSelected(Selection *stog) {
209209
//-----------------------------------------------------------------------------
210210
void GraphicsWindow::SelectByMarquee() {
211211
Point2d marqueePoint = ProjectPoint(orig.marqueePoint);
212-
BBox marqueeBBox = BBox::From(Vector::From(marqueePoint.x, marqueePoint.y, VERY_NEGATIVE),
213-
Vector::From(orig.mouse.x, orig.mouse.y, VERY_POSITIVE));
212+
BBox marqueeBBox = BBox::From({marqueePoint.x, marqueePoint.y, VERY_NEGATIVE},
213+
{orig.mouse.x, orig.mouse.y, VERY_POSITIVE});
214214

215215
for(Entity &e : SK.entity) {
216216
if(e.group != SS.GW.activeGroup) continue;
@@ -578,7 +578,7 @@ Vector GraphicsWindow::UnProjectPoint3(Vector p) {
578578

579579
void GraphicsWindow::NormalizeProjectionVectors() {
580580
if(projRight.Magnitude() < LENGTH_EPS) {
581-
projRight = Vector::From(1, 0, 0);
581+
projRight = {1, 0, 0};
582582
}
583583

584584
Vector norm = projRight.Cross(projUp);

src/drawconstraint.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -740,8 +740,8 @@ void Constraint::DoLayout(DrawAs how, Canvas *canvas,
740740
RgbaColor cd = Style::Color(Style::DATUM),
741741
cc = Style::Color(Style::CONSTRAINT);
742742
// convert from 8-bit color to a vector
743-
Vector vd = Vector::From(cd.redF(), cd.greenF(), cd.blueF()),
744-
vc = Vector::From(cc.redF(), cc.greenF(), cc.blueF());
743+
Vector vd = {cd.redF(), cd.greenF(), cd.blueF()},
744+
vc = {cc.redF(), cc.greenF(), cc.blueF()};
745745
// and scale the constraint color to have the same magnitude as
746746
// the datum color, maybe a bit dimmer
747747
vc = vc.WithMagnitude(vd.Magnitude()*0.9);
@@ -884,7 +884,7 @@ void Constraint::DoLayout(DrawAs how, Canvas *canvas,
884884
}
885885

886886
case Type::PERPENDICULAR: {
887-
Vector u = Vector::From(0, 0, 0), v = Vector::From(0, 0, 0);
887+
Vector u{}, v{}; // {0, 0, 0}
888888
Vector rn, ru;
889889
if(workplane == Entity::FREE_IN_3D) {
890890
rn = gn;
@@ -1041,7 +1041,7 @@ void Constraint::DoLayout(DrawAs how, Canvas *canvas,
10411041
case Type::LENGTH_RATIO:
10421042
case Type::LENGTH_DIFFERENCE:
10431043
case Type::EQUAL_LENGTH_LINES: {
1044-
Vector a, b = Vector::From(0, 0, 0);
1044+
Vector a, b;
10451045
for(int i = 0; i < 2; i++) {
10461046
Entity *e = SK.GetEntity(i == 0 ? entityA : entityB);
10471047
a = SK.GetEntity(e->point[0])->PointGetNum();
@@ -1090,7 +1090,7 @@ void Constraint::DoLayout(DrawAs how, Canvas *canvas,
10901090
}
10911091
case Type::ARC_LINE_LEN_RATIO:
10921092
case Type::ARC_LINE_DIFFERENCE: {
1093-
Vector a, b = Vector::From(0, 0, 0);
1093+
Vector a, b;
10941094
Vector ref;
10951095
Entity *e = SK.GetEntity(entityA);
10961096
a = SK.GetEntity(e->point[0])->PointGetNum();

src/drawentity.cpp

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

262262
// The starting and finishing control points that define our end tangents
263263
// (if the spline isn't periodic), and the on-curve points.
264-
Vector ctrl_s = Vector::From(0, 0, 0);
265-
Vector ctrl_f = Vector::From(0, 0, 0);
264+
Vector ctrl_s{}; // {0, 0, 0}
265+
Vector ctrl_f{}; // {0, 0, 0}
266266
Vector pt[MAX_N+4];
267267
if(periodic) {
268268
for(i = 0; i < ep + 3; i++) {
@@ -360,24 +360,24 @@ void Entity::ComputeInterpolatingSpline(SBezierList *sbl, bool periodic) const {
360360
if(periodic) {
361361
p0 = pt[i];
362362
int iw = WRAP(i - 1, n);
363-
p1 = p0.Plus(Vector::From(Xx[iw], Xy[iw], Xz[iw]));
363+
p1 = p0.Plus({Xx[iw], Xy[iw], Xz[iw]});
364364
} else if(i == 0) {
365365
p0 = pt[0];
366366
p1 = ctrl_s;
367367
} else {
368368
p0 = pt[i];
369-
p1 = p0.Plus(Vector::From(Xx[i-1], Xy[i-1], Xz[i-1]));
369+
p1 = p0.Plus({Xx[i-1], Xy[i-1], Xz[i-1]});
370370
}
371371
if(periodic) {
372372
p3 = pt[i+1];
373373
int iw = WRAP(i, n);
374-
p2 = p3.Minus(Vector::From(Xx[iw], Xy[iw], Xz[iw]));
374+
p2 = p3.Minus({Xx[iw], Xy[iw], Xz[iw]});
375375
} else if(i == (pts - 2)) {
376376
p3 = pt[pts-1];
377377
p2 = ctrl_f;
378378
} else {
379379
p3 = pt[i+1];
380-
p2 = p3.Minus(Vector::From(Xx[i], Xy[i], Xz[i]));
380+
p2 = p3.Minus({Xx[i], Xy[i], Xz[i]});
381381
}
382382
SBezier sb = SBezier::From(p0, p1, p2, p3);
383383
sbl->l.Add(&sb);
@@ -501,7 +501,7 @@ Vector Entity::ExplodeOffset() const {
501501
double offset = SS.explodeDistance * (requestIdx + 1);
502502
return SK.GetEntity(workplane)->Normal()->NormalN().ScaledBy(offset);
503503
} else {
504-
return Vector::From(0, 0, 0);
504+
return {}; // {0, 0, 0}
505505
}
506506
}
507507

src/entity.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ bool EntityBase::IsFace() const {
721721
ExprVector EntityBase::FaceGetNormalExprs() const {
722722
ExprVector r;
723723
if(type == Type::FACE_NORMAL_PT) {
724-
Vector v = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz);
724+
Vector v = {numNormal.vx, numNormal.vy, numNormal.vz};
725725
r = ExprVector::From(v.WithMagnitude(1));
726726
} else if(type == Type::FACE_XPROD) {
727727
ExprVector vc = ExprVector::From(param[0], param[1], param[2]);
@@ -750,20 +750,20 @@ ExprVector EntityBase::FaceGetNormalExprs() const {
750750
Vector EntityBase::FaceGetNormalNum() const {
751751
Vector r;
752752
if(type == Type::FACE_NORMAL_PT) {
753-
r = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz);
753+
r = {numNormal.vx, numNormal.vy, numNormal.vz};
754754
} else if(type == Type::FACE_XPROD) {
755755
Vector vc = Vector::From(param[0], param[1], param[2]);
756-
Vector vn = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz);
756+
Vector vn = {numNormal.vx, numNormal.vy, numNormal.vz};
757757
r = vc.Cross(vn);
758758
} else if(type == Type::FACE_N_ROT_TRANS) {
759759
// The numerical normal vector gets the rotation
760-
r = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz);
760+
r = {numNormal.vx, numNormal.vy, numNormal.vz};
761761
Quaternion q = Quaternion::From(param[3], param[4], param[5], param[6]);
762762
r = q.Rotate(r);
763763
} else if(type == Type::FACE_N_TRANS) {
764-
r = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz);
764+
r = {numNormal.vx, numNormal.vy, numNormal.vz};
765765
} else if((type == Type::FACE_N_ROT_AA) || (type == Type::FACE_ROT_NORMAL_PT)) {
766-
r = Vector::From(numNormal.vx, numNormal.vy, numNormal.vz);
766+
r = {numNormal.vx, numNormal.vy, numNormal.vz};
767767
Quaternion q = GetAxisAngleQuaternion(3);
768768
r = q.Rotate(r);
769769
} else ssassert(false, "Unexpected entity type");

src/export.cpp

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

246246
if(exportWireframe) {
247-
Vector u = Vector::From(1.0, 0.0, 0.0),
248-
v = Vector::From(0.0, 1.0, 0.0),
249-
n = Vector::From(0.0, 0.0, 1.0),
250-
origin = Vector::From(0.0, 0.0, 0.0);
247+
Vector u{1.0, 0.0, 0.0},
248+
v{0.0, 1.0, 0.0},
249+
n{0.0, 0.0, 1.0},
250+
origin{}; // {0, 0, 0}
251251
double cameraTan = 0.0,
252252
scale = 1.0;
253253

@@ -342,7 +342,7 @@ void SolveSpaceUI::ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *s
342342
sel->Clear();
343343

344344
SPolygon compd = {};
345-
sp.normal = Vector::From(0, 0, -1);
345+
sp.normal = {0, 0, -1};
346346
sp.FixContourDirections();
347347
sp.OffsetInto(&compd, SS.exportOffset*s);
348348
sp.Clear();
@@ -589,9 +589,9 @@ void SolveSpaceUI::ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *s
589589
// will then get exported as closed paths.
590590
SBezierLoopSetSet sblss = {};
591591
SBezierLoopSet leftovers = {};
592-
SSurface srf = SSurface::FromPlane(Vector::From(0, 0, 0),
593-
Vector::From(1, 0, 0),
594-
Vector::From(0, 1, 0));
592+
SSurface srf = SSurface::FromPlane({0, 0, 0},
593+
{1, 0, 0},
594+
{0, 1, 0});
595595
SPolygon spxyz = {};
596596
bool allClosed;
597597
SEdge notClosedAt;
@@ -683,8 +683,8 @@ void VectorFileWriter::OutputLinesAndMesh(SBezierLoopSetSet *sblss, SMesh *sm) {
683683
SBezier *b;
684684

685685
// First calculate the bounding box.
686-
ptMin = Vector::From(VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE);
687-
ptMax = Vector::From(VERY_NEGATIVE, VERY_NEGATIVE, VERY_NEGATIVE);
686+
ptMin = {VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE};
687+
ptMax = {VERY_NEGATIVE, VERY_NEGATIVE, VERY_NEGATIVE};
688688
if(sm) {
689689
for(tr = sm->l.First(); tr; tr = sm->l.NextAfter(tr)) {
690690
(tr->a).MakeMaxMin(&ptMax, &ptMin);

src/exportvector.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,10 @@ class DxfWriteInterface : public DRW_Interface {
309309
int findDxfColor(const RgbaColor &src) {
310310
int best = 0;
311311
double minDist = VERY_POSITIVE;
312-
Vector srcv = Vector::From(src.redF(), src.greenF(), src.blueF());
312+
Vector srcv = {src.redF(), src.greenF(), src.blueF()};
313313
for(int i = 1; i < 256; i++) {
314314
RgbaColor dst = RGBi(DRW::dxfColors[i][0], DRW::dxfColors[i][1], DRW::dxfColors[i][2]);
315-
Vector dstv = Vector::From(dst.redF(), dst.greenF(), dst.blueF());
315+
Vector dstv = {dst.redF(), dst.greenF(), dst.blueF()};
316316
double dist = srcv.Minus(dstv).Magnitude();
317317
if(dist < minDist || best == 0) {
318318
best = i;
@@ -419,7 +419,7 @@ class DxfWriteInterface : public DRW_Interface {
419419
void writeBezier(SBezier *sb) {
420420
hStyle hs = { (uint32_t)sb->auxA };
421421
Vector c;
422-
Vector n = Vector::From(0.0, 0.0, 1.0);
422+
Vector n = {0.0, 0.0, 1.0};
423423
double r;
424424

425425
if(sb->deg == 1) {
@@ -730,7 +730,7 @@ void EpsFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
730730
bool filled, RgbaColor fillRgb, hStyle hs)
731731
{
732732
fprintf(f, "newpath\r\n");
733-
prevPt = Vector::From(VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE);
733+
prevPt = {VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE};
734734
}
735735
void EpsFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth,
736736
bool filled, RgbaColor fillRgb, hStyle hs)
@@ -787,7 +787,7 @@ void EpsFileWriter::Triangle(STriangle *tr) {
787787
}
788788

789789
void EpsFileWriter::Bezier(SBezier *sb) {
790-
Vector c, n = Vector::From(0, 0, 1);
790+
Vector c, n = {0, 0, 1};
791791
double r;
792792
if(sb->deg == 1) {
793793
MaybeMoveTo(sb->ctrl[0], sb->ctrl[1]);
@@ -997,7 +997,7 @@ void PdfFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
997997
fillRgb.redF(), fillRgb.greenF(), fillRgb.blueF());
998998
}
999999

1000-
prevPt = Vector::From(VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE);
1000+
prevPt = {VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE};
10011001
}
10021002
void PdfFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth,
10031003
bool filled, RgbaColor fillRgb, hStyle hs)
@@ -1131,7 +1131,7 @@ void SvgFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
11311131
bool filled, RgbaColor fillRgb, hStyle hs)
11321132
{
11331133
fprintf(f, "<path d='");
1134-
prevPt = Vector::From(VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE);
1134+
prevPt = {VERY_POSITIVE, VERY_POSITIVE, VERY_POSITIVE};
11351135
}
11361136
void SvgFileWriter::FinishPath(RgbaColor strokeRgb, double lineWidth,
11371137
bool filled, RgbaColor fillRgb, hStyle hs)
@@ -1166,7 +1166,7 @@ void SvgFileWriter::Triangle(STriangle *tr) {
11661166
}
11671167

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

0 commit comments

Comments
 (0)