Skip to content

Commit

Permalink
Perform vertex serialization as doubles, as that's what we compute in (
Browse files Browse the repository at this point in the history
  • Loading branch information
kintel authored Dec 6, 2024
1 parent c190dac commit 40472a8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
14 changes: 6 additions & 8 deletions src/io/export_stl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace {
#define DC_MAX_LEADING_ZEROES (5)
#define DC_MAX_TRAILING_ZEROES (0)

std::string toString(const Vector3f& v)
std::string toString(const Vector3d& v)
{
double_conversion::DoubleToStringConverter dc(
DC_FLAGS, DC_INF, DC_NAN, DC_EXP,
Expand All @@ -72,11 +72,11 @@ std::string toString(const Vector3f& v)
char buffer[DC_BUFFER_SIZE];

double_conversion::StringBuilder builder(buffer, DC_BUFFER_SIZE);
dc.ToShortestSingle(v[0], &builder);
dc.ToShortest(v[0], &builder);
builder.AddCharacter(' ');
dc.ToShortestSingle(v[1], &builder);
dc.ToShortest(v[1], &builder);
builder.AddCharacter(' ');
dc.ToShortestSingle(v[2], &builder);
dc.ToShortest(v[2], &builder);
builder.Finalize();

return buffer;
Expand Down Expand Up @@ -127,8 +127,7 @@ uint64_t append_stl(std::shared_ptr<const PolySet> polyset, std::ostream& output
if (!binary) {
vertexStrings.resize(ps->vertices.size());
std::transform(ps->vertices.begin(), ps->vertices.end(), vertexStrings.begin(),
[](const auto& p)
{ return toString({static_cast<float>(p.x()), static_cast<float>(p.y()) , static_cast<float>(p.z()) }); });
[](const auto& p) { return toString(p); });
}

// Used for binary mode only
Expand Down Expand Up @@ -172,8 +171,7 @@ uint64_t append_stl(std::shared_ptr<const PolySet> polyset, std::ostream& output
assert(s0 != s1 && s0 != s2 && s1 != s2);

output << " facet normal ";
output << toString(
{static_cast<float>(normal.x()), static_cast<float>(normal.y()), static_cast<float>(normal.z()) }) << "\n";
output << toString(normal) << "\n";
output << " outer loop\n";
output << " vertex " << s0 << "\n";
output << " vertex " << s1 << "\n";
Expand Down
16 changes: 8 additions & 8 deletions tests/regression/stlexport/stl-export-expected.stl
Original file line number Diff line number Diff line change
@@ -1,54 +1,54 @@
solid OpenSCAD_Model
facet normal -0.6396021 -0.6396021 0.42640144
facet normal -0.6396021490668313 -0.6396021490668313 0.42640143271122083
outer loop
vertex -4 0 6
vertex 0 -4 6
vertex 0 0 12
endloop
endfacet
facet normal -0.6396021 -0.6396021 -0.42640144
facet normal -0.6396021490668313 -0.6396021490668313 -0.42640143271122083
outer loop
vertex -4 0 6
vertex 0 0 0
vertex 0 -4 6
endloop
endfacet
facet normal -0.6396021 0.6396021 0.42640144
facet normal -0.6396021490668313 0.6396021490668313 0.42640143271122083
outer loop
vertex -4 0 6
vertex 0 0 12
vertex 0 4 6
endloop
endfacet
facet normal -0.6396021 0.6396021 -0.42640144
facet normal -0.6396021490668313 0.6396021490668313 -0.42640143271122083
outer loop
vertex -4 0 6
vertex 0 4 6
vertex 0 0 0
endloop
endfacet
facet normal 0.6396021 -0.6396021 -0.42640144
facet normal 0.6396021490668313 -0.6396021490668313 -0.42640143271122083
outer loop
vertex 0 -4 6
vertex 0 0 0
vertex 4 0 6
endloop
endfacet
facet normal 0.6396021 -0.6396021 0.42640144
facet normal 0.6396021490668313 -0.6396021490668313 0.42640143271122083
outer loop
vertex 0 -4 6
vertex 4 0 6
vertex 0 0 12
endloop
endfacet
facet normal 0.6396021 0.6396021 -0.42640144
facet normal 0.6396021490668313 0.6396021490668313 -0.42640143271122083
outer loop
vertex 0 0 0
vertex 0 4 6
vertex 4 0 6
endloop
endfacet
facet normal 0.6396021 0.6396021 0.42640144
facet normal 0.6396021490668313 0.6396021490668313 0.42640143271122083
outer loop
vertex 0 0 12
vertex 4 0 6
Expand Down

0 comments on commit 40472a8

Please sign in to comment.