FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add and use IdList::IsEmpty. NFC. · PavelZX/solvespace@5ada4db · GitHub

Repository navigation

Commit 5ada4db

Browse files
authored andcommitted
Add and use IdList::IsEmpty. NFC.
Removes consuming code from the implementation details, easing swap of the underlying container, etc.
1 parent b5f36a4 commit 5ada4db

22 files changed

Lines changed: 65 additions & 49 deletions

‎src/clipboard.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ void GraphicsWindow::MenuClipboard(Command id) {
287287
}
288288

289289
case Command::PASTE_TRANSFORM: {
290-
if(SS.clipboard.r.n == 0) {
290+
if(SS.clipboard.r.IsEmpty()) {
291291
Error(_("Clipboard is empty; nothing to paste."));
292292
break;
293293
}

‎src/draw.cpp‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,8 @@ Lighting GraphicsWindow::GetLighting() const {
329329

330330
GraphicsWindow::Selection GraphicsWindow::ChooseFromHoverToSelect() {
331331
Selection sel = {};
332-
if(hoverList.n == 0) return sel;
332+
if(hoverList.IsEmpty())
333+
return sel;
333334

334335
Group *activeGroup = SK.GetGroup(SS.GW.activeGroup);
335336
int bestOrder = -1;

‎src/drawentity.cpp‎

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,18 @@ void Entity::GenerateEdges(SEdgeList *el) {
3434
}
3535

3636
SBezierList *Entity::GetOrGenerateBezierCurves() {
37-
if(beziers.l.n == 0)
37+
if(beziers.l.IsEmpty())
3838
GenerateBezierCurves(&beziers);
3939
return &beziers;
4040
}
4141

4242
SEdgeList *Entity::GetOrGenerateEdges() {
43-
if(edges.l.n != 0) {
43+
if(!edges.l.IsEmpty()) {
4444
if(EXACT(edgesChordTol == SS.ChordTolMm()))
4545
return &edges;
4646
edges.l.Clear();
4747
}
48-
if(edges.l.n == 0)
48+
if(edges.l.IsEmpty())
4949
GenerateEdges(&edges);
5050
edgesChordTol = SS.ChordTolMm();
5151
return &edges;
@@ -55,7 +55,7 @@ BBox Entity::GetOrGenerateScreenBBox(bool *hasBBox) {
5555
SBezierList *sbl = GetOrGenerateBezierCurves();
5656

5757
// We don't bother with bounding boxes for workplanes, etc.
58-
*hasBBox = (IsPoint() || IsNormal() || sbl->l.n > 0);
58+
*hasBBox = (IsPoint() || IsNormal() || !sbl->l.IsEmpty());
5959
if(!*hasBBox) return {};
6060

6161
if(screenBBoxValid)
@@ -67,16 +67,14 @@ BBox Entity::GetOrGenerateScreenBBox(bool *hasBBox) {
6767
} else if(IsNormal()) {
6868
Vector proj = SK.GetEntity(point[0])->PointGetNum();
6969
screenBBox = BBox::From(proj, proj);
70-
} else if(sbl->l.n > 0) {
70+
} else if(!sbl->l.IsEmpty()) {
7171
Vector first = SS.GW.ProjectPoint3(sbl->l.elem[0].ctrl[0]);
7272
screenBBox = BBox::From(first, first);
73-
for(int i = 0; i < sbl->l.n; i++) {
74-
SBezier *sb = &sbl->l.elem[i];
75-
for(int i = 0; i <= sb->deg; i++) {
76-
screenBBox.Include(SS.GW.ProjectPoint3(sb->ctrl[i]));
77-
}
73+
for(auto &sb : sbl->l) {
74+
for(int i = 0; i < sb.deg; ++i) { screenBBox.Include(SS.GW.ProjectPoint3(sb.ctrl[i])); }
7875
}
79-
} else ssassert(false, "Expected entity to be a point or have beziers");
76+
} else
77+
ssassert(false, "Expected entity to be a point or have beziers");
8078

8179
screenBBoxValid = true;
8280
return screenBBox;

‎src/dsc.h‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,12 @@ class IdList {
325325
int n;
326326
int elemsAllocated;
327327

328+
bool IsEmpty() const {
329+
return n == 0;
330+
}
331+
328332
uint32_t MaximumId() {
329-
if(n == 0) {
333+
if(IsEmpty()) {
330334
return 0;
331335
} else {
332336
return elem[n - 1].h.v;
@@ -385,6 +389,9 @@ class IdList {
385389
}
386390

387391
int IndexOf(H h) {
392+
if(IsEmpty()) {
393+
return -1;
394+
}
388395
int first = 0, last = n-1;
389396
while(first <= last) {
390397
int mid = (first + last)/2;
@@ -401,6 +408,9 @@ class IdList {
401408
}
402409

403410
T *FindByIdNoOops(H h) {
411+
if(IsEmpty()) {
412+
return nullptr;
413+
}
404414
int first = 0, last = n-1;
405415
while(first <= last) {
406416
int mid = (first + last)/2;
@@ -417,10 +427,10 @@ class IdList {
417427
}
418428

419429
T *First() {
420-
return (n == 0) ? NULL : &(elem[0]);
430+
return (IsEmpty()) ? NULL : &(elem[0]);
421431
}
422432
T *NextAfter(T *prev) {
423-
if(!prev) return NULL;
433+
if(IsEmpty() || !prev) return NULL;
424434
if(prev - elem == (n - 1)) return NULL;
425435
return prev + 1;
426436
}

‎src/exportstep.cpp‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,13 @@ void StepFileWriter::ExportSurfacesTo(const Platform::Path &filename) {
296296
Group *g = SK.GetGroup(SS.GW.activeGroup);
297297
SShell *shell = &(g->runningShell);
298298

299-
if(shell->surface.n == 0) {
299+
if(shell->surface.IsEmpty()) {
300300
Error("The model does not contain any surfaces to export.%s",
301-
g->runningMesh.l.n > 0 ?
302-
"\n\nThe model does contain triangles from a mesh, but "
303-
"a triangle mesh cannot be exported as a STEP file. Try "
304-
"File -> Export Mesh... instead." : "");
301+
!g->runningMesh.l.IsEmpty()
302+
? "\n\nThe model does contain triangles from a mesh, but "
303+
"a triangle mesh cannot be exported as a STEP file. Try "
304+
"File -> Export Mesh... instead."
305+
: "");
305306
return;
306307
}
307308

@@ -318,7 +319,8 @@ void StepFileWriter::ExportSurfacesTo(const Platform::Path &filename) {
318319

319320
SSurface *ss;
320321
for(ss = shell->surface.First(); ss; ss = shell->surface.NextAfter(ss)) {
321-
if(ss->trim.n == 0) continue;
322+
if(ss->trim.IsEmpty())
323+
continue;
322324

323325
// Get all of the loops of Beziers that trim our surface (with each
324326
// Bezier split so that we use the section as t goes from 0 to 1), and

‎src/file.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,7 @@ bool SolveSpaceUI::LoadFromFile(const Platform::Path &filename, bool canCancel)
549549
Error(_("Unrecognized data in file. This file may be corrupt, or "
550550
"from a newer version of the program."));
551551
// At least leave the program in a non-crashing state.
552-
if(SK.group.n == 0) {
552+
if(SK.group.IsEmpty()) {
553553
NewFile();
554554
}
555555
}

‎src/graphicswin.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ void GraphicsWindow::ToggleBool(bool *v) {
13061306
// If the mesh or edges were previously hidden, they haven't been generated,
13071307
// and if we are going to show them, we need to generate them first.
13081308
Group *g = SK.GetGroup(SS.GW.activeGroup);
1309-
if(*v && (g->displayOutlines.l.n == 0 && (v == &showEdges || v == &showOutlines))) {
1309+
if(*v && (g->displayOutlines.l.IsEmpty() && (v == &showEdges || v == &showOutlines))) {
13101310
SS.GenerateAll(SolveSpaceUI::Generate::UNTIL_ACTIVE);
13111311
}
13121312

‎src/group.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ void Group::MenuGroup(Command id, Platform::Path linkFile) {
297297
}
298298

299299
// Copy color from the previous mesh-contributing group.
300-
if(g.IsMeshGroup() && SK.groupOrder.n > 0) {
300+
if(g.IsMeshGroup() && !SK.groupOrder.IsEmpty()) {
301301
Group *running = SK.GetRunningMeshGroupFor(SS.GW.activeGroup);
302302
if(running != NULL) {
303303
g.color = running->color;

‎src/groupmesh.cpp‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ void Group::GenerateDisplayItems() {
466466

467467
if(SS.GW.showEdges || SS.GW.showOutlines) {
468468
SOutlineList rawOutlines = {};
469-
if(runningMesh.l.n > 0) {
469+
if(!runningMesh.l.IsEmpty()) {
470470
// Triangle mesh only; no shell or emphasized edges.
471471
runningMesh.MakeOutlinesInto(&rawOutlines, EdgeKind::EMPHASIZED);
472472
} else {
@@ -706,7 +706,8 @@ void Group::DrawPolyError(Canvas *canvas) {
706706

707707
void Group::DrawFilledPaths(Canvas *canvas) {
708708
for(const SBezierLoopSet &sbls : bezierLoops.l) {
709-
if(sbls.l.n == 0 || sbls.l.elem[0].l.n == 0) continue;
709+
if(sbls.l.IsEmpty() || sbls.l[0].l.IsEmpty())
710+
continue;
710711

711712
// In an assembled loop, all the styles should be the same; so doesn't
712713
// matter which one we grab.
@@ -740,7 +741,8 @@ void Group::DrawContourAreaLabels(Canvas *canvas) {
740741
Vector gu = camera.projUp.ScaledBy(1 / camera.scale);
741742

742743
for(SBezierLoopSet &sbls : bezierLoops.l) {
743-
if(sbls.l.n == 0 || sbls.l.elem[0].l.n == 0) continue;
744+
if(sbls.l.IsEmpty() || sbls.l[0].l.IsEmpty())
745+
continue;
744746

745747
Vector min = sbls.l.elem[0].l.elem[0].ctrl[0];
746748
Vector max = min;

‎src/lib.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ default: dbp("bad constraint type %d", sc->type); return;
182182
c.other2 = (sc->other2) ? true : false;
183183

184184
c.Generate(&params);
185-
if(params.n > 0) {
185+
if(!params.IsEmpty()) {
186186
for(Param &p : params) {
187187
p.h = SK.param.AddAndAssignId(&p);
188188
c.valP = p.h;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL