Replace all ZERO and memset with C++11 brace-initialization.

This will allow us to use non-POD classes inside these objects
in future and is otherwise functionally equivalent, as well
as more concise.

Note that there are some subtleties with handling of
brace-initialization. Specifically:

On aggregates (e.g. simple C-style structures) using an empty
brace-initializer zero-initializes the aggregate, i.e. it makes
all members zero.

On non-aggregates an empty brace-initializer calls the default
constructor. And if the constructor doesn't explicitly initialize
the members (which the auto-generated constructor doesn't) then
the members will be constructed but otherwise uninitialized.

So, what is an aggregate class? To quote the C++ standard
(C++03 8.5.1 §1):

An aggregate is an array or a class (clause 9) with no
user-declared constructors (12.1), no private or protected
non-static data members (clause 11), no base classes (clause 10),
and no virtual functions (10.3).

In SolveSpace, we only have to handle the case of base classes;
Constraint and Entity have those. Thus, they had to gain a default
constructor that does nothing but initializes the members to zero.
pull/4/head
whitequark 2015-03-27 18:31:23 +03:00
parent 02c30e6f87
commit 45f056c852
40 changed files with 249 additions and 401 deletions

View File

@ -52,7 +52,7 @@ static void Example3d(void)
sys.param[sys.params++] = Slvs_MakeParam(6, g, 20.0); sys.param[sys.params++] = Slvs_MakeParam(6, g, 20.0);
sys.entity[sys.entities++] = Slvs_MakePoint3d(102, g, 4, 5, 6); sys.entity[sys.entities++] = Slvs_MakePoint3d(102, g, 4, 5, 6);
/* and a line segment connecting them. */ /* and a line segment connecting them. */
sys.entity[sys.entities++] = Slvs_MakeLineSegment(200, g, sys.entity[sys.entities++] = Slvs_MakeLineSegment(200, g,
SLVS_FREE_IN_3D, 101, 102); SLVS_FREE_IN_3D, 101, 102);
/* The distance between the points should be 30.0 units. */ /* The distance between the points should be 30.0 units. */
@ -127,7 +127,7 @@ static void Example2d(void)
sys.entity[sys.entities++] = Slvs_MakePoint2d(302, g, 200, 13, 14); sys.entity[sys.entities++] = Slvs_MakePoint2d(302, g, 200, 13, 14);
/* And we create a line segment with those endpoints. */ /* And we create a line segment with those endpoints. */
sys.entity[sys.entities++] = Slvs_MakeLineSegment(400, g, sys.entity[sys.entities++] = Slvs_MakeLineSegment(400, g,
200, 301, 302); 200, 301, 302);
/* Now three more points. */ /* Now three more points. */
@ -256,7 +256,6 @@ static void Example2d(void)
int main(void) int main(void)
{ {
memset(&sys, 0, sizeof(sys));
sys.param = CheckMalloc(50*sizeof(sys.param[0])); sys.param = CheckMalloc(50*sizeof(sys.param[0]));
sys.entity = CheckMalloc(50*sizeof(sys.entity[0])); sys.entity = CheckMalloc(50*sizeof(sys.entity[0]));
sys.constraint = CheckMalloc(50*sizeof(sys.constraint[0])); sys.constraint = CheckMalloc(50*sizeof(sys.constraint[0]));

View File

@ -15,7 +15,7 @@ SBsp3 *SBsp3::FromMesh(SMesh *m) {
SBsp3 *bsp3 = NULL; SBsp3 *bsp3 = NULL;
int i; int i;
SMesh mc; ZERO(&mc); SMesh mc = {};
for(i = 0; i < m->l.n; i++) { for(i = 0; i < m->l.n; i++) {
mc.AddTriangle(&(m->l.elem[i])); mc.AddTriangle(&(m->l.elem[i]));
} }
@ -288,8 +288,7 @@ SBsp3 *SBsp3::Insert(STriangle *tr, SMesh *instead) {
double dt[3] = { (tr->a).Dot(n), (tr->b).Dot(n), (tr->c).Dot(n) }; double dt[3] = { (tr->a).Dot(n), (tr->b).Dot(n), (tr->c).Dot(n) };
int inc = 0, posc = 0, negc = 0; int inc = 0, posc = 0, negc = 0;
bool isPos[3], isNeg[3], isOn[3]; bool isPos[3] = {}, isNeg[3] = {}, isOn[3] = {};
ZERO(&isPos); ZERO(&isNeg); ZERO(&isOn);
// Count vertices in the plane // Count vertices in the plane
for(int i = 0; i < 3; i++) { for(int i = 0; i < 3; i++) {
if(fabs(dt[i] - d) < LENGTH_EPS) { if(fabs(dt[i] - d) < LENGTH_EPS) {
@ -492,8 +491,7 @@ SBsp2 *SBsp2::InsertEdge(SEdge *nedge, Vector nnp, Vector out) {
double dt[2] = { (nedge->a).Dot(no), (nedge->b).Dot(no) }; double dt[2] = { (nedge->a).Dot(no), (nedge->b).Dot(no) };
bool isPos[2], isNeg[2], isOn[2]; bool isPos[2] = {}, isNeg[2] = {}, isOn[2] = {};
ZERO(&isPos); ZERO(&isNeg); ZERO(&isOn);
for(int i = 0; i < 2; i++) { for(int i = 0; i < 2; i++) {
if(fabs(dt[i] - d) < LENGTH_EPS) { if(fabs(dt[i] - d) < LENGTH_EPS) {
isOn[i] = true; isOn[i] = true;
@ -570,9 +568,8 @@ void SBsp2::InsertTriangleHow(int how, STriangle *tr, SMesh *m, SBsp3 *bsp3) {
void SBsp2::InsertTriangle(STriangle *tr, SMesh *m, SBsp3 *bsp3) { void SBsp2::InsertTriangle(STriangle *tr, SMesh *m, SBsp3 *bsp3) {
double dt[3] = { (tr->a).Dot(no), (tr->b).Dot(no), (tr->c).Dot(no) }; double dt[3] = { (tr->a).Dot(no), (tr->b).Dot(no), (tr->c).Dot(no) };
bool isPos[3], isNeg[3], isOn[3]; bool isPos[3] = {}, isNeg[3] = {}, isOn[3] = {};
int inc = 0, posc = 0, negc = 0; int inc = 0, posc = 0, negc = 0;
ZERO(&isPos); ZERO(&isNeg); ZERO(&isOn);
for(int i = 0; i < 3; i++) { for(int i = 0; i < 3; i++) {
if(fabs(dt[i] - d) < LENGTH_EPS) { if(fabs(dt[i] - d) < LENGTH_EPS) {
isOn[i] = true; isOn[i] = true;

View File

@ -82,8 +82,7 @@ void GraphicsWindow::CopySelection(void) {
} }
if(req == Request::WORKPLANE) continue; if(req == Request::WORKPLANE) continue;
ClipboardRequest cr; ClipboardRequest cr = {};
ZERO(&cr);
cr.type = req; cr.type = req;
cr.extraPoints = e->extraPoints; cr.extraPoints = e->extraPoints;
cr.style = e->style; cr.style = e->style;

View File

@ -1063,8 +1063,7 @@ void SolveSpace::LoadAllFontFiles(void) {
CFURLRef url = (CFURLRef)CTFontDescriptorCopyAttribute(fontRef, kCTFontURLAttribute); CFURLRef url = (CFURLRef)CTFontDescriptorCopyAttribute(fontRef, kCTFontURLAttribute);
NSString *fontPath = [NSString stringWithString:[(NSURL *)CFBridgingRelease(url) path]]; NSString *fontPath = [NSString stringWithString:[(NSURL *)CFBridgingRelease(url) path]];
if([[fontPath pathExtension] isEqual:@"ttf"]) { if([[fontPath pathExtension] isEqual:@"ttf"]) {
TtfFont tf; TtfFont tf = {};
ZERO(&tf);
strcpy(tf.fontFile, [[NSFileManager defaultManager] strcpy(tf.fontFile, [[NSFileManager defaultManager]
fileSystemRepresentationWithPath:fontPath]); fileSystemRepresentationWithPath:fontPath]);
SS.fonts.l.Add(&tf); SS.fonts.l.Add(&tf);

View File

@ -94,8 +94,7 @@ void Constraint::Constrain(int type, hEntity ptA, hEntity ptB,
hEntity entityA, hEntity entityB, hEntity entityA, hEntity entityB,
bool other, bool other2) bool other, bool other2)
{ {
Constraint c; Constraint c = {};
memset(&c, 0, sizeof(c));
c.group = SS.GW.activeGroup; c.group = SS.GW.activeGroup;
c.workplane = SS.GW.ActiveWorkplane(); c.workplane = SS.GW.ActiveWorkplane();
c.type = type; c.type = type;
@ -116,8 +115,7 @@ void Constraint::ConstrainCoincident(hEntity ptA, hEntity ptB) {
} }
void Constraint::MenuConstrain(int id) { void Constraint::MenuConstrain(int id) {
Constraint c; Constraint c = {};
ZERO(&c);
c.group = SS.GW.activeGroup; c.group = SS.GW.activeGroup;
c.workplane = SS.GW.ActiveWorkplane(); c.workplane = SS.GW.ActiveWorkplane();

View File

@ -179,9 +179,7 @@ void ConstraintBase::ModifyToSatisfy(void) {
} 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.
IdList<Equation,hEquation> l; IdList<Equation,hEquation> l = {};
// An uninit IdList could lead us to free some random address, bad.
ZERO(&l);
// Generate the equations even if this is a reference dimension // Generate the equations even if this is a reference dimension
GenerateReal(&l); GenerateReal(&l);
if(l.n != 1) oops(); if(l.n != 1) oops();

View File

@ -99,8 +99,7 @@ void GraphicsWindow::ClearNonexistentSelectionItems(void) {
// Is this entity/constraint selected? // Is this entity/constraint selected?
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool GraphicsWindow::IsSelected(hEntity he) { bool GraphicsWindow::IsSelected(hEntity he) {
Selection s; Selection s = {};
ZERO(&s);
s.entity = he; s.entity = he;
return IsSelected(&s); return IsSelected(&s);
} }
@ -121,8 +120,7 @@ bool GraphicsWindow::IsSelected(Selection *st) {
// would otherwise be impossible to de-select the lower of the two. // would otherwise be impossible to de-select the lower of the two.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void GraphicsWindow::MakeUnselected(hEntity he, bool coincidentPointTrick) { void GraphicsWindow::MakeUnselected(hEntity he, bool coincidentPointTrick) {
Selection stog; Selection stog = {};
ZERO(&stog);
stog.entity = he; stog.entity = he;
MakeUnselected(&stog, coincidentPointTrick); MakeUnselected(&stog, coincidentPointTrick);
} }
@ -164,8 +162,7 @@ void GraphicsWindow::MakeUnselected(Selection *stog, bool coincidentPointTrick){
// Select an item, if it isn't selected already. // Select an item, if it isn't selected already.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void GraphicsWindow::MakeSelected(hEntity he) { void GraphicsWindow::MakeSelected(hEntity he) {
Selection stog; Selection stog = {};
ZERO(&stog);
stog.entity = he; stog.entity = he;
MakeSelected(&stog); MakeSelected(&stog);
} }
@ -225,8 +222,7 @@ void GraphicsWindow::SelectByMarquee(void) {
// includes the z = 0 plane. // includes the z = 0 plane.
Vector ptMin = Vector::From(xmin, ymin, -1), Vector ptMin = Vector::From(xmin, ymin, -1),
ptMax = Vector::From(xmax, ymax, 1); ptMax = Vector::From(xmax, ymax, 1);
SEdgeList sel; SEdgeList sel = {};
ZERO(&sel);
e->GenerateEdges(&sel, true); e->GenerateEdges(&sel, true);
SEdge *se; SEdge *se;
for(se = sel.l.First(); se; se = sel.l.NextAfter(se)) { for(se = sel.l.First(); se; se = sel.l.NextAfter(se)) {
@ -254,7 +250,7 @@ void GraphicsWindow::SelectByMarquee(void) {
// lines, etc.), and so on. // lines, etc.), and so on.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void GraphicsWindow::GroupSelection(void) { void GraphicsWindow::GroupSelection(void) {
memset(&gs, 0, sizeof(gs)); gs = {};
int i; int i;
for(i = 0; i < selection.n && i < MAX_SELECTED; i++) { for(i = 0; i < selection.n && i < MAX_SELECTED; i++) {
Selection *s = &(selection.elem[i]); Selection *s = &(selection.elem[i]);
@ -321,8 +317,7 @@ void GraphicsWindow::GroupSelection(void) {
void GraphicsWindow::HitTestMakeSelection(Point2d mp) { void GraphicsWindow::HitTestMakeSelection(Point2d mp) {
int i; int i;
double d, dmin = 1e12; double d, dmin = 1e12;
Selection s; Selection s = {};
ZERO(&s);
// Always do the entities; we might be dragging something that should // Always do the entities; we might be dragging something that should
// be auto-constrained, and we need the hover for that. // be auto-constrained, and we need the hover for that.
@ -343,7 +338,7 @@ void GraphicsWindow::HitTestMakeSelection(Point2d mp) {
d = e->GetDistance(mp); d = e->GetDistance(mp);
if(d < 10 && d < dmin) { if(d < 10 && d < dmin) {
memset(&s, 0, sizeof(s)); s = {};
s.entity = e->h; s.entity = e->h;
dmin = d; dmin = d;
} }
@ -355,7 +350,7 @@ void GraphicsWindow::HitTestMakeSelection(Point2d mp) {
for(i = 0; i < SK.constraint.n; i++) { for(i = 0; i < SK.constraint.n; i++) {
d = SK.constraint.elem[i].GetDistance(mp); d = SK.constraint.elem[i].GetDistance(mp);
if(d < 10 && d < dmin) { if(d < 10 && d < dmin) {
memset(&s, 0, sizeof(s)); s = {};
s.constraint = SK.constraint.elem[i].h; s.constraint = SK.constraint.elem[i].h;
dmin = d; dmin = d;
} }
@ -714,8 +709,7 @@ nogrid:;
SuggestedConstraint suggested = SuggestedConstraint suggested =
SS.GW.SuggestLineConstraint(SS.GW.pending.request); SS.GW.SuggestLineConstraint(SS.GW.pending.request);
if(suggested != GraphicsWindow::SUGGESTED_NONE) { if(suggested != GraphicsWindow::SUGGESTED_NONE) {
Constraint c; Constraint c = {};
ZERO(&c);
c.group = SS.GW.activeGroup; c.group = SS.GW.activeGroup;
c.workplane = SS.GW.ActiveWorkplane(); c.workplane = SS.GW.ActiveWorkplane();
c.type = suggested; c.type = suggested;

View File

@ -124,16 +124,14 @@ void Entity::Draw(void) {
void Entity::GenerateEdges(SEdgeList *el, bool includingConstruction) { void Entity::GenerateEdges(SEdgeList *el, bool includingConstruction) {
if(construction && !includingConstruction) return; if(construction && !includingConstruction) return;
SBezierList sbl; SBezierList sbl = {};
ZERO(&sbl);
GenerateBezierCurves(&sbl); GenerateBezierCurves(&sbl);
int i, j; int i, j;
for(i = 0; i < sbl.l.n; i++) { for(i = 0; i < sbl.l.n; i++) {
SBezier *sb = &(sbl.l.elem[i]); SBezier *sb = &(sbl.l.elem[i]);
List<Vector> lv; List<Vector> lv = {};
ZERO(&lv);
sb->MakePwlInto(&lv); sb->MakePwlInto(&lv);
for(j = 1; j < lv.n; j++) { for(j = 1; j < lv.n; j++) {
el->AddEdge(lv.elem[j-1], lv.elem[j], style.v); el->AddEdge(lv.elem[j-1], lv.elem[j], style.v);
@ -266,8 +264,7 @@ void Entity::ComputeInterpolatingSpline(SBezierList *sbl, bool periodic) {
// f''(0) = 6*(P0 - 2*P1 + P2) // f''(0) = 6*(P0 - 2*P1 + P2)
// f''(1) = 6*(P3 - 2*P2 + P1) // f''(1) = 6*(P3 - 2*P2 + P1)
for(a = 0; a < 3; a++) { for(a = 0; a < 3; a++) {
BandedMatrix bm; BandedMatrix bm = {};
ZERO(&bm);
bm.n = n; bm.n = n;
for(i = 0; i < n; i++) { for(i = 0; i < n; i++) {
@ -650,8 +647,7 @@ void Entity::DrawOrGetDistance(void) {
// And draw the curves; generate the rational polynomial curves for // And draw the curves; generate the rational polynomial curves for
// everything, then piecewise linearize them, and display those. // everything, then piecewise linearize them, and display those.
SEdgeList sel; SEdgeList sel = {};
ZERO(&sel);
GenerateEdges(&sel, true); GenerateEdges(&sel, true);
int i; int i;
for(i = 0; i < sel.l.n; i++) { for(i = 0; i < sel.l.n; i++) {

View File

@ -71,10 +71,8 @@ void SolveSpaceUI::ExportSectionTo(const char *filename) {
n = n.WithMagnitude(1); n = n.WithMagnitude(1);
d = origin.Dot(n); d = origin.Dot(n);
SEdgeList el; SEdgeList el = {};
ZERO(&el); SBezierList bl = {};
SBezierList bl;
ZERO(&bl);
// If there's a mesh, then grab the edges from it. // If there's a mesh, then grab the edges from it.
g->runningMesh.MakeEdgesInPlaneInto(&el, n, d); g->runningMesh.MakeEdgesInPlaneInto(&el, n, d);
@ -111,10 +109,8 @@ void SolveSpaceUI::ExportSectionTo(const char *filename) {
void SolveSpaceUI::ExportViewOrWireframeTo(const char *filename, bool wireframe) { void SolveSpaceUI::ExportViewOrWireframeTo(const char *filename, bool wireframe) {
int i; int i;
SEdgeList edges; SEdgeList edges = {};
ZERO(&edges); SBezierList beziers = {};
SBezierList beziers;
ZERO(&beziers);
SMesh *sm = NULL; SMesh *sm = NULL;
if(SS.GW.showShaded) { if(SS.GW.showShaded) {
@ -197,8 +193,7 @@ void SolveSpaceUI::ExportViewOrWireframeTo(const char *filename, bool wireframe)
void SolveSpaceUI::ExportWireframeCurves(SEdgeList *sel, SBezierList *sbl, void SolveSpaceUI::ExportWireframeCurves(SEdgeList *sel, SBezierList *sbl,
VectorFileWriter *out) VectorFileWriter *out)
{ {
SBezierLoopSetSet sblss; SBezierLoopSetSet sblss = {};
ZERO(&sblss);
SEdge *se; SEdge *se;
for(se = sel->l.First(); se; se = sel->l.NextAfter(se)) { for(se = sel->l.First(); se; se = sel->l.NextAfter(se)) {
SBezier sb = SBezier::From( SBezier sb = SBezier::From(
@ -247,13 +242,11 @@ void SolveSpaceUI::ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *s
// If cutter radius compensation is requested, then perform it now // If cutter radius compensation is requested, then perform it now
if(fabs(SS.exportOffset) > LENGTH_EPS) { if(fabs(SS.exportOffset) > LENGTH_EPS) {
// assemble those edges into a polygon, and clear the edge list // assemble those edges into a polygon, and clear the edge list
SPolygon sp; SPolygon sp = {};
ZERO(&sp);
sel->AssemblePolygon(&sp, NULL); sel->AssemblePolygon(&sp, NULL);
sel->Clear(); sel->Clear();
SPolygon compd; SPolygon compd = {};
ZERO(&compd);
sp.normal = Vector::From(0, 0, -1); sp.normal = Vector::From(0, 0, -1);
sp.FixContourDirections(); sp.FixContourDirections();
sp.OffsetInto(&compd, SS.exportOffset*s); sp.OffsetInto(&compd, SS.exportOffset*s);
@ -265,8 +258,7 @@ void SolveSpaceUI::ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *s
// Now the triangle mesh; project, then build a BSP to perform // Now the triangle mesh; project, then build a BSP to perform
// occlusion testing and generated the shaded surfaces. // occlusion testing and generated the shaded surfaces.
SMesh smp; SMesh smp = {};
ZERO(&smp);
if(sm) { if(sm) {
Vector l0 = (SS.lightDir[0]).WithMagnitude(1), Vector l0 = (SS.lightDir[0]).WithMagnitude(1),
l1 = (SS.lightDir[1]).WithMagnitude(1); l1 = (SS.lightDir[1]).WithMagnitude(1);
@ -292,8 +284,7 @@ void SolveSpaceUI::ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *s
// Use the BSP routines to generate the split triangles in paint order. // Use the BSP routines to generate the split triangles in paint order.
SBsp3 *bsp = SBsp3::FromMesh(&smp); SBsp3 *bsp = SBsp3::FromMesh(&smp);
SMesh sms; SMesh sms = {};
ZERO(&sms);
bsp->GenerateInPaintOrder(&sms); bsp->GenerateInPaintOrder(&sms);
// And cull the back-facing triangles // And cull the back-facing triangles
STriangle *tr; STriangle *tr;
@ -307,8 +298,7 @@ void SolveSpaceUI::ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *s
sms.l.RemoveTagged(); sms.l.RemoveTagged();
// And now we perform hidden line removal if requested // And now we perform hidden line removal if requested
SEdgeList hlrd; SEdgeList hlrd = {};
ZERO(&hlrd);
if(sm && !SS.GW.showHdnLines) { if(sm && !SS.GW.showHdnLines) {
SKdNode *root = SKdNode::From(&smp); SKdNode *root = SKdNode::From(&smp);
@ -331,8 +321,7 @@ void SolveSpaceUI::ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *s
continue; continue;
} }
SEdgeList out; SEdgeList out = {};
ZERO(&out);
// Split the original edge against the mesh // Split the original edge against the mesh
out.AddEdge(se->a, se->b, se->auxA); out.AddEdge(se->a, se->b, se->auxA);
root->OcclusionTestLine(*se, &out, cnt); root->OcclusionTestLine(*se, &out, cnt);
@ -366,15 +355,12 @@ void SolveSpaceUI::ExportLinesAndMesh(SEdgeList *sel, SBezierList *sbl, SMesh *s
// If possible, then we will assemble these output curves into loops. They // If possible, then we will assemble these output curves into loops. They
// will then get exported as closed paths. // will then get exported as closed paths.
SBezierLoopSetSet sblss; SBezierLoopSetSet sblss = {};
ZERO(&sblss); SBezierList leftovers = {};
SBezierList leftovers;
ZERO(&leftovers);
SSurface srf = SSurface::FromPlane(Vector::From(0, 0, 0), SSurface srf = SSurface::FromPlane(Vector::From(0, 0, 0),
Vector::From(1, 0, 0), Vector::From(1, 0, 0),
Vector::From(0, 1, 0)); Vector::From(0, 1, 0));
SPolygon spxyz; SPolygon spxyz = {};
ZERO(&spxyz);
bool allClosed; bool allClosed;
SEdge notClosedAt; SEdge notClosedAt;
sbl->l.ClearTags(); sbl->l.ClearTags();
@ -522,8 +508,7 @@ void VectorFileWriter::Output(SBezierLoopSetSet *sblss, SMesh *sm) {
} }
void VectorFileWriter::BezierAsPwl(SBezier *sb) { void VectorFileWriter::BezierAsPwl(SBezier *sb) {
List<Vector> lv; List<Vector> lv = {};
ZERO(&lv);
sb->MakePwlInto(&lv, SS.ChordTolMm() / SS.exportScale); sb->MakePwlInto(&lv, SS.ChordTolMm() / SS.exportScale);
int i; int i;
for(i = 1; i < lv.n; i++) { for(i = 1; i < lv.n; i++) {
@ -606,8 +591,7 @@ void SolveSpaceUI::ExportMeshTo(const char *filename) {
// not self-intersecting, so not much to do. // not self-intersecting, so not much to do.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void SolveSpaceUI::ExportMeshAsStlTo(FILE *f, SMesh *sm) { void SolveSpaceUI::ExportMeshAsStlTo(FILE *f, SMesh *sm) {
char str[80]; char str[80] = {};
memset(str, 0, sizeof(str));
strcpy(str, "STL exported mesh"); strcpy(str, "STL exported mesh");
fwrite(str, 1, 80, f); fwrite(str, 1, 80, f);
@ -642,8 +626,7 @@ void SolveSpaceUI::ExportMeshAsStlTo(FILE *f, SMesh *sm) {
// identical vertices to the same identifier, so do that first. // identical vertices to the same identifier, so do that first.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void SolveSpaceUI::ExportMeshAsObjTo(FILE *f, SMesh *sm) { void SolveSpaceUI::ExportMeshAsObjTo(FILE *f, SMesh *sm) {
SPointList spl; SPointList spl = {};
ZERO(&spl);
STriangle *tr; STriangle *tr;
for(tr = sm->l.First(); tr; tr = sm->l.NextAfter(tr)) { for(tr = sm->l.First(); tr; tr = sm->l.NextAfter(tr)) {
spl.IncrementTagFor(tr->a); spl.IncrementTagFor(tr->a);
@ -678,8 +661,7 @@ void SolveSpaceUI::ExportMeshAsObjTo(FILE *f, SMesh *sm) {
void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const char * filename, SMesh *sm, void SolveSpaceUI::ExportMeshAsThreeJsTo(FILE *f, const char * filename, SMesh *sm,
SEdgeList *sel) SEdgeList *sel)
{ {
SPointList spl; SPointList spl = {};
ZERO(&spl);
STriangle *tr; STriangle *tr;
SEdge *e; SEdge *e;
Vector bndl, bndh; Vector bndl, bndh;

View File

@ -119,8 +119,7 @@ int StepFileWriter::ExportCurve(SBezier *sb) {
int StepFileWriter::ExportCurveLoop(SBezierLoop *loop, bool inner) { int StepFileWriter::ExportCurveLoop(SBezierLoop *loop, bool inner) {
if(loop->l.n < 1) oops(); if(loop->l.n < 1) oops();
List<int> listOfTrims; List<int> listOfTrims = {};
ZERO(&listOfTrims);
SBezier *sb = &(loop->l.elem[loop->l.n - 1]); SBezier *sb = &(loop->l.elem[loop->l.n - 1]);
@ -229,10 +228,8 @@ void StepFileWriter::ExportSurface(SSurface *ss, SBezierList *sbl) {
// Now we do the trim curves. We must group each outer loop separately // Now we do the trim curves. We must group each outer loop separately
// along with its inner faces, so do that now. // along with its inner faces, so do that now.
SBezierLoopSetSet sblss; SBezierLoopSetSet sblss = {};
ZERO(&sblss); SPolygon spxyz = {};
SPolygon spxyz;
ZERO(&spxyz);
bool allClosed; bool allClosed;
SEdge notClosedAt; SEdge notClosedAt;
// We specify a surface, so it doesn't check for coplanarity; and we // We specify a surface, so it doesn't check for coplanarity; and we
@ -252,8 +249,7 @@ void StepFileWriter::ExportSurface(SSurface *ss, SBezierList *sbl) {
for(sbls = sblss.l.First(); sbls; sbls = sblss.l.NextAfter(sbls)) { for(sbls = sblss.l.First(); sbls; sbls = sblss.l.NextAfter(sbls)) {
SBezierLoop *loop = sbls->l.First(); SBezierLoop *loop = sbls->l.First();
List<int> listOfLoops; List<int> listOfLoops = {};
ZERO(&listOfLoops);
// Create the face outer boundary from the outer loop. // Create the face outer boundary from the outer loop.
int fob = ExportCurveLoop(loop, false); int fob = ExportCurveLoop(loop, false);
listOfLoops.Add(&fob); listOfLoops.Add(&fob);
@ -318,7 +314,7 @@ void StepFileWriter::ExportSurfacesTo(char *file) {
WriteHeader(); WriteHeader();
WriteProductHeader(); WriteProductHeader();
ZERO(&advancedFaces); advancedFaces = {};
SSurface *ss; SSurface *ss;
for(ss = shell->surface.First(); ss; ss = shell->surface.NextAfter(ss)) { for(ss = shell->surface.First(); ss; ss = shell->surface.NextAfter(ss)) {
@ -327,8 +323,7 @@ void StepFileWriter::ExportSurfacesTo(char *file) {
// Get all of the loops of Beziers that trim our surface (with each // Get all of the loops of Beziers that trim our surface (with each
// Bezier split so that we use the section as t goes from 0 to 1), and // Bezier split so that we use the section as t goes from 0 to 1), and
// the piecewise linearization of those loops in xyz space. // the piecewise linearization of those loops in xyz space.
SBezierList sbl; SBezierList sbl = {};
ZERO(&sbl);
ss->MakeSectionEdgesInto(shell, NULL, &sbl); ss->MakeSectionEdgesInto(shell, NULL, &sbl);
// Apply the export scale factor. // Apply the export scale factor.

View File

@ -626,7 +626,7 @@ void HpglFileWriter::FinishAndCloseFile(void) {
// set in the configuration screen. // set in the configuration screen.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void GCodeFileWriter::StartFile(void) { void GCodeFileWriter::StartFile(void) {
ZERO(&sel); sel = {};
} }
void GCodeFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth, void GCodeFileWriter::StartPath(RgbaColor strokeRgb, double lineWidth,
bool filled, RgbaColor fillRgb) bool filled, RgbaColor fillRgb)
@ -648,8 +648,7 @@ void GCodeFileWriter::Bezier(SBezier *sb) {
} }
void GCodeFileWriter::FinishAndCloseFile(void) { void GCodeFileWriter::FinishAndCloseFile(void) {
SPolygon sp; SPolygon sp = {};
ZERO(&sp);
sel.AssemblePolygon(&sp, NULL); sel.AssemblePolygon(&sp, NULL);
int i; int i;
@ -689,7 +688,7 @@ void GCodeFileWriter::FinishAndCloseFile(void) {
// can also be used for surfaces or 3d curves. // can also be used for surfaces or 3d curves.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void Step2dFileWriter::StartFile(void) { void Step2dFileWriter::StartFile(void) {
ZERO(&sfw); sfw = {};
sfw.f = f; sfw.f = f;
sfw.WriteHeader(); sfw.WriteHeader();
} }

View File

@ -35,8 +35,7 @@ void SolveSpaceUI::ClearExisting(void) {
} }
hGroup SolveSpaceUI::CreateDefaultDrawingGroup(void) { hGroup SolveSpaceUI::CreateDefaultDrawingGroup(void) {
Group g; Group g = {};
ZERO(&g);
// And an empty group, for the first stuff the user draws. // And an empty group, for the first stuff the user draws.
g.visible = true; g.visible = true;
@ -55,8 +54,7 @@ void SolveSpaceUI::NewFile(void) {
ClearExisting(); ClearExisting();
// Our initial group, that contains the references. // Our initial group, that contains the references.
Group g; Group g = {};
memset(&g, 0, sizeof(g));
g.visible = true; g.visible = true;
g.name.strcpy("#references"); g.name.strcpy("#references");
g.type = Group::DRAWING_3D; g.type = Group::DRAWING_3D;
@ -65,8 +63,7 @@ void SolveSpaceUI::NewFile(void) {
// Let's create three two-d coordinate systems, for the coordinate // Let's create three two-d coordinate systems, for the coordinate
// planes; these are our references, present in every sketch. // planes; these are our references, present in every sketch.
Request r; Request r = {};
ZERO(&r);
r.type = Request::WORKPLANE; r.type = Request::WORKPLANE;
r.group = Group::HGROUP_REFERENCES; r.group = Group::HGROUP_REFERENCES;
r.workplane = Entity::FREE_IN_3D; r.workplane = Entity::FREE_IN_3D;
@ -396,7 +393,7 @@ void SolveSpaceUI::LoadUsingTable(char *key, char *val) {
// makes a shallow copy, so that would result in us // makes a shallow copy, so that would result in us
// freeing memory that we want to keep around. Just // freeing memory that we want to keep around. Just
// zero it out so that new memory is allocated. // zero it out so that new memory is allocated.
memset(&(p->M), 0, sizeof(p->M)); p->M = {};
for(;;) { for(;;) {
EntityMap em; EntityMap em;
char line2[1024]; char line2[1024];
@ -435,7 +432,7 @@ bool SolveSpaceUI::LoadFromFile(const char *filename) {
ClearExisting(); ClearExisting();
memset(&sv, 0, sizeof(sv)); sv = {};
sv.g.scale = 1; // default is 1, not 0; so legacy files need this sv.g.scale = 1; // default is 1, not 0; so legacy files need this
char line[1024]; char line[1024];
@ -456,24 +453,24 @@ bool SolveSpaceUI::LoadFromFile(const char *filename) {
LoadUsingTable(key, val); LoadUsingTable(key, val);
} else if(strcmp(line, "AddGroup")==0) { } else if(strcmp(line, "AddGroup")==0) {
SK.group.Add(&(sv.g)); SK.group.Add(&(sv.g));
ZERO(&(sv.g)); sv.g = {};
sv.g.scale = 1; // default is 1, not 0; so legacy files need this sv.g.scale = 1; // default is 1, not 0; so legacy files need this
} else if(strcmp(line, "AddParam")==0) { } else if(strcmp(line, "AddParam")==0) {
// params are regenerated, but we want to preload the values // params are regenerated, but we want to preload the values
// for initial guesses // for initial guesses
SK.param.Add(&(sv.p)); SK.param.Add(&(sv.p));
ZERO(&(sv.p)); sv.p = {};
} else if(strcmp(line, "AddEntity")==0) { } else if(strcmp(line, "AddEntity")==0) {
// entities are regenerated // entities are regenerated
} else if(strcmp(line, "AddRequest")==0) { } else if(strcmp(line, "AddRequest")==0) {
SK.request.Add(&(sv.r)); SK.request.Add(&(sv.r));
ZERO(&(sv.r)); sv.r = {};
} else if(strcmp(line, "AddConstraint")==0) { } else if(strcmp(line, "AddConstraint")==0) {
SK.constraint.Add(&(sv.c)); SK.constraint.Add(&(sv.c));
ZERO(&(sv.c)); sv.c = {};
} else if(strcmp(line, "AddStyle")==0) { } else if(strcmp(line, "AddStyle")==0) {
SK.style.Add(&(sv.s)); SK.style.Add(&(sv.s));
ZERO(&(sv.s)); sv.s = {};
} else if(strcmp(line, VERSION_STRING)==0) { } else if(strcmp(line, VERSION_STRING)==0) {
// do nothing, version string // do nothing, version string
} else if(StrStartsWith(line, "Triangle ") || } else if(StrStartsWith(line, "Triangle ") ||
@ -507,18 +504,16 @@ bool SolveSpaceUI::LoadFromFile(const char *filename) {
} }
bool SolveSpaceUI::LoadEntitiesFromFile(const char *file, EntityList *le, bool SolveSpaceUI::LoadEntitiesFromFile(const char *file, EntityList *le,
SMesh *m, SShell *sh) SMesh *m, SShell *sh)
{ {
SSurface srf; SSurface srf = {};
ZERO(&srf); SCurve crv = {};
SCurve crv;
ZERO(&crv);
fh = fopen(file, "rb"); fh = fopen(file, "rb");
if(!fh) return false; if(!fh) return false;
le->Clear(); le->Clear();
memset(&sv, 0, sizeof(sv)); sv = {};
char line[1024]; char line[1024];
while(fgets(line, (int)sizeof(line), fh)) { while(fgets(line, (int)sizeof(line), fh)) {
@ -544,7 +539,7 @@ bool SolveSpaceUI::LoadEntitiesFromFile(const char *file, EntityList *le,
} else if(strcmp(line, "AddEntity")==0) { } else if(strcmp(line, "AddEntity")==0) {
le->Add(&(sv.e)); le->Add(&(sv.e));
memset(&(sv.e), 0, sizeof(sv.e)); sv.e = {};
} else if(strcmp(line, "AddRequest")==0) { } else if(strcmp(line, "AddRequest")==0) {
} else if(strcmp(line, "AddConstraint")==0) { } else if(strcmp(line, "AddConstraint")==0) {
@ -554,7 +549,7 @@ bool SolveSpaceUI::LoadEntitiesFromFile(const char *file, EntityList *le,
} else if(strcmp(line, VERSION_STRING)==0) { } else if(strcmp(line, VERSION_STRING)==0) {
} else if(StrStartsWith(line, "Triangle ")) { } else if(StrStartsWith(line, "Triangle ")) {
STriangle tr; ZERO(&tr); STriangle tr = {};
unsigned int rgba = 0; unsigned int rgba = 0;
if(sscanf(line, "Triangle %x %x " if(sscanf(line, "Triangle %x %x "
"%lf %lf %lf %lf %lf %lf %lf %lf %lf", "%lf %lf %lf %lf %lf %lf %lf %lf %lf",
@ -586,8 +581,7 @@ bool SolveSpaceUI::LoadEntitiesFromFile(const char *file, EntityList *le,
srf.ctrl[i][j] = c; srf.ctrl[i][j] = c;
srf.weight[i][j] = w; srf.weight[i][j] = w;
} else if(StrStartsWith(line, "TrimBy ")) { } else if(StrStartsWith(line, "TrimBy ")) {
STrimBy stb; STrimBy stb = {};
ZERO(&stb);
int backwards; int backwards;
if(sscanf(line, "TrimBy %x %d %lf %lf %lf %lf %lf %lf", if(sscanf(line, "TrimBy %x %d %lf %lf %lf %lf %lf %lf",
&(stb.curve.v), &backwards, &(stb.curve.v), &backwards,
@ -600,7 +594,7 @@ bool SolveSpaceUI::LoadEntitiesFromFile(const char *file, EntityList *le,
srf.trim.Add(&stb); srf.trim.Add(&stb);
} else if(strcmp(line, "AddSurface")==0) { } else if(strcmp(line, "AddSurface")==0) {
sh->surface.Add(&srf); sh->surface.Add(&srf);
ZERO(&srf); srf = {};
} else if(StrStartsWith(line, "Curve ")) { } else if(StrStartsWith(line, "Curve ")) {
int isExact; int isExact;
if(sscanf(line, "Curve %x %d %d %x %x", if(sscanf(line, "Curve %x %d %d %x %x",
@ -636,7 +630,7 @@ bool SolveSpaceUI::LoadEntitiesFromFile(const char *file, EntityList *le,
crv.pts.Add(&scpt); crv.pts.Add(&scpt);
} else if(strcmp(line, "AddCurve")==0) { } else if(strcmp(line, "AddCurve")==0) {
sh->curve.Add(&crv); sh->curve.Add(&crv);
ZERO(&crv); crv = {};
} else { } else {
oops(); oops();
} }

View File

@ -175,7 +175,7 @@ void SolveSpaceUI::GenerateAll(int first, int last, bool andFindFree) {
; ;
// Don't lose our numerical guesses when we regenerate. // Don't lose our numerical guesses when we regenerate.
IdList<Param,hParam> prev; IdList<Param,hParam> prev = {};
SK.param.MoveSelfInto(&prev); SK.param.MoveSelfInto(&prev);
SK.entity.Clear(); SK.entity.Clear();
@ -336,7 +336,8 @@ void SolveSpaceUI::GenerateAll(int first, int last, bool andFindFree) {
deleted.constraints, deleted.constraints == 1 ? "" : "s", deleted.constraints, deleted.constraints == 1 ? "" : "s",
deleted.groups, deleted.groups == 1 ? "" : "s"); deleted.groups, deleted.groups == 1 ? "" : "s");
} }
memset(&deleted, 0, sizeof(deleted));
deleted = {};
} }
FreeAllTemporary(); FreeAllTemporary();

View File

@ -215,8 +215,6 @@ bool SolveSpace::MakeAcceleratorLabel(int accel, char *out) {
} }
void GraphicsWindow::Init(void) { void GraphicsWindow::Init(void) {
memset(this, 0, sizeof(*this));
scale = 5; scale = 5;
offset = Vector::From(0, 0, 0); offset = Vector::From(0, 0, 0);
projRight = Vector::From(1, 0, 0); projRight = Vector::From(1, 0, 0);

View File

@ -37,8 +37,7 @@ void Group::Clear(void) {
} }
void Group::AddParam(IdList<Param,hParam> *param, hParam hp, double v) { void Group::AddParam(IdList<Param,hParam> *param, hParam hp, double v) {
Param pa; Param pa = {};
memset(&pa, 0, sizeof(pa));
pa.h = hp; pa.h = hp;
pa.val = v; pa.val = v;
@ -52,8 +51,7 @@ bool Group::IsVisible(void) {
} }
void Group::MenuGroup(int id) { void Group::MenuGroup(int id) {
Group g; Group g = {};
ZERO(&g);
g.visible = true; g.visible = true;
g.color = RGBi(100, 100, 100); g.color = RGBi(100, 100, 100);
g.scale = 1; g.scale = 1;
@ -326,8 +324,7 @@ void Group::Generate(IdList<Entity,hEntity> *entity,
q = predef.q; q = predef.q;
} else oops(); } else oops();
Entity normal; Entity normal = {};
memset(&normal, 0, sizeof(normal));
normal.type = Entity::NORMAL_N_COPY; normal.type = Entity::NORMAL_N_COPY;
normal.numNormal = q; normal.numNormal = q;
normal.point[0] = h.entity(2); normal.point[0] = h.entity(2);
@ -335,16 +332,14 @@ void Group::Generate(IdList<Entity,hEntity> *entity,
normal.h = h.entity(1); normal.h = h.entity(1);
entity->Add(&normal); entity->Add(&normal);
Entity point; Entity point = {};
memset(&point, 0, sizeof(point));
point.type = Entity::POINT_N_COPY; point.type = Entity::POINT_N_COPY;
point.numPoint = SK.GetEntity(predef.origin)->PointGetNum(); point.numPoint = SK.GetEntity(predef.origin)->PointGetNum();
point.group = h; point.group = h;
point.h = h.entity(2); point.h = h.entity(2);
entity->Add(&point); entity->Add(&point);
Entity wp; Entity wp = {};
memset(&wp, 0, sizeof(wp));
wp.type = Entity::WORKPLANE; wp.type = Entity::WORKPLANE;
wp.normal = normal.h; wp.normal = normal.h;
wp.point[0] = point.h; wp.point[0] = point.h;
@ -489,8 +484,7 @@ void Group::AddEq(IdList<Equation,hEquation> *l, Expr *expr, int index) {
} }
void Group::GenerateEquations(IdList<Equation,hEquation> *l) { void Group::GenerateEquations(IdList<Equation,hEquation> *l) {
Equation eq; Equation eq = {};
ZERO(&eq);
if(type == IMPORTED) { if(type == IMPORTED) {
// Normalize the quaternion // Normalize the quaternion
ExprQuaternion q = { ExprQuaternion q = {
@ -573,8 +567,7 @@ hEntity Group::Remap(hEntity in, int copyNumber) {
void Group::MakeExtrusionLines(IdList<Entity,hEntity> *el, hEntity in) { void Group::MakeExtrusionLines(IdList<Entity,hEntity> *el, hEntity in) {
Entity *ep = SK.GetEntity(in); Entity *ep = SK.GetEntity(in);
Entity en; Entity en = {};
ZERO(&en);
if(ep->IsPoint()) { if(ep->IsPoint()) {
// A point gets extruded to form a line segment // A point gets extruded to form a line segment
en.point[0] = Remap(ep->h, REMAP_TOP); en.point[0] = Remap(ep->h, REMAP_TOP);
@ -613,8 +606,7 @@ void Group::MakeExtrusionTopBottomFaces(IdList<Entity,hEntity> *el, hEntity pt)
Group *src = SK.GetGroup(opA); Group *src = SK.GetGroup(opA);
Vector n = src->polyLoops.normal; Vector n = src->polyLoops.normal;
Entity en; Entity en = {};
ZERO(&en);
en.type = Entity::FACE_NORMAL_PT; en.type = Entity::FACE_NORMAL_PT;
en.group = h; en.group = h;
@ -634,8 +626,7 @@ void Group::CopyEntity(IdList<Entity,hEntity> *el,
hParam qw, hParam qvx, hParam qvy, hParam qvz, hParam qw, hParam qvx, hParam qvy, hParam qvz,
bool asTrans, bool asAxisAngle) bool asTrans, bool asAxisAngle)
{ {
Entity en; Entity en = {};
ZERO(&en);
en.type = ep->type; en.type = ep->type;
en.extraPoints = ep->extraPoints; en.extraPoints = ep->extraPoints;
en.h = Remap(ep->h, remap); en.h = Remap(ep->h, remap);

View File

@ -13,8 +13,7 @@ void Group::AssembleLoops(bool *allClosed,
bool *allCoplanar, bool *allCoplanar,
bool *allNonZeroLen) bool *allNonZeroLen)
{ {
SBezierList sbl; SBezierList sbl = {};
ZERO(&sbl);
int i; int i;
for(i = 0; i < SK.entity.n; i++) { for(i = 0; i < SK.entity.n; i++) {
@ -108,8 +107,8 @@ void SMesh::RemapFaces(Group *g, int remap) {
template<class T> template<class T>
void Group::GenerateForStepAndRepeat(T *steps, T *outs) { void Group::GenerateForStepAndRepeat(T *steps, T *outs) {
T workA, workB; T workA, workB;
ZERO(&workA); workA = {};
ZERO(&workB); workB = {};
T *soFar = &workA, *scratch = &workB; T *soFar = &workA, *scratch = &workB;
int n = (int)valA, a0 = 0; int n = (int)valA, a0 = 0;
@ -121,8 +120,7 @@ void Group::GenerateForStepAndRepeat(T *steps, T *outs) {
int ap = a*2 - (subtype == ONE_SIDED ? 0 : (n-1)); int ap = a*2 - (subtype == ONE_SIDED ? 0 : (n-1));
int remap = (a == (n - 1)) ? REMAP_LAST : a; int remap = (a == (n - 1)) ? REMAP_LAST : a;
T transd; T transd = {};
ZERO(&transd);
if(type == TRANSLATE) { if(type == TRANSLATE) {
Vector trans = Vector::From(h.param(0), h.param(1), h.param(2)); Vector trans = Vector::From(h.param(0), h.param(1), h.param(2));
trans = trans.ScaledBy(ap); trans = trans.ScaledBy(ap);
@ -334,8 +332,8 @@ void Group::GenerateShellAndMesh(void) {
} }
} else { } else {
SMesh prevm, thism; SMesh prevm, thism;
ZERO(&prevm); prevm = {};
ZERO(&thism); thism = {};
prevm.MakeFromCopyOf(&(prevg->runningMesh)); prevm.MakeFromCopyOf(&(prevg->runningMesh));
prevg->runningShell.TriangulateInto(&prevm); prevg->runningShell.TriangulateInto(&prevm);
@ -343,8 +341,7 @@ void Group::GenerateShellAndMesh(void) {
thism.MakeFromCopyOf(&thisMesh); thism.MakeFromCopyOf(&thisMesh);
thisShell.TriangulateInto(&thism); thisShell.TriangulateInto(&thism);
SMesh outm; SMesh outm = {};
ZERO(&outm);
GenerateForBoolean<SMesh>(&prevm, &thism, &outm, srcg->meshCombine); GenerateForBoolean<SMesh>(&prevm, &thism, &outm, srcg->meshCombine);
// And make sure that the output mesh is vertex-to-vertex. // And make sure that the output mesh is vertex-to-vertex.
@ -540,8 +537,7 @@ void Group::Draw(void) {
} }
void Group::FillLoopSetAsPolygon(SBezierLoopSet *sbls) { void Group::FillLoopSetAsPolygon(SBezierLoopSet *sbls) {
SPolygon sp; SPolygon sp = {};
ZERO(&sp);
sbls->MakePwlInto(&sp); sbls->MakePwlInto(&sp);
ssglDepthRangeOffset(1); ssglDepthRangeOffset(1);
ssglFillPolygon(&sp); ssglFillPolygon(&sp);

View File

@ -1446,8 +1446,7 @@ void LoadAllFontFiles(void) {
Glib::ustring ufilename = (char*) filename; Glib::ustring ufilename = (char*) filename;
if(ufilename.length() > 4 && if(ufilename.length() > 4 &&
ufilename.substr(ufilename.length() - 4, 4).lowercase() == ".ttf") { ufilename.substr(ufilename.length() - 4, 4).lowercase() == ".ttf") {
TtfFont tf; TtfFont tf = {};
ZERO(&tf);
strcpy(tf.fontFile, (char*) filename); strcpy(tf.fontFile, (char*) filename);
SS.fonts.l.Add(&tf); SS.fonts.l.Add(&tf);
} }

View File

@ -8,7 +8,7 @@
#define EXPORT_DLL #define EXPORT_DLL
#include <slvs.h> #include <slvs.h>
Sketch SolveSpace::SK; Sketch SolveSpace::SK = {};
static System SYS; static System SYS;
static int IsInit = 0; static int IsInit = 0;
@ -88,8 +88,7 @@ void Slvs_Solve(Slvs_System *ssys, Slvs_hGroup shg)
int i; int i;
for(i = 0; i < ssys->params; i++) { for(i = 0; i < ssys->params; i++) {
Slvs_Param *sp = &(ssys->param[i]); Slvs_Param *sp = &(ssys->param[i]);
Param p; Param p = {};
ZERO(&p);
p.h.v = sp->h; p.h.v = sp->h;
p.val = sp->val; p.val = sp->val;
@ -101,8 +100,7 @@ void Slvs_Solve(Slvs_System *ssys, Slvs_hGroup shg)
for(i = 0; i < ssys->entities; i++) { for(i = 0; i < ssys->entities; i++) {
Slvs_Entity *se = &(ssys->entity[i]); Slvs_Entity *se = &(ssys->entity[i]);
EntityBase e; EntityBase e = {};
ZERO(&e);
switch(se->type) { switch(se->type) {
case SLVS_E_POINT_IN_3D: e.type = Entity::POINT_IN_3D; break; case SLVS_E_POINT_IN_3D: e.type = Entity::POINT_IN_3D; break;
@ -137,8 +135,7 @@ default: dbp("bad entity type %d", se->type); return;
for(i = 0; i < ssys->constraints; i++) { for(i = 0; i < ssys->constraints; i++) {
Slvs_Constraint *sc = &(ssys->constraint[i]); Slvs_Constraint *sc = &(ssys->constraint[i]);
ConstraintBase c; ConstraintBase c = {};
ZERO(&c);
int t; int t;
switch(sc->type) { switch(sc->type) {
@ -205,12 +202,10 @@ default: dbp("bad constraint type %d", sc->type); return;
} }
} }
Group g; Group g = {};
ZERO(&g);
g.h.v = shg; g.h.v = shg;
List<hConstraint> bad; List<hConstraint> bad = {};
ZERO(&bad);
// Now we're finally ready to solve! // Now we're finally ready to solve!
bool andFindBad = ssys->calculateFaileds ? true : false; bool andFindBad = ssys->calculateFaileds ? true : false;

View File

@ -24,7 +24,7 @@ void SMesh::AddTriangle(STriMeta meta, Vector n, Vector a, Vector b, Vector c) {
} }
} }
void SMesh::AddTriangle(STriMeta meta, Vector a, Vector b, Vector c) { void SMesh::AddTriangle(STriMeta meta, Vector a, Vector b, Vector c) {
STriangle t; ZERO(&t); STriangle t = {};
t.meta = meta; t.meta = meta;
t.a = a; t.a = a;
t.b = b; t.b = b;
@ -62,8 +62,7 @@ void SMesh::GetBounding(Vector *vmax, Vector *vmin) {
// within the plane n dot p = d. // within the plane n dot p = d.
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
void SMesh::MakeEdgesInPlaneInto(SEdgeList *sel, Vector n, double d) { void SMesh::MakeEdgesInPlaneInto(SEdgeList *sel, Vector n, double d) {
SMesh m; SMesh m = {};
ZERO(&m);
m.MakeFromCopyOf(this); m.MakeFromCopyOf(this);
// Delete all triangles in the mesh that do not lie in our export plane. // Delete all triangles in the mesh that do not lie in our export plane.
@ -623,8 +622,7 @@ void SKdNode::SnapToMesh(SMesh *m) {
((j == 1) ? tr->b : ((j == 1) ? tr->b :
tr->c)); tr->c));
SMesh extra; SMesh extra = {};
ZERO(&extra);
SnapToVertex(v, &extra); SnapToVertex(v, &extra);
for(k = 0; k < extra.l.n; k++) { for(k = 0; k < extra.l.n; k++) {
@ -643,8 +641,7 @@ void SKdNode::SnapToMesh(SMesh *m) {
// and our output. // and our output.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void SKdNode::SplitLinesAgainstTriangle(SEdgeList *sel, STriangle *tr) { void SKdNode::SplitLinesAgainstTriangle(SEdgeList *sel, STriangle *tr) {
SEdgeList seln; SEdgeList seln = {};
ZERO(&seln);
Vector tn = tr->Normal().WithMagnitude(1); Vector tn = tr->Normal().WithMagnitude(1);
double td = tn.Dot(tr->a); double td = tn.Dot(tr->a);
@ -904,8 +901,7 @@ void SKdNode::MakeCertainEdgesInto(SEdgeList *sel, int how,
if(inter) *inter = false; if(inter) *inter = false;
if(leaky) *leaky = false; if(leaky) *leaky = false;
SMesh m; SMesh m = {};
ZERO(&m);
ClearTags(); ClearTags();
MakeMeshInto(&m); MakeMeshInto(&m);

View File

@ -50,8 +50,7 @@ void GraphicsWindow::FixConstraintsForRequestBeingDeleted(hRequest hr) {
} }
} }
void GraphicsWindow::FixConstraintsForPointBeingDeleted(hEntity hpt) { void GraphicsWindow::FixConstraintsForPointBeingDeleted(hEntity hpt) {
List<hEntity> ld; List<hEntity> ld = {};
ZERO(&ld);
Constraint *c; Constraint *c;
SK.constraint.ClearTags(); SK.constraint.ClearTags();
@ -89,7 +88,7 @@ void GraphicsWindow::FixConstraintsForPointBeingDeleted(hEntity hpt) {
// arcs by a numerical method. // arcs by a numerical method.
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void GraphicsWindow::ParametricCurve::MakeFromEntity(hEntity he, bool reverse) { void GraphicsWindow::ParametricCurve::MakeFromEntity(hEntity he, bool reverse) {
ZERO(this); *this = {};
Entity *e = SK.GetEntity(he); Entity *e = SK.GetEntity(he);
if(e->type == Entity::LINE_SEGMENT) { if(e->type == Entity::LINE_SEGMENT) {
isLine = true; isLine = true;
@ -483,8 +482,7 @@ hEntity GraphicsWindow::SplitCircle(hEntity he, Vector pinter) {
hEntity GraphicsWindow::SplitCubic(hEntity he, Vector pinter) { hEntity GraphicsWindow::SplitCubic(hEntity he, Vector pinter) {
// Save the original endpoints, since we're about to delete this entity. // Save the original endpoints, since we're about to delete this entity.
Entity *e01 = SK.GetEntity(he); Entity *e01 = SK.GetEntity(he);
SBezierList sbl; SBezierList sbl = {};
ZERO(&sbl);
e01->GenerateBezierCurves(&sbl); e01->GenerateBezierCurves(&sbl);
hEntity hep0 = e01->point[0], hEntity hep0 = e01->point[0],
@ -606,13 +604,12 @@ void GraphicsWindow::SplitLinesOrCurves(void) {
// Compute the possibly-rational Bezier curves for each of these entities // Compute the possibly-rational Bezier curves for each of these entities
SBezierList sbla, sblb; SBezierList sbla, sblb;
ZERO(&sbla); sbla = {};
ZERO(&sblb); sblb = {};
ea->GenerateBezierCurves(&sbla); ea->GenerateBezierCurves(&sbla);
eb->GenerateBezierCurves(&sblb); eb->GenerateBezierCurves(&sblb);
// and then compute the points where they intersect, based on those curves. // and then compute the points where they intersect, based on those curves.
SPointList inters; SPointList inters = {};
ZERO(&inters);
sbla.AllIntersectionsWith(&sblb, &inters); sbla.AllIntersectionsWith(&sblb, &inters);
if(inters.l.n > 0) { if(inters.l.n > 0) {

View File

@ -454,7 +454,7 @@ void GraphicsWindow::MouseMoved(double x, double y, bool leftDown,
void GraphicsWindow::ClearPending(void) { void GraphicsWindow::ClearPending(void) {
pending.points.Clear(); pending.points.Clear();
ZERO(&pending); pending = {};
SS.ScheduleShowTW(); SS.ScheduleShowTW();
} }
@ -727,8 +727,7 @@ hRequest GraphicsWindow::AddRequest(int type) {
hRequest GraphicsWindow::AddRequest(int type, bool rememberForUndo) { hRequest GraphicsWindow::AddRequest(int type, bool rememberForUndo) {
if(rememberForUndo) SS.UndoRemember(); if(rememberForUndo) SS.UndoRemember();
Request r; Request r = {};
memset(&r, 0, sizeof(r));
r.group = activeGroup; r.group = activeGroup;
Group *g = SK.GetGroup(activeGroup); Group *g = SK.GetGroup(activeGroup);
if(g->type == Group::DRAWING_3D || g->type == Group::DRAWING_WORKPLANE) { if(g->type == Group::DRAWING_3D || g->type == Group::DRAWING_WORKPLANE) {
@ -948,8 +947,7 @@ void GraphicsWindow::MouseLeftDown(double mx, double my) {
case MNU_COMMENT: { case MNU_COMMENT: {
ClearSuper(); ClearSuper();
Constraint c; Constraint c = {};
ZERO(&c);
c.group = SS.GW.activeGroup; c.group = SS.GW.activeGroup;
c.workplane = SS.GW.ActiveWorkplane(); c.workplane = SS.GW.ActiveWorkplane();
c.type = Constraint::COMMENT; c.type = Constraint::COMMENT;

View File

@ -48,8 +48,7 @@ void STriangle::FlipNormal(void) {
} }
STriangle STriangle::From(STriMeta meta, Vector a, Vector b, Vector c) { STriangle STriangle::From(STriMeta meta, Vector a, Vector b, Vector c) {
STriangle tr; STriangle tr = {};
ZERO(&tr);
tr.meta = meta; tr.meta = meta;
tr.a = a; tr.a = a;
tr.b = b; tr.b = b;
@ -58,8 +57,7 @@ STriangle STriangle::From(STriMeta meta, Vector a, Vector b, Vector c) {
} }
SEdge SEdge::From(Vector a, Vector b) { SEdge SEdge::From(Vector a, Vector b) {
SEdge se; SEdge se = {};
ZERO(&se);
se.a = a; se.a = a;
se.b = b; se.b = b;
return se; return se;
@ -152,7 +150,7 @@ void SEdgeList::Clear(void) {
} }
void SEdgeList::AddEdge(Vector a, Vector b, int auxA, int auxB) { void SEdgeList::AddEdge(Vector a, Vector b, int auxA, int auxB) {
SEdge e; ZERO(&e); SEdge e = {};
e.a = a; e.a = a;
e.b = b; e.b = b;
e.auxA = auxA; e.auxA = auxA;
@ -303,12 +301,12 @@ void SEdgeList::CullExtraneousEdges(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
SKdNodeEdges *SKdNodeEdges::Alloc(void) { SKdNodeEdges *SKdNodeEdges::Alloc(void) {
SKdNodeEdges *ne = (SKdNodeEdges *)AllocTemporary(sizeof(SKdNodeEdges)); SKdNodeEdges *ne = (SKdNodeEdges *)AllocTemporary(sizeof(SKdNodeEdges));
ZERO(ne); *ne = {};
return ne; return ne;
} }
SEdgeLl *SEdgeLl::Alloc(void) { SEdgeLl *SEdgeLl::Alloc(void) {
SEdgeLl *sell = (SEdgeLl *)AllocTemporary(sizeof(SEdgeLl)); SEdgeLl *sell = (SEdgeLl *)AllocTemporary(sizeof(SEdgeLl));
ZERO(sell); *sell = {};
return sell; return sell;
} }
SKdNodeEdges *SKdNodeEdges::From(SEdgeList *sel) { SKdNodeEdges *SKdNodeEdges::From(SEdgeList *sel) {
@ -499,8 +497,7 @@ void SPointList::IncrementTagFor(Vector pt) {
} }
void SPointList::Add(Vector pt) { void SPointList::Add(Vector pt) {
SPoint p; SPoint p = {};
ZERO(&p);
p.p = pt; p.p = pt;
l.Add(&p); l.Add(&p);
} }
@ -621,8 +618,7 @@ void SPolygon::Clear(void) {
} }
void SPolygon::AddEmptyContour(void) { void SPolygon::AddEmptyContour(void) {
SContour c; SContour c = {};
memset(&c, 0, sizeof(c));
l.Add(&c); l.Add(&c);
} }
@ -709,8 +705,7 @@ Vector SPolygon::AnyPoint(void) {
} }
bool SPolygon::SelfIntersecting(Vector *intersectsAt) { bool SPolygon::SelfIntersecting(Vector *intersectsAt) {
SEdgeList el; SEdgeList el = {};
ZERO(&el);
MakeEdgesInto(&el); MakeEdgesInto(&el);
SKdNodeEdges *kdtree = SKdNodeEdges::From(&el); SKdNodeEdges *kdtree = SKdNodeEdges::From(&el);

View File

@ -91,8 +91,7 @@ void Request::Generate(IdList<Entity,hEntity> *entity,
bool hasDistance = false; bool hasDistance = false;
int i; int i;
Entity e; Entity e = {};
ZERO(&e);
EntReqTable::GetRequestInfo(type, extraPoints, EntReqTable::GetRequestInfo(type, extraPoints,
&et, &points, &hasNormal, &hasDistance); &et, &points, &hasNormal, &hasDistance);
@ -109,8 +108,7 @@ void Request::Generate(IdList<Entity,hEntity> *entity,
// And generate entities for the points // And generate entities for the points
for(i = 0; i < points; i++) { for(i = 0; i < points; i++) {
Entity p; Entity p = {};
memset(&p, 0, sizeof(p));
p.workplane = workplane; p.workplane = workplane;
// points start from entity 1, except for datum point case // points start from entity 1, except for datum point case
p.h = h.entity(i+(et ? 1 : 0)); p.h = h.entity(i+(et ? 1 : 0));
@ -133,8 +131,7 @@ void Request::Generate(IdList<Entity,hEntity> *entity,
e.point[i] = p.h; e.point[i] = p.h;
} }
if(hasNormal) { if(hasNormal) {
Entity n; Entity n = {};
memset(&n, 0, sizeof(n));
n.workplane = workplane; n.workplane = workplane;
n.h = h.entity(32); n.h = h.entity(32);
n.group = group; n.group = group;
@ -158,8 +155,7 @@ void Request::Generate(IdList<Entity,hEntity> *entity,
e.normal = n.h; e.normal = n.h;
} }
if(hasDistance) { if(hasDistance) {
Entity d; Entity d = {};
memset(&d, 0, sizeof(d));
d.workplane = workplane; d.workplane = workplane;
d.h = h.entity(64); d.h = h.entity(64);
d.group = group; d.group = group;
@ -190,8 +186,7 @@ char *Request::DescriptionString(void) {
} }
hParam Request::AddParam(IdList<Param,hParam> *param, hParam hp) { hParam Request::AddParam(IdList<Param,hParam> *param, hParam hp) {
Param pa; Param pa = {};
memset(&pa, 0, sizeof(pa));
pa.h = hp; pa.h = hp;
param->Add(&pa); param->Add(&pa);
return hp; return hp;

View File

@ -438,6 +438,13 @@ public:
class Entity : public EntityBase { class Entity : public EntityBase {
public: public:
// Necessary for Entity e = {} to zero-initialize, since
// classes with base classes are not aggregates and
// the default constructor does not initialize members.
Entity() : EntityBase(), forceHidden(), actPoint(), actNormal(),
actDistance(), actVisible(), style(), construction(),
dogd() {};
// An imported entity that was hidden in the source file ends up hidden // An imported entity that was hidden in the source file ends up hidden
// here too. // here too.
bool forceHidden; bool forceHidden;
@ -616,6 +623,9 @@ public:
class Constraint : public ConstraintBase { class Constraint : public ConstraintBase {
public: public:
// See Entity::Entity().
Constraint() : ConstraintBase(), disp(), dogd() {}
// These define how the constraint is drawn on-screen. // These define how the constraint is drawn on-screen.
struct { struct {
Vector offset; Vector offset;

View File

@ -7,8 +7,8 @@
#include "solvespace.h" #include "solvespace.h"
#include <string> #include <string>
SolveSpaceUI SolveSpace::SS; SolveSpaceUI SolveSpace::SS = {};
Sketch SolveSpace::SK; Sketch SolveSpace::SK = {};
void SolveSpaceUI::Init() { void SolveSpaceUI::Init() {
SS.tangentArcRadius = 10.0; SS.tangentArcRadius = 10.0;
@ -235,7 +235,7 @@ void SolveSpaceUI::ScheduleShowTW() {
void SolveSpaceUI::DoLater(void) { void SolveSpaceUI::DoLater(void) {
if(later.generateAll) GenerateAll(); if(later.generateAll) GenerateAll();
if(later.showTW) TW.Show(); if(later.showTW) TW.Show();
ZERO(&later); later = {};
} }
double SolveSpaceUI::MmPerUnit(void) { double SolveSpaceUI::MmPerUnit(void) {
@ -530,8 +530,7 @@ void SolveSpaceUI::MenuFile(int id) {
case GraphicsWindow::MNU_EXPORT_SURFACES: { case GraphicsWindow::MNU_EXPORT_SURFACES: {
char exportFile[MAX_PATH] = ""; char exportFile[MAX_PATH] = "";
if(!GetSaveFile(exportFile, SRF_EXT, SRF_PATTERN)) break; if(!GetSaveFile(exportFile, SRF_EXT, SRF_PATTERN)) break;
StepFileWriter sfw; StepFileWriter sfw = {};
ZERO(&sfw);
sfw.ExportSurfacesTo(exportFile); sfw.ExportSurfacesTo(exportFile);
break; break;
} }
@ -714,11 +713,9 @@ void SolveSpaceUI::MenuAnalyze(int id) {
"intersecting."); "intersecting.");
break; break;
} }
SEdgeList sel; SEdgeList sel = {};
ZERO(&sel);
g->polyLoops.MakeEdgesInto(&sel); g->polyLoops.MakeEdgesInto(&sel);
SPolygon sp; SPolygon sp = {};
ZERO(&sp);
sel.AssemblePolygon(&sp, NULL, true); sel.AssemblePolygon(&sp, NULL, true);
sp.normal = sp.ComputeNormal(); sp.normal = sp.ComputeNormal();
sp.FixContourDirections(); sp.FixContourDirections();

View File

@ -84,7 +84,6 @@ inline double WRAP_SYMMETRIC(double v, double n) {
// Why is this faster than the library function? // Why is this faster than the library function?
inline double ffabs(double v) { return (v > 0) ? v : (-v); } inline double ffabs(double v) { return (v > 0) ? v : (-v); }
#define ZERO(v) memset((v), 0, sizeof(*(v)))
#define CO(v) (v).x, (v).y, (v).z #define CO(v) (v).x, (v).y, (v).z
#define LENGTH_EPS (1e-6) #define LENGTH_EPS (1e-6)

View File

@ -40,7 +40,7 @@ SCurve SCurve::MakeCopySplitAgainst(SShell *agnstA, SShell *agnstB,
{ {
SCurve ret; SCurve ret;
ret = *this; ret = *this;
ZERO(&(ret.pts)); ret.pts = {};
SCurvePt *p = pts.First(); SCurvePt *p = pts.First();
if(!p) oops(); if(!p) oops();
@ -49,8 +49,7 @@ SCurve SCurve::MakeCopySplitAgainst(SShell *agnstA, SShell *agnstB,
p = pts.NextAfter(p); p = pts.NextAfter(p);
for(; p; p = pts.NextAfter(p)) { for(; p; p = pts.NextAfter(p)) {
List<SInter> il; List<SInter> il = {};
ZERO(&il);
// Find all the intersections with the two passed shells // Find all the intersections with the two passed shells
if(agnstA) if(agnstA)
@ -148,8 +147,7 @@ void SShell::CopyCurvesSplitAgainst(bool opA, SShell *agnst, SShell *into) {
void SSurface::TrimFromEdgeList(SEdgeList *el, bool asUv) { void SSurface::TrimFromEdgeList(SEdgeList *el, bool asUv) {
el->l.ClearTags(); el->l.ClearTags();
STrimBy stb; STrimBy stb = {};
ZERO(&stb);
for(;;) { for(;;) {
// Find an edge, any edge; we'll start from there. // Find an edge, any edge; we'll start from there.
SEdge *se; SEdge *se;
@ -424,7 +422,7 @@ SSurface SSurface::MakeCopyTrimAgainst(SShell *parent,
SSurface ret; SSurface ret;
// The returned surface is identical, just the trim curves change // The returned surface is identical, just the trim curves change
ret = *this; ret = *this;
ZERO(&(ret.trim)); ret.trim = {};
// First, build a list of the existing trim curves; update them to use // First, build a list of the existing trim curves; update them to use
// the split curves. // the split curves.
@ -443,16 +441,14 @@ SSurface SSurface::MakeCopyTrimAgainst(SShell *parent,
// Build up our original trim polygon; remember the coordinates could // Build up our original trim polygon; remember the coordinates could
// be changed if we just flipped the surface normal, and we are using // be changed if we just flipped the surface normal, and we are using
// the split curves (not the original curves). // the split curves (not the original curves).
SEdgeList orig; SEdgeList orig = {};
ZERO(&orig);
ret.MakeEdgesInto(into, &orig, AS_UV); ret.MakeEdgesInto(into, &orig, AS_UV);
ret.trim.Clear(); ret.trim.Clear();
// which means that we can't necessarily use the old BSP... // which means that we can't necessarily use the old BSP...
SBspUv *origBsp = SBspUv::From(&orig, &ret); SBspUv *origBsp = SBspUv::From(&orig, &ret);
// And now intersect the other shell against us // And now intersect the other shell against us
SEdgeList inter; SEdgeList inter = {};
ZERO(&inter);
SSurface *ss; SSurface *ss;
for(ss = agnst->surface.First(); ss; ss = agnst->surface.NextAfter(ss)) { for(ss = agnst->surface.First(); ss; ss = agnst->surface.NextAfter(ss)) {
@ -504,8 +500,7 @@ SSurface SSurface::MakeCopyTrimAgainst(SShell *parent,
// the choosing points. If two edges join at a non-choosing point, then // the choosing points. If two edges join at a non-choosing point, then
// they must either both be kept or both be discarded (since that would // they must either both be kept or both be discarded (since that would
// otherwise create an open contour). // otherwise create an open contour).
SPointList choosing; SPointList choosing = {};
ZERO(&choosing);
SEdge *se; SEdge *se;
for(se = orig.l.First(); se; se = orig.l.NextAfter(se)) { for(se = orig.l.First(); se; se = orig.l.NextAfter(se)) {
choosing.IncrementTagFor(se->a); choosing.IncrementTagFor(se->a);
@ -527,12 +522,10 @@ SSurface SSurface::MakeCopyTrimAgainst(SShell *parent,
// The list of edges to trim our new surface, a combination of edges from // The list of edges to trim our new surface, a combination of edges from
// our original and intersecting edge lists. // our original and intersecting edge lists.
SEdgeList final; SEdgeList final = {};
ZERO(&final);
while(orig.l.n > 0) { while(orig.l.n > 0) {
SEdgeList chain; SEdgeList chain = {};
ZERO(&chain);
FindChainAvoiding(&orig, &chain, &choosing); FindChainAvoiding(&orig, &chain, &choosing);
// Arbitrarily choose an edge within the chain to classify; they // Arbitrarily choose an edge within the chain to classify; they
@ -566,8 +559,7 @@ SSurface SSurface::MakeCopyTrimAgainst(SShell *parent,
} }
while(inter.l.n > 0) { while(inter.l.n > 0) {
SEdgeList chain; SEdgeList chain = {};
ZERO(&chain);
FindChainAvoiding(&inter, &chain, &choosing); FindChainAvoiding(&inter, &chain, &choosing);
// Any edge in the chain, same as above. // Any edge in the chain, same as above.
@ -608,8 +600,7 @@ SSurface SSurface::MakeCopyTrimAgainst(SShell *parent,
// Use our reassembled edges to trim the new surface. // Use our reassembled edges to trim the new surface.
ret.TrimFromEdgeList(&final, true); ret.TrimFromEdgeList(&final, true);
SPolygon poly; SPolygon poly = {};
ZERO(&poly);
final.l.ClearTags(); final.l.ClearTags();
if(!final.AssemblePolygon(&poly, NULL, true)) { if(!final.AssemblePolygon(&poly, NULL, true)) {
into->booleanFailed = true; into->booleanFailed = true;
@ -782,14 +773,13 @@ void SShell::MakeClassifyingBsps(SShell *useCurvesFrom) {
} }
void SSurface::MakeClassifyingBsp(SShell *shell, SShell *useCurvesFrom) { void SSurface::MakeClassifyingBsp(SShell *shell, SShell *useCurvesFrom) {
SEdgeList el; SEdgeList el = {};
ZERO(&el);
MakeEdgesInto(shell, &el, AS_UV, useCurvesFrom); MakeEdgesInto(shell, &el, AS_UV, useCurvesFrom);
bsp = SBspUv::From(&el, this); bsp = SBspUv::From(&el, this);
el.Clear(); el.Clear();
ZERO(&edges); edges = {};
MakeEdgesInto(shell, &edges, AS_XYZ, useCurvesFrom); MakeEdgesInto(shell, &edges, AS_XYZ, useCurvesFrom);
} }
@ -810,8 +800,7 @@ static int ByLength(const void *av, const void *bv)
return (la < lb) ? 1 : -1; return (la < lb) ? 1 : -1;
} }
SBspUv *SBspUv::From(SEdgeList *el, SSurface *srf) { SBspUv *SBspUv::From(SEdgeList *el, SSurface *srf) {
SEdgeList work; SEdgeList work = {};
ZERO(&work);
SEdge *se; SEdge *se;
for(se = el->l.First(); se; se = el->l.NextAfter(se)) { for(se = el->l.First(); se; se = el->l.NextAfter(se)) {

View File

@ -7,8 +7,7 @@
#include "../solvespace.h" #include "../solvespace.h"
SBezier SBezier::From(Vector4 p0, Vector4 p1) { SBezier SBezier::From(Vector4 p0, Vector4 p1) {
SBezier ret; SBezier ret = {};
ZERO(&ret);
ret.deg = 1; ret.deg = 1;
ret.weight[0] = p0.w; ret.weight[0] = p0.w;
ret.ctrl [0] = p0.PerspectiveProject(); ret.ctrl [0] = p0.PerspectiveProject();
@ -18,8 +17,7 @@ SBezier SBezier::From(Vector4 p0, Vector4 p1) {
} }
SBezier SBezier::From(Vector4 p0, Vector4 p1, Vector4 p2) { SBezier SBezier::From(Vector4 p0, Vector4 p1, Vector4 p2) {
SBezier ret; SBezier ret = {};
ZERO(&ret);
ret.deg = 2; ret.deg = 2;
ret.weight[0] = p0.w; ret.weight[0] = p0.w;
ret.ctrl [0] = p0.PerspectiveProject(); ret.ctrl [0] = p0.PerspectiveProject();
@ -31,8 +29,7 @@ SBezier SBezier::From(Vector4 p0, Vector4 p1, Vector4 p2) {
} }
SBezier SBezier::From(Vector4 p0, Vector4 p1, Vector4 p2, Vector4 p3) { SBezier SBezier::From(Vector4 p0, Vector4 p1, Vector4 p2, Vector4 p3) {
SBezier ret; SBezier ret = {};
ZERO(&ret);
ret.deg = 3; ret.deg = 3;
ret.weight[0] = p0.w; ret.weight[0] = p0.w;
ret.ctrl [0] = p0.PerspectiveProject(); ret.ctrl [0] = p0.PerspectiveProject();
@ -274,11 +271,10 @@ void SBezierList::AllIntersectionsWith(SBezierList *sblb, SPointList *spl) {
} }
} }
void SBezier::AllIntersectionsWith(SBezier *sbb, SPointList *spl) { void SBezier::AllIntersectionsWith(SBezier *sbb, SPointList *spl) {
SPointList splRaw; SPointList splRaw = {};
ZERO(&splRaw);
SEdgeList sea, seb; SEdgeList sea, seb;
ZERO(&sea); sea = {};
ZERO(&seb); seb = {};
this->MakePwlInto(&sea); this->MakePwlInto(&sea);
sbb ->MakePwlInto(&seb); sbb ->MakePwlInto(&seb);
SEdge *se; SEdge *se;
@ -393,8 +389,7 @@ bool SBezierList::GetPlaneContainingBeziers(Vector *p, Vector *u, Vector *v,
SBezierLoop SBezierLoop::FromCurves(SBezierList *sbl, SBezierLoop SBezierLoop::FromCurves(SBezierList *sbl,
bool *allClosed, SEdge *errorAt) bool *allClosed, SEdge *errorAt)
{ {
SBezierLoop loop; SBezierLoop loop = {};
ZERO(&loop);
if(sbl->l.n < 1) return loop; if(sbl->l.n < 1) return loop;
sbl->l.ClearTags(); sbl->l.ClearTags();
@ -502,8 +497,7 @@ SBezierLoopSet SBezierLoopSet::From(SBezierList *sbl, SPolygon *poly,
bool *allClosed, SEdge *errorAt, bool *allClosed, SEdge *errorAt,
SBezierList *openContours) SBezierList *openContours)
{ {
SBezierLoopSet ret; SBezierLoopSet ret = {};
ZERO(&ret);
*allClosed = true; *allClosed = true;
while(sbl->l.n > 0) { while(sbl->l.n > 0) {
@ -610,8 +604,7 @@ void SBezierLoopSetSet::FindOuterFacesFrom(SBezierList *sbl, SPolygon *spxyz,
if(sbls.l.n != spxyz->l.n) return; if(sbls.l.n != spxyz->l.n) return;
// Convert the xyz piecewise linear to uv piecewise linear. // Convert the xyz piecewise linear to uv piecewise linear.
SPolygon spuv; SPolygon spuv = {};
ZERO(&spuv);
SContour *sc; SContour *sc;
for(sc = spxyz->l.First(); sc; sc = spxyz->l.NextAfter(sc)) { for(sc = spxyz->l.First(); sc; sc = spxyz->l.NextAfter(sc)) {
spuv.AddEmptyContour(); spuv.AddEmptyContour();
@ -671,8 +664,7 @@ void SBezierLoopSetSet::FindOuterFacesFrom(SBezierList *sbl, SPolygon *spxyz,
continue; continue;
} }
SBezierLoopSet outerAndInners; SBezierLoopSet outerAndInners = {};
ZERO(&outerAndInners);
loopsRemaining = true; loopsRemaining = true;
loop->tag = USED_LOOP; loop->tag = USED_LOOP;
outerAndInners.l.Add(loop); outerAndInners.l.Add(loop);
@ -723,12 +715,10 @@ void SBezierLoopSetSet::FindOuterFacesFrom(SBezierList *sbl, SPolygon *spxyz,
} }
void SBezierLoopSetSet::AddOpenPath(SBezier *sb) { void SBezierLoopSetSet::AddOpenPath(SBezier *sb) {
SBezierLoop sbl; SBezierLoop sbl = {};
ZERO(&sbl);
sbl.l.Add(sb); sbl.l.Add(sb);
SBezierLoopSet sbls; SBezierLoopSet sbls = {};
ZERO(&sbls);
sbls.l.Add(&sbl); sbls.l.Add(&sbl);
l.Add(&sbls); l.Add(&sbls);
@ -745,8 +735,7 @@ void SBezierLoopSetSet::Clear(void) {
SCurve SCurve::FromTransformationOf(SCurve *a, SCurve SCurve::FromTransformationOf(SCurve *a,
Vector t, Quaternion q, double scale) Vector t, Quaternion q, double scale)
{ {
SCurve ret; SCurve ret = {};
ZERO(&ret);
ret.h = a->h; ret.h = a->h;
ret.isExact = a->isExact; ret.isExact = a->isExact;
@ -840,8 +829,7 @@ void SCurve::RemoveShortSegments(SSurface *srfA, SSurface *srfB) {
} }
STrimBy STrimBy::EntireCurve(SShell *shell, hSCurve hsc, bool backwards) { STrimBy STrimBy::EntireCurve(SShell *shell, hSCurve hsc, bool backwards) {
STrimBy stb; STrimBy stb = {};
ZERO(&stb);
stb.curve = hsc; stb.curve = hsc;
SCurve *sc = shell->curve.FindById(hsc); SCurve *sc = shell->curve.FindById(hsc);

View File

@ -22,8 +22,7 @@ void SShell::MergeCoincidentSurfaces(void) {
// time on other surfaces. // time on other surfaces.
if(si->degm != 1 || si->degn != 1) continue; if(si->degm != 1 || si->degn != 1) continue;
SEdgeList sel; SEdgeList sel = {};
ZERO(&sel);
si->MakeEdgesInto(this, &sel, SSurface::AS_XYZ); si->MakeEdgesInto(this, &sel, SSurface::AS_XYZ);
bool mergedThisTime, merged = false; bool mergedThisTime, merged = false;
@ -42,8 +41,7 @@ void SShell::MergeCoincidentSurfaces(void) {
// surfaces if they contain disjoint contours; that just makes // surfaces if they contain disjoint contours; that just makes
// the bounding box tests less effective, and possibly things // the bounding box tests less effective, and possibly things
// less robust. // less robust.
SEdgeList tel; SEdgeList tel = {};
ZERO(&tel);
sj->MakeEdgesInto(this, &tel, SSurface::AS_XYZ); sj->MakeEdgesInto(this, &tel, SSurface::AS_XYZ);
if(!sel.ContainsEdgeFrom(&tel)) { if(!sel.ContainsEdgeFrom(&tel)) {
tel.Clear(); tel.Clear();

View File

@ -227,8 +227,7 @@ void SBezier::SplitAt(double t, SBezier *bef, SBezier *aft) {
} }
void SBezier::MakePwlInto(SEdgeList *sel, double chordTol) { void SBezier::MakePwlInto(SEdgeList *sel, double chordTol) {
List<Vector> lv; List<Vector> lv = {};
ZERO(&lv);
MakePwlInto(&lv, chordTol); MakePwlInto(&lv, chordTol);
int i; int i;
for(i = 1; i < lv.n; i++) { for(i = 1; i < lv.n; i++) {
@ -237,8 +236,7 @@ void SBezier::MakePwlInto(SEdgeList *sel, double chordTol) {
lv.Clear(); lv.Clear();
} }
void SBezier::MakePwlInto(List<SCurvePt> *l, double chordTol) { void SBezier::MakePwlInto(List<SCurvePt> *l, double chordTol) {
List<Vector> lv; List<Vector> lv = {};
ZERO(&lv);
MakePwlInto(&lv, chordTol); MakePwlInto(&lv, chordTol);
int i; int i;
for(i = 0; i < lv.n; i++) { for(i = 0; i < lv.n; i++) {
@ -251,8 +249,7 @@ void SBezier::MakePwlInto(List<SCurvePt> *l, double chordTol) {
lv.Clear(); lv.Clear();
} }
void SBezier::MakePwlInto(SContour *sc, double chordTol) { void SBezier::MakePwlInto(SContour *sc, double chordTol) {
List<Vector> lv; List<Vector> lv = {};
ZERO(&lv);
MakePwlInto(&lv, chordTol); MakePwlInto(&lv, chordTol);
int i; int i;
for(i = 0; i < lv.n; i++) { for(i = 0; i < lv.n; i++) {

View File

@ -254,8 +254,7 @@ void SSurface::AllPointsIntersecting(Vector a, Vector b,
Vector ba = b.Minus(a); Vector ba = b.Minus(a);
double bam = ba.Magnitude(); double bam = ba.Magnitude();
List<Inter> inters; List<Inter> inters = {};
ZERO(&inters);
// All the intersections between the line and the surface; either special // All the intersections between the line and the surface; either special
// cases that we can quickly solve in closed form, or general numerical. // cases that we can quickly solve in closed form, or general numerical.
@ -426,8 +425,7 @@ bool SShell::ClassifyEdge(int *indir, int *outdir,
Vector p, Vector p,
Vector edge_n_in, Vector edge_n_out, Vector surf_n) Vector edge_n_in, Vector edge_n_out, Vector surf_n)
{ {
List<SInter> l; List<SInter> l = {};
ZERO(&l);
srand(0); srand(0);

View File

@ -7,8 +7,7 @@
#include "../solvespace.h" #include "../solvespace.h"
SSurface SSurface::FromExtrusionOf(SBezier *sb, Vector t0, Vector t1) { SSurface SSurface::FromExtrusionOf(SBezier *sb, Vector t0, Vector t1) {
SSurface ret; SSurface ret = {};
ZERO(&ret);
ret.degm = sb->deg; ret.degm = sb->deg;
ret.degn = 1; ret.degn = 1;
@ -67,8 +66,7 @@ bool SSurface::IsCylinder(Vector *axis, Vector *center, double *r,
SSurface SSurface::FromRevolutionOf(SBezier *sb, Vector pt, Vector axis, SSurface SSurface::FromRevolutionOf(SBezier *sb, Vector pt, Vector axis,
double thetas, double thetaf) double thetas, double thetaf)
{ {
SSurface ret; SSurface ret = {};
ZERO(&ret);
ret.degm = sb->deg; ret.degm = sb->deg;
@ -117,8 +115,7 @@ SSurface SSurface::FromRevolutionOf(SBezier *sb, Vector pt, Vector axis,
} }
SSurface SSurface::FromPlane(Vector pt, Vector u, Vector v) { SSurface SSurface::FromPlane(Vector pt, Vector u, Vector v) {
SSurface ret; SSurface ret = {};
ZERO(&ret);
ret.degm = 1; ret.degm = 1;
ret.degn = 1; ret.degn = 1;
@ -138,8 +135,7 @@ SSurface SSurface::FromTransformationOf(SSurface *a,
Vector t, Quaternion q, double scale, Vector t, Quaternion q, double scale,
bool includingTrims) bool includingTrims)
{ {
SSurface ret; SSurface ret = {};
ZERO(&ret);
ret.h = a->h; ret.h = a->h;
ret.color = a->color; ret.color = a->color;
@ -403,13 +399,11 @@ void SSurface::MakeSectionEdgesInto(SShell *shell,
} }
void SSurface::TriangulateInto(SShell *shell, SMesh *sm) { void SSurface::TriangulateInto(SShell *shell, SMesh *sm) {
SEdgeList el; SEdgeList el = {};
ZERO(&el);
MakeEdgesInto(shell, &el, AS_UV); MakeEdgesInto(shell, &el, AS_UV);
SPolygon poly; SPolygon poly = {};
ZERO(&poly);
if(el.AssemblePolygon(&poly, NULL, true)) { if(el.AssemblePolygon(&poly, NULL, true)) {
int i, start = sm->l.n; int i, start = sm->l.n;
if(degm == 1 && degn == 1) { if(degm == 1 && degn == 1) {
@ -528,8 +522,7 @@ void SShell::MakeFromExtrusionOf(SBezierLoopSet *sbls, Vector t0, Vector t1, Rgb
SBezierLoop *sbl; SBezierLoop *sbl;
for(sbl = sbls->l.First(); sbl; sbl = sbls->l.NextAfter(sbl)) { for(sbl = sbls->l.First(); sbl; sbl = sbls->l.NextAfter(sbl)) {
SBezier *sb; SBezier *sb;
List<TrimLine> trimLines; List<TrimLine> trimLines = {};
ZERO(&trimLines);
for(sb = sbl->l.First(); sb; sb = sbl->l.NextAfter(sb)) { for(sb = sbl->l.First(); sb; sb = sbl->l.NextAfter(sb)) {
// Generate the surface of extrusion of this curve, and add // Generate the surface of extrusion of this curve, and add
@ -539,8 +532,7 @@ void SShell::MakeFromExtrusionOf(SBezierLoopSet *sbls, Vector t0, Vector t1, Rgb
hSSurface hsext = surface.AddAndAssignId(&ss); hSSurface hsext = surface.AddAndAssignId(&ss);
// Translate the curve by t0 and t1 to produce two trim curves // Translate the curve by t0 and t1 to produce two trim curves
SCurve sc; SCurve sc = {};
ZERO(&sc);
sc.isExact = true; sc.isExact = true;
sc.exact = sb->TransformedBy(t0, Quaternion::IDENTITY, 1.0); sc.exact = sb->TransformedBy(t0, Quaternion::IDENTITY, 1.0);
(sc.exact).MakePwlInto(&(sc.pts)); (sc.exact).MakePwlInto(&(sc.pts));
@ -548,7 +540,7 @@ void SShell::MakeFromExtrusionOf(SBezierLoopSet *sbls, Vector t0, Vector t1, Rgb
sc.surfB = hsext; sc.surfB = hsext;
hSCurve hc0 = curve.AddAndAssignId(&sc); hSCurve hc0 = curve.AddAndAssignId(&sc);
ZERO(&sc); sc = {};
sc.isExact = true; sc.isExact = true;
sc.exact = sb->TransformedBy(t1, Quaternion::IDENTITY, 1.0); sc.exact = sb->TransformedBy(t1, Quaternion::IDENTITY, 1.0);
(sc.exact).MakePwlInto(&(sc.pts)); (sc.exact).MakePwlInto(&(sc.pts));
@ -571,7 +563,7 @@ void SShell::MakeFromExtrusionOf(SBezierLoopSet *sbls, Vector t0, Vector t1, Rgb
// And form the trim line // And form the trim line
Vector pt = sb->Finish(); Vector pt = sb->Finish();
ZERO(&sc); sc = {};
sc.isExact = true; sc.isExact = true;
sc.exact = SBezier::From(pt.Plus(t0), pt.Plus(t1)); sc.exact = SBezier::From(pt.Plus(t0), pt.Plus(t1));
(sc.exact).MakePwlInto(&(sc.pts)); (sc.exact).MakePwlInto(&(sc.pts));
@ -645,8 +637,7 @@ void SShell::MakeFromRevolutionOf(SBezierLoopSet *sbls, Vector pt, Vector axis,
for(sbl = sbls->l.First(); sbl; sbl = sbls->l.NextAfter(sbl)) { for(sbl = sbls->l.First(); sbl; sbl = sbls->l.NextAfter(sbl)) {
int i, j; int i, j;
SBezier *sb, *prev; SBezier *sb, *prev;
List<Revolved> hsl; List<Revolved> hsl = {};
ZERO(&hsl);
for(sb = sbl->l.First(); sb; sb = sbl->l.NextAfter(sb)) { for(sb = sbl->l.First(); sb; sb = sbl->l.NextAfter(sb)) {
Revolved revs; Revolved revs;
@ -685,7 +676,7 @@ void SShell::MakeFromRevolutionOf(SBezierLoopSet *sbls, Vector pt, Vector axis,
// If this input curve generate a surface, then trim that // If this input curve generate a surface, then trim that
// surface with the rotated version of the input curve. // surface with the rotated version of the input curve.
if(revs.d[j].v) { if(revs.d[j].v) {
ZERO(&sc); sc = {};
sc.isExact = true; sc.isExact = true;
sc.exact = sb->TransformedBy(ts, qs, 1.0); sc.exact = sb->TransformedBy(ts, qs, 1.0);
(sc.exact).MakePwlInto(&(sc.pts)); (sc.exact).MakePwlInto(&(sc.pts));
@ -707,7 +698,7 @@ void SShell::MakeFromRevolutionOf(SBezierLoopSet *sbls, Vector pt, Vector axis,
if(revs.d[j].v && revsp.d[j].v) { if(revs.d[j].v && revsp.d[j].v) {
SSurface *ss = surface.FindById(revs.d[j]); SSurface *ss = surface.FindById(revs.d[j]);
ZERO(&sc); sc = {};
sc.isExact = true; sc.isExact = true;
sc.exact = SBezier::From(ss->ctrl[0][0], sc.exact = SBezier::From(ss->ctrl[0][0],
ss->ctrl[0][1], ss->ctrl[0][1],

View File

@ -12,8 +12,7 @@ extern int FLAG;
void SSurface::AddExactIntersectionCurve(SBezier *sb, SSurface *srfB, void SSurface::AddExactIntersectionCurve(SBezier *sb, SSurface *srfB,
SShell *agnstA, SShell *agnstB, SShell *into) SShell *agnstA, SShell *agnstB, SShell *into)
{ {
SCurve sc; SCurve sc = {};
ZERO(&sc);
// Important to keep the order of (surfA, surfB) consistent; when we later // Important to keep the order of (surfA, surfB) consistent; when we later
// rewrite the identifiers, we rewrite surfA from A and surfB from B. // rewrite the identifiers, we rewrite surfA from A and surfB from B.
sc.surfA = h; sc.surfA = h;
@ -48,7 +47,7 @@ void SSurface::AddExactIntersectionCurve(SBezier *sb, SSurface *srfB,
} }
if(backwards) sc.pts.Reverse(); if(backwards) sc.pts.Reverse();
split = sc; split = sc;
ZERO(&sc); sc = {};
} else { } else {
sb->MakePwlInto(&(sc.pts)); sb->MakePwlInto(&(sc.pts));
// and split the line where it intersects our existing surfaces // and split the line where it intersects our existing surfaces
@ -216,8 +215,7 @@ void SSurface::IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB,
// extrusion, and dp component doesn't matter so zero // extrusion, and dp component doesn't matter so zero
p0 = n.ScaledBy(d).Plus(alu.ScaledBy(pm.Dot(alu))); p0 = n.ScaledBy(d).Plus(alu.ScaledBy(pm.Dot(alu)));
List<SInter> inters; List<SInter> inters = {};
ZERO(&inters);
sext->AllPointsIntersecting( sext->AllPointsIntersecting(
p0, p0.Plus(dp), &inters, false, false, true); p0, p0.Plus(dp), &inters, false, false, true);
@ -252,10 +250,8 @@ void SSurface::IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB,
// intersect along some number of lines parallel to the axis. // intersect along some number of lines parallel to the axis.
Vector axis = alongt.WithMagnitude(1); Vector axis = alongt.WithMagnitude(1);
List<SInter> inters; List<SInter> inters = {};
ZERO(&inters); List<Vector> lv = {};
List<Vector> lv;
ZERO(&lv);
double a_axis0 = ( ctrl[0][0]).Dot(axis), double a_axis0 = ( ctrl[0][0]).Dot(axis),
a_axis1 = ( ctrl[0][1]).Dot(axis), a_axis1 = ( ctrl[0][1]).Dot(axis),
@ -313,8 +309,7 @@ void SSurface::IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB,
// Try intersecting the surfaces numerically, by a marching algorithm. // Try intersecting the surfaces numerically, by a marching algorithm.
// First, we find all the intersections between a surface and the // First, we find all the intersections between a surface and the
// boundary of the other surface. // boundary of the other surface.
SPointList spl; SPointList spl = {};
ZERO(&spl);
int a; int a;
for(a = 0; a < 2; a++) { for(a = 0; a < 2; a++) {
SShell *shA = (a == 0) ? agnstA : agnstB, SShell *shA = (a == 0) ? agnstA : agnstB,
@ -322,14 +317,12 @@ void SSurface::IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB,
SSurface *srfA = (a == 0) ? this : b, SSurface *srfA = (a == 0) ? this : b,
*srfB = (a == 0) ? b : this; *srfB = (a == 0) ? b : this;
SEdgeList el; SEdgeList el = {};
ZERO(&el);
srfA->MakeEdgesInto(shA, &el, AS_XYZ, NULL); srfA->MakeEdgesInto(shA, &el, AS_XYZ, NULL);
SEdge *se; SEdge *se;
for(se = el.l.First(); se; se = el.l.NextAfter(se)) { for(se = el.l.First(); se; se = el.l.NextAfter(se)) {
List<SInter> lsi; List<SInter> lsi = {};
ZERO(&lsi);
srfB->AllPointsIntersecting(se->a, se->b, &lsi, srfB->AllPointsIntersecting(se->a, se->b, &lsi,
true, true, false); true, true, false);
@ -369,8 +362,7 @@ void SSurface::IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB,
} }
while(spl.l.n >= 2) { while(spl.l.n >= 2) {
SCurve sc; SCurve sc = {};
ZERO(&sc);
sc.surfA = h; sc.surfA = h;
sc.surfB = b->h; sc.surfB = b->h;
sc.isExact = false; sc.isExact = false;
@ -387,8 +379,7 @@ void SSurface::IntersectAgainst(SSurface *b, SShell *agnstA, SShell *agnstB,
int maxsteps = max(300, SS.maxSegments*3); int maxsteps = max(300, SS.maxSegments*3);
// The curve starts at our starting point. // The curve starts at our starting point.
SCurvePt padd; SCurvePt padd = {};
ZERO(&padd);
padd.vertex = true; padd.vertex = true;
padd.p = start; padd.p = start;
sc.pts.Add(&padd); sc.pts.Add(&padd);

View File

@ -33,18 +33,15 @@ void SPolygon::UvTriangulateInto(SMesh *m, SSurface *srf) {
} }
// Start with the outer contour // Start with the outer contour
SContour merged; SContour merged = {};
ZERO(&merged);
top->tag = 1; top->tag = 1;
top->CopyInto(&merged); top->CopyInto(&merged);
(merged.l.n)--; (merged.l.n)--;
// List all of the edges, for testing whether bridges work. // List all of the edges, for testing whether bridges work.
SEdgeList el; SEdgeList el = {};
ZERO(&el);
top->MakeEdgesInto(&el); top->MakeEdgesInto(&el);
List<Vector> vl; List<Vector> vl = {};
ZERO(&vl);
// And now find all of its holes. Note that we will also find any // And now find all of its holes. Note that we will also find any
// outer contours that lie entirely within this contour, and any // outer contours that lie entirely within this contour, and any
@ -191,8 +188,7 @@ bool SContour::BridgeToContour(SContour *sc,
return false; return false;
haveEdge: haveEdge:
SContour merged; SContour merged = {};
ZERO(&merged);
for(i = 0; i < l.n; i++) { for(i = 0; i < l.n; i++) {
merged.AddPoint(l.elem[i].p); merged.AddPoint(l.elem[i].p);
if(i == thisp) { if(i == thisp) {
@ -221,8 +217,7 @@ bool SContour::IsEar(int bp, double scaledEps) {
int ap = WRAP(bp-1, l.n), int ap = WRAP(bp-1, l.n),
cp = WRAP(bp+1, l.n); cp = WRAP(bp+1, l.n);
STriangle tr; STriangle tr = {};
ZERO(&tr);
tr.a = l.elem[ap].p; tr.a = l.elem[ap].p;
tr.b = l.elem[bp].p; tr.b = l.elem[bp].p;
tr.c = l.elem[cp].p; tr.c = l.elem[cp].p;
@ -270,8 +265,7 @@ void SContour::ClipEarInto(SMesh *m, int bp, double scaledEps) {
int ap = WRAP(bp-1, l.n), int ap = WRAP(bp-1, l.n),
cp = WRAP(bp+1, l.n); cp = WRAP(bp+1, l.n);
STriangle tr; STriangle tr = {};
ZERO(&tr);
tr.a = l.elem[ap].p; tr.a = l.elem[ap].p;
tr.b = l.elem[bp].p; tr.b = l.elem[bp].p;
tr.c = l.elem[cp].p; tr.c = l.elem[cp].p;
@ -425,12 +419,10 @@ void SSurface::MakeTriangulationGridInto(List<double> *l, double vs, double vf,
} }
void SPolygon::UvGridTriangulateInto(SMesh *mesh, SSurface *srf) { void SPolygon::UvGridTriangulateInto(SMesh *mesh, SSurface *srf) {
SEdgeList orig; SEdgeList orig = {};
ZERO(&orig);
MakeEdgesInto(&orig); MakeEdgesInto(&orig);
SEdgeList holes; SEdgeList holes = {};
ZERO(&holes);
normal = Vector::From(0, 0, 1); normal = Vector::From(0, 0, 1);
FixContourDirections(); FixContourDirections();
@ -438,8 +430,8 @@ void SPolygon::UvGridTriangulateInto(SMesh *mesh, SSurface *srf) {
// Build a rectangular grid, with horizontal and vertical lines in the // Build a rectangular grid, with horizontal and vertical lines in the
// uv plane. The spacing of these lines is adaptive, so calculate that. // uv plane. The spacing of these lines is adaptive, so calculate that.
List<double> li, lj; List<double> li, lj;
ZERO(&li); li = {};
ZERO(&lj); lj = {};
double v = 0; double v = 0;
li.Add(&v); li.Add(&v);
srf->MakeTriangulationGridInto(&li, 0, 1, true); srf->MakeTriangulationGridInto(&li, 0, 1, true);
@ -475,8 +467,7 @@ void SPolygon::UvGridTriangulateInto(SMesh *mesh, SSurface *srf) {
} }
// Add the quad to our mesh // Add the quad to our mesh
STriangle tr; STriangle tr = {};
ZERO(&tr);
tr.a = a; tr.a = a;
tr.b = b; tr.b = b;
tr.c = c; tr.c = c;
@ -494,8 +485,7 @@ void SPolygon::UvGridTriangulateInto(SMesh *mesh, SSurface *srf) {
} }
holes.CullExtraneousEdges(); holes.CullExtraneousEdges();
SPolygon hp; SPolygon hp = {};
ZERO(&hp);
holes.AssemblePolygon(&hp, NULL, true); holes.AssemblePolygon(&hp, NULL, true);
SContour *sc; SContour *sc;

View File

@ -72,8 +72,7 @@ void Style::CreateDefaultStyle(hStyle h) {
isDefaultStyle = false; isDefaultStyle = false;
} }
Style ns; Style ns = {};
ZERO(&ns);
ns.color = CnfThawColor(d->color, CnfColor(d->cnfPrefix)); ns.color = CnfThawColor(d->color, CnfColor(d->cnfPrefix));
ns.width = CnfThawFloat((float)(d->width), CnfWidth(d->cnfPrefix)); ns.width = CnfThawFloat((float)(d->width), CnfWidth(d->cnfPrefix));
ns.widthAs = UNITS_AS_PIXELS; ns.widthAs = UNITS_AS_PIXELS;

View File

@ -137,8 +137,7 @@ void System::SolveBySubstitution(void) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
int System::CalculateRank(void) { int System::CalculateRank(void) {
// Actually work with magnitudes squared, not the magnitudes // Actually work with magnitudes squared, not the magnitudes
double rowMag[MAX_UNKNOWNS]; double rowMag[MAX_UNKNOWNS] = {};
ZERO(&rowMag);
double tol = RANK_MAG_TOLERANCE*RANK_MAG_TOLERANCE; double tol = RANK_MAG_TOLERANCE*RANK_MAG_TOLERANCE;
int i, iprev, j; int i, iprev, j;

View File

@ -175,15 +175,13 @@ void TextWindow::ScreenHoverRequest(int link, uint32_t v) {
} }
void TextWindow::ScreenSelectConstraint(int link, uint32_t v) { void TextWindow::ScreenSelectConstraint(int link, uint32_t v) {
SS.GW.ClearSelection(); SS.GW.ClearSelection();
GraphicsWindow::Selection sel; GraphicsWindow::Selection sel = {};
ZERO(&sel);
sel.constraint.v = v; sel.constraint.v = v;
SS.GW.selection.Add(&sel); SS.GW.selection.Add(&sel);
} }
void TextWindow::ScreenSelectRequest(int link, uint32_t v) { void TextWindow::ScreenSelectRequest(int link, uint32_t v) {
SS.GW.ClearSelection(); SS.GW.ClearSelection();
GraphicsWindow::Selection sel; GraphicsWindow::Selection sel = {};
ZERO(&sel);
hRequest hr = { v }; hRequest hr = { v };
sel.entity = hr.entity(0); sel.entity = hr.entity(0);
SS.GW.selection.Add(&sel); SS.GW.selection.Add(&sel);

View File

@ -62,7 +62,11 @@ void TextWindow::Init(void) {
void TextWindow::ClearSuper(void) { void TextWindow::ClearSuper(void) {
HideEditControl(); HideEditControl();
// Cannot use *this = {} here because TextWindow instances
// are 2.4MB long; this causes stack overflows in prologue
// when built with MSVC, even with optimizations.
memset(this, 0, sizeof(*this)); memset(this, 0, sizeof(*this));
MakeColorTable(fgColors, fgColorTable); MakeColorTable(fgColors, fgColorTable);
MakeColorTable(bgColors, bgColorTable); MakeColorTable(bgColors, bgColorTable);

View File

@ -46,31 +46,31 @@ void SolveSpaceUI::PushFromCurrentOnto(UndoStack *uk) {
} }
UndoState *ut = &(uk->d[uk->write]); UndoState *ut = &(uk->d[uk->write]);
ZERO(ut); *ut = {};
for(i = 0; i < SK.group.n; i++) { for(i = 0; i < SK.group.n; i++) {
Group *src = &(SK.group.elem[i]); Group *src = &(SK.group.elem[i]);
Group dest = *src; Group dest = *src;
// And then clean up all the stuff that needs to be a deep copy, // And then clean up all the stuff that needs to be a deep copy,
// and zero out all the dynamic stuff that will get regenerated. // and zero out all the dynamic stuff that will get regenerated.
dest.clean = false; dest.clean = false;
ZERO(&(dest.solved)); dest.solved = {};
ZERO(&(dest.polyLoops)); dest.polyLoops = {};
ZERO(&(dest.bezierLoops)); dest.bezierLoops = {};
ZERO(&(dest.bezierOpens)); dest.bezierOpens = {};
ZERO(&(dest.polyError)); dest.polyError = {};
ZERO(&(dest.thisMesh)); dest.thisMesh = {};
ZERO(&(dest.runningMesh)); dest.runningMesh = {};
ZERO(&(dest.thisShell)); dest.thisShell = {};
ZERO(&(dest.runningShell)); dest.runningShell = {};
ZERO(&(dest.displayMesh)); dest.displayMesh = {};
ZERO(&(dest.displayEdges)); dest.displayEdges = {};
ZERO(&(dest.remap)); dest.remap = {};
src->remap.DeepCopyInto(&(dest.remap)); src->remap.DeepCopyInto(&(dest.remap));
ZERO(&(dest.impMesh)); dest.impMesh = {};
ZERO(&(dest.impShell)); dest.impShell = {};
ZERO(&(dest.impEntity)); dest.impEntity = {};
ut->group.Add(&dest); ut->group.Add(&dest);
} }
for(i = 0; i < SK.request.n; i++) { for(i = 0; i < SK.request.n; i++) {
@ -79,7 +79,7 @@ void SolveSpaceUI::PushFromCurrentOnto(UndoStack *uk) {
for(i = 0; i < SK.constraint.n; i++) { for(i = 0; i < SK.constraint.n; i++) {
Constraint *src = &(SK.constraint.elem[i]); Constraint *src = &(SK.constraint.elem[i]);
Constraint dest = *src; Constraint dest = *src;
ZERO(&(dest.dogd)); dest.dogd = {};
ut->constraint.Add(&dest); ut->constraint.Add(&dest);
} }
for(i = 0; i < SK.param.n; i++) { for(i = 0; i < SK.param.n; i++) {
@ -120,7 +120,7 @@ void SolveSpaceUI::PopOntoCurrentFrom(UndoStack *uk) {
SS.GW.activeGroup = ut->activeGroup; SS.GW.activeGroup = ut->activeGroup;
// No need to free it, since a shallow copy was made above // No need to free it, since a shallow copy was made above
ZERO(ut); *ut = {};
// And reset the state everywhere else in the program, since the // And reset the state everywhere else in the program, since the
// sketch just changed a lot. // sketch just changed a lot.
@ -141,7 +141,7 @@ void SolveSpaceUI::UndoClearStack(UndoStack *uk) {
(uk->cnt)--; (uk->cnt)--;
UndoClearState(&(uk->d[uk->write])); UndoClearState(&(uk->d[uk->write]));
} }
ZERO(uk); // for good measure *uk = {}; // for good measure
} }
void SolveSpaceUI::UndoClearState(UndoState *ut) { void SolveSpaceUI::UndoClearState(UndoState *ut) {
@ -156,6 +156,6 @@ void SolveSpaceUI::UndoClearState(UndoState *ut) {
ut->constraint.Clear(); ut->constraint.Clear();
ut->param.Clear(); ut->param.Clear();
ut->style.Clear(); ut->style.Clear();
ZERO(ut); *ut = {};
} }

View File

@ -135,8 +135,7 @@ void SolveSpace::DoMessageBox(const char *str, int rows, int cols, bool error)
//HWND h = GetForegroundWindow(); //HWND h = GetForegroundWindow();
// Register the window class for our dialog. // Register the window class for our dialog.
WNDCLASSEX wc; WNDCLASSEX wc = {};
memset(&wc, 0, sizeof(wc));
wc.cbSize = sizeof(wc); wc.cbSize = sizeof(wc);
wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_OWNDC; wc.style = CS_BYTEALIGNCLIENT | CS_BYTEALIGNWINDOW | CS_OWNDC;
wc.lpfnWndProc = (WNDPROC)MessageProc; wc.lpfnWndProc = (WNDPROC)MessageProc;
@ -345,8 +344,7 @@ static void PaintTextWnd(HDC hdc)
void SolveSpace::MoveTextScrollbarTo(int pos, int maxPos, int page) void SolveSpace::MoveTextScrollbarTo(int pos, int maxPos, int page)
{ {
SCROLLINFO si; SCROLLINFO si = {};
memset(&si, 0, sizeof(si));
si.cbSize = sizeof(si); si.cbSize = sizeof(si);
si.fMask = SIF_DISABLENOSCROLL | SIF_ALL; si.fMask = SIF_DISABLENOSCROLL | SIF_ALL;
si.nMin = 0; si.nMin = 0;
@ -488,8 +486,7 @@ LRESULT CALLBACK TextWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
case WM_MOUSEMOVE: { case WM_MOUSEMOVE: {
// We need this in order to get the WM_MOUSELEAVE // We need this in order to get the WM_MOUSELEAVE
TRACKMOUSEEVENT tme; TRACKMOUSEEVENT tme = {};
ZERO(&tme);
tme.cbSize = sizeof(tme); tme.cbSize = sizeof(tme);
tme.dwFlags = TME_LEAVE; tme.dwFlags = TME_LEAVE;
tme.hwndTrack = TextWnd; tme.hwndTrack = TextWnd;
@ -535,8 +532,7 @@ static bool ProcessKeyDown(WPARAM wParam)
{ {
if(GraphicsEditControlIsVisible() && wParam != VK_ESCAPE) { if(GraphicsEditControlIsVisible() && wParam != VK_ESCAPE) {
if(wParam == VK_RETURN) { if(wParam == VK_RETURN) {
char s[1024]; char s[1024] = {};
memset(s, 0, sizeof(s));
SendMessage(GraphicsEditControl, WM_GETTEXT, 900, (LPARAM)s); SendMessage(GraphicsEditControl, WM_GETTEXT, 900, (LPARAM)s);
SS.GW.EditControlDone(s); SS.GW.EditControlDone(s);
return true; return true;
@ -546,8 +542,7 @@ static bool ProcessKeyDown(WPARAM wParam)
} }
if(TextEditControlIsVisible() && wParam != VK_ESCAPE) { if(TextEditControlIsVisible() && wParam != VK_ESCAPE) {
if(wParam == VK_RETURN) { if(wParam == VK_RETURN) {
char s[1024]; char s[1024] = {};
memset(s, 0, sizeof(s));
SendMessage(TextEditControl, WM_GETTEXT, 900, (LPARAM)s); SendMessage(TextEditControl, WM_GETTEXT, 900, (LPARAM)s);
SS.TW.EditControlDone(s); SS.TW.EditControlDone(s);
} else { } else {
@ -638,10 +633,9 @@ static void CreateGlContext(HWND hwnd, HGLRC *glrc)
{ {
HDC hdc = GetDC(hwnd); HDC hdc = GetDC(hwnd);
PIXELFORMATDESCRIPTOR pfd; PIXELFORMATDESCRIPTOR pfd = {};
int pixelFormat; int pixelFormat;
memset(&pfd, 0, sizeof(pfd));
pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
pfd.nVersion = 1; pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
@ -791,8 +785,7 @@ LRESULT CALLBACK GraphicsWndProc(HWND hwnd, UINT msg, WPARAM wParam,
int y = HIWORD(lParam); int y = HIWORD(lParam);
// We need this in order to get the WM_MOUSELEAVE // We need this in order to get the WM_MOUSELEAVE
TRACKMOUSEEVENT tme; TRACKMOUSEEVENT tme = {};
ZERO(&tme);
tme.cbSize = sizeof(tme); tme.cbSize = sizeof(tme);
tme.dwFlags = TME_LEAVE; tme.dwFlags = TME_LEAVE;
tme.hwndTrack = GraphicsWnd; tme.hwndTrack = GraphicsWnd;
@ -873,9 +866,8 @@ LRESULT CALLBACK GraphicsWndProc(HWND hwnd, UINT msg, WPARAM wParam,
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
bool SolveSpace::GetOpenFile(char *file, const char *defExtension, const char *selPattern) bool SolveSpace::GetOpenFile(char *file, const char *defExtension, const char *selPattern)
{ {
OPENFILENAME ofn; OPENFILENAME ofn = {};
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn); ofn.lStructSize = sizeof(ofn);
ofn.hInstance = Instance; ofn.hInstance = Instance;
ofn.hwndOwner = GraphicsWnd; ofn.hwndOwner = GraphicsWnd;
@ -899,9 +891,8 @@ bool SolveSpace::GetOpenFile(char *file, const char *defExtension, const char *s
bool SolveSpace::GetSaveFile(char *file, const char *defExtension, const char *selPattern) bool SolveSpace::GetSaveFile(char *file, const char *defExtension, const char *selPattern)
{ {
OPENFILENAME ofn; OPENFILENAME ofn = {};
memset(&ofn, 0, sizeof(ofn));
ofn.lStructSize = sizeof(ofn); ofn.lStructSize = sizeof(ofn);
ofn.hInstance = Instance; ofn.hInstance = Instance;
ofn.hwndOwner = GraphicsWnd; ofn.hwndOwner = GraphicsWnd;
@ -979,8 +970,7 @@ void SolveSpace::LoadAllFontFiles(void)
HANDLE h = FindFirstFile(dir, &wfd); HANDLE h = FindFirstFile(dir, &wfd);
while(h != INVALID_HANDLE_VALUE) { while(h != INVALID_HANDLE_VALUE) {
TtfFont tf; TtfFont tf = {};
ZERO(&tf);
char fullPath[MAX_PATH]; char fullPath[MAX_PATH];
GetWindowsDirectory(fullPath, MAX_PATH - (30 + (UINT)strlen(wfd.cFileName))); GetWindowsDirectory(fullPath, MAX_PATH - (30 + (UINT)strlen(wfd.cFileName)));
@ -1098,9 +1088,8 @@ HMENU CreateGraphicsWindowMenus(void)
static void CreateMainWindows(void) static void CreateMainWindows(void)
{ {
WNDCLASSEX wc; WNDCLASSEX wc = {};
memset(&wc, 0, sizeof(wc));
wc.cbSize = sizeof(wc); wc.cbSize = sizeof(wc);
// The graphics window, where the sketch is drawn and shown. // The graphics window, where the sketch is drawn and shown.