Skip to content

Commit

Permalink
Double precision (#895)
Browse files Browse the repository at this point in the history
* added configuration summary

* use custom math type

* use std function if possible

* build success

* fix js binding

* format

* use better primitives

* use old precision for polygon tests

* fix polygon CCW check

* temp-fix tests

* add simpler failing test case

* refactored CutKeyhole

* fixed tests

* more keyholing fixes

* truncate long debug output

* shrink SDF blobs test

* fixed WASM and disabled zebra

* fix hull

* cleanup a bit

* fix wasm

* CI cleanuo

* reenable zebra

* upped precision and fixed tests

* fix format

* disable zebra test on windows

---------

Co-authored-by: Emmett Lalish <[email protected]>
  • Loading branch information
pca006132 and elalish authored Sep 3, 2024
1 parent d0d5106 commit 492c3a8
Show file tree
Hide file tree
Showing 84 changed files with 66,185 additions and 66,009 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/manifold.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
with:
submodules: recursive
- uses: jwlawson/actions-setup-cmake@v2
- name: Build ${{matrix.backend}}
- name: Build ${{matrix.parallel_backend}}
if: matrix.parallel_backend != 'NONE'
run: |
mkdir build
Expand Down Expand Up @@ -106,7 +106,7 @@ jobs:
mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DMANIFOLD_PYBIND=ON -DMANIFOLD_DEBUG=ON -DMANIFOLD_CBIND=ON -DMANIFOLD_PAR=TBB .. && make
- name: Test ${{matrix.parallel_backend}}
- name: Test
run: |
cd build/test
./manifold_test --gtest_filter=CBIND.*
Expand Down Expand Up @@ -174,7 +174,7 @@ jobs:
submodules: recursive
- uses: jwlawson/actions-setup-cmake@v2
- uses: ilammy/msvc-dev-cmd@v1
- name: Build ${{matrix.backend}}
- name: Build ${{matrix.parallel_backend}}
shell: powershell
run: |
cmake . -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF -DMANIFOLD_DEBUG=ON -DMANIFOLD_PAR=${{matrix.parallel_backend}} -A x64 -B build
Expand All @@ -184,7 +184,7 @@ jobs:
shell: bash
run: |
cd build/bin/Release
./manifold_test.exe
./manifold_test.exe --gtest_filter=-Polygon.Zebra*
cd ../../
- name: test cmake consumer
run: |
Expand Down
4 changes: 4 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
"args": [
"--gtest_break_on_failure",
"--gtest_catch_exceptions=0",
<<<<<<< HEAD

This comment has been minimized.

Copy link
@kzhsw

kzhsw Sep 4, 2024

Is this something wrong with merging

This comment has been minimized.

Copy link
@elalish

elalish Sep 4, 2024

Author Owner

Ha, indeed - probably why these shouldn't be checked in in the first place. Thanks, will fix!

"--gtest_filter=Polygon.MultiMerge"
=======
"--gtest_filter=Samples.GyroidModule"
>>>>>>> fbf07bf92a1d8cb380aec321f920d1db5d772f20
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build/test",
Expand Down
50 changes: 50 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,53 @@ install(FILES ${CMAKE_CURRENT_BINARY_DIR}/manifold.pc
DESTINATION lib/pkgconfig)

endif()

# configuration summary, idea from openscad
# https://github.com/openscad/openscad/blob/master/cmake/Modules/info.cmake
message(STATUS "====================================")
message(STATUS "Manifold Build Configuration Summary")
message(STATUS "====================================")
message(STATUS " ")
if (MXECROSS)
message(STATUS "Environment: MXE")
elseif (APPLE)
message(STATUS "Environment: macOS")
elseif (WIN32)
if (MINGW)
message(STATUS "Environment: msys2")
else()
message(STATUS "Environment: Windows")
endif()
elseif (LINUX)
message(STATUS "Environment: Linux")
elseif(UNIX)
message(STATUS "Environment: Unknown Unix")
else()
message(STATUS "Environment: Unknown")
endif()
message(STATUS " ")
message(STATUS "CMAKE_VERSION: ${CMAKE_VERSION}")
message(STATUS "CMAKE_TOOLCHAIN_FILE: ${CMAKE_TOOLCHAIN_FILE}")
message(STATUS "CMAKE_GENERATOR: ${CMAKE_GENERATOR}")
message(STATUS "CPACK_CMAKE_GENERATOR: ${CPACK_CMAKE_GENERATOR}")
message(STATUS "CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}")
message(STATUS "CMAKE_PREFIX_PATH: ${CMAKE_PREFIX_PATH}")
message(STATUS "CMAKE_CXX_COMPILER_ID: ${CMAKE_CXX_COMPILER_ID}")
message(STATUS "CMAKE_CXX_COMPILER_VERSION: ${CMAKE_CXX_COMPILER_VERSION}")
if (APPLE)
message(STATUS "CMAKE_OSX_DEPLOYMENT_TARGET: ${CMAKE_OSX_DEPLOYMENT_TARGET}")
message(STATUS "CMAKE_OSX_ARCHITECTURES: ${CMAKE_OSX_ARCHITECTURES}")
endif()
message(STATUS "BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}")
message(STATUS " ")
message(STATUS "MANIFOLD_PAR: ${MANIFOLD_PAR}")
message(STATUS "MANIFOLD_FLAGS: ${MANIFOLD_FLAGS}")
message(STATUS "MANIFOLD_EXPORT: ${MANIFOLD_EXPORT}")
message(STATUS "MANIFOLD_TEST: ${MANIFOLD_TEST}")
message(STATUS "MANIFOLD_FUZZ: ${MANIFOLD_FUZZ}")
message(STATUS "MANIFOLD_DEBUG: ${MANIFOLD_DEBUG}")
message(STATUS "MANIFOLD_PYBIND: ${MANIFOLD_PYBIND}")
message(STATUS "MANIFOLD_CBIND: ${MANIFOLD_CBIND}")
message(STATUS "MANIFOLD_JSBIND: ${MANIFOLD_JSBIND}")
message(STATUS "MANIFOLD_EXCEPTIONS: ${MANIFOLD_EXCEPTIONS}")
message(STATUS " ")
44 changes: 22 additions & 22 deletions bindings/c/box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
#include "public.h"
#include "types.h"

ManifoldBox *manifold_box(void *mem, float x1, float y1, float z1, float x2,
float y2, float z2) {
auto p1 = glm::vec3(x1, y1, z1);
auto p2 = glm::vec3(x2, y2, z2);
ManifoldBox *manifold_box(void *mem, double x1, double y1, double z1, double x2,
double y2, double z2) {
auto p1 = vec3(x1, y1, z1);
auto p2 = vec3(x2, y2, z2);
auto box = new (mem) Box(p1, p2);
return to_c(box);
}
Expand All @@ -39,10 +39,10 @@ ManifoldVec3 manifold_box_center(ManifoldBox *b) {
return {v.x, v.y, v.z};
}

float manifold_box_scale(ManifoldBox *b) { return from_c(b)->Scale(); }
double manifold_box_scale(ManifoldBox *b) { return from_c(b)->Scale(); }

int manifold_box_contains_pt(ManifoldBox *b, float x, float y, float z) {
auto p = glm::vec3(x, y, z);
int manifold_box_contains_pt(ManifoldBox *b, double x, double y, double z) {
auto p = vec3(x, y, z);
return from_c(b)->Contains(p);
}

Expand All @@ -52,9 +52,9 @@ int manifold_box_contains_box(ManifoldBox *a, ManifoldBox *b) {
return outer.Contains(inner);
}

void manifold_box_include_pt(ManifoldBox *b, float x, float y, float z) {
void manifold_box_include_pt(ManifoldBox *b, double x, double y, double z) {
auto box = *from_c(b);
auto p = glm::vec3(x, y, z);
auto p = vec3(x, y, z);
box.Union(p);
}

Expand All @@ -63,31 +63,31 @@ ManifoldBox *manifold_box_union(void *mem, ManifoldBox *a, ManifoldBox *b) {
return to_c(new (mem) Box(box));
}

ManifoldBox *manifold_box_transform(void *mem, ManifoldBox *b, float x1,
float y1, float z1, float x2, float y2,
float z2, float x3, float y3, float z3,
float x4, float y4, float z4) {
auto mat = glm::mat4x3(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4);
ManifoldBox *manifold_box_transform(void *mem, ManifoldBox *b, double x1,
double y1, double z1, double x2, double y2,
double z2, double x3, double y3, double z3,
double x4, double y4, double z4) {
auto mat = mat4x3(x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4);
auto transformed = from_c(b)->Transform(mat);
return to_c(new (mem) Box(transformed));
}

ManifoldBox *manifold_box_translate(void *mem, ManifoldBox *b, float x, float y,
float z) {
auto p = glm::vec3(x, y, z);
ManifoldBox *manifold_box_translate(void *mem, ManifoldBox *b, double x,
double y, double z) {
auto p = vec3(x, y, z);
auto translated = (*from_c(b)) + p;
return to_c(new (mem) Box(translated));
}

ManifoldBox *manifold_box_mul(void *mem, ManifoldBox *b, float x, float y,
float z) {
auto p = glm::vec3(x, y, z);
ManifoldBox *manifold_box_mul(void *mem, ManifoldBox *b, double x, double y,
double z) {
auto p = vec3(x, y, z);
auto scaled = (*from_c(b)) * p;
return to_c(new (mem) Box(scaled));
}

int manifold_box_does_overlap_pt(ManifoldBox *b, float x, float y, float z) {
auto p = glm::vec3(x, y, z);
int manifold_box_does_overlap_pt(ManifoldBox *b, double x, double y, double z) {
auto p = vec3(x, y, z);
return from_c(b)->DoesOverlap(p);
}

Expand Down
26 changes: 13 additions & 13 deletions bindings/c/conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,11 @@ ManifoldRect *to_c(manifold::Rect *m) {
return reinterpret_cast<ManifoldRect *>(m);
}

ManifoldVec2 to_c(glm::vec2 v) { return {v.x, v.y}; }
ManifoldVec2 to_c(vec2 v) { return {v.x, v.y}; }

ManifoldVec3 to_c(glm::vec3 v) { return {v.x, v.y, v.z}; }
ManifoldVec3 to_c(vec3 v) { return {v.x, v.y, v.z}; }

ManifoldIVec3 to_c(glm::ivec3 v) { return {v.x, v.y, v.z}; }
ManifoldIVec3 to_c(ivec3 v) { return {v.x, v.y, v.z}; }

ManifoldProperties to_c(manifold::Properties p) {
return {p.surfaceArea, p.volume};
Expand Down Expand Up @@ -216,32 +216,32 @@ const manifold::Rect *from_c(ManifoldRect *m) {
return reinterpret_cast<manifold::Rect const *>(m);
}

glm::vec2 from_c(ManifoldVec2 v) { return glm::vec2(v.x, v.y); }
vec2 from_c(ManifoldVec2 v) { return vec2(v.x, v.y); }

glm::vec3 from_c(ManifoldVec3 v) { return glm::vec3(v.x, v.y, v.z); }
vec3 from_c(ManifoldVec3 v) { return vec3(v.x, v.y, v.z); }

glm::ivec3 from_c(ManifoldIVec3 v) { return glm::ivec3(v.x, v.y, v.z); }
ivec3 from_c(ManifoldIVec3 v) { return ivec3(v.x, v.y, v.z); }

glm::vec4 from_c(ManifoldVec4 v) { return glm::vec4(v.x, v.y, v.z, v.w); }
vec4 from_c(ManifoldVec4 v) { return vec4(v.x, v.y, v.z, v.w); }

std::vector<glm::vec3> vector_of_vec_array(ManifoldVec3 *vs, size_t length) {
auto vec = std::vector<glm::vec3>();
std::vector<vec3> vector_of_vec_array(ManifoldVec3 *vs, size_t length) {
auto vec = std::vector<vec3>();
for (size_t i = 0; i < length; ++i) {
vec.push_back(from_c(vs[i]));
}
return vec;
}

std::vector<glm::ivec3> vector_of_vec_array(ManifoldIVec3 *vs, size_t length) {
auto vec = std::vector<glm::ivec3>();
std::vector<ivec3> vector_of_vec_array(ManifoldIVec3 *vs, size_t length) {
auto vec = std::vector<ivec3>();
for (size_t i = 0; i < length; ++i) {
vec.push_back(from_c(vs[i]));
}
return vec;
}

std::vector<glm::vec4> vector_of_vec_array(ManifoldVec4 *vs, size_t length) {
auto vec = std::vector<glm::vec4>();
std::vector<vec4> vector_of_vec_array(ManifoldVec4 *vs, size_t length) {
auto vec = std::vector<vec4>();
for (size_t i = 0; i < length; ++i) {
vec.push_back(from_c(vs[i]));
}
Expand Down
36 changes: 18 additions & 18 deletions bindings/c/cross.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ void manifold_cross_section_vec_push_back(ManifoldCrossSectionVec *csv,
return from_c(csv)->push_back(*from_c(cs));
}

ManifoldCrossSection *manifold_cross_section_square(void *mem, float x, float y,
int center) {
auto cs = CrossSection::Square(glm::vec2(x, y), center);
ManifoldCrossSection *manifold_cross_section_square(void *mem, double x,
double y, int center) {
auto cs = CrossSection::Square(vec2(x, y), center);
return to_c(new (mem) CrossSection(cs));
}

ManifoldCrossSection *manifold_cross_section_circle(void *mem, float radius,
ManifoldCrossSection *manifold_cross_section_circle(void *mem, double radius,
int circular_segments) {
auto cs = CrossSection::Circle(radius, circular_segments);
return to_c(new (mem) CrossSection(cs));
Expand Down Expand Up @@ -145,49 +145,49 @@ ManifoldCrossSection *manifold_cross_section_hull_polygons(

ManifoldCrossSection *manifold_cross_section_translate(void *mem,
ManifoldCrossSection *cs,
float x, float y) {
auto translated = from_c(cs)->Translate(glm::vec2(x, y));
double x, double y) {
auto translated = from_c(cs)->Translate(vec2(x, y));
return to_c(new (mem) CrossSection(translated));
}

ManifoldCrossSection *manifold_cross_section_rotate(void *mem,
ManifoldCrossSection *cs,
float deg) {
double deg) {
auto rotated = from_c(cs)->Rotate(deg);
return to_c(new (mem) CrossSection(rotated));
}

ManifoldCrossSection *manifold_cross_section_scale(void *mem,
ManifoldCrossSection *cs,
float x, float y) {
auto scaled = from_c(cs)->Scale(glm::vec2(x, y));
double x, double y) {
auto scaled = from_c(cs)->Scale(vec2(x, y));
return to_c(new (mem) CrossSection(scaled));
}

ManifoldCrossSection *manifold_cross_section_mirror(void *mem,
ManifoldCrossSection *cs,
float ax_x, float ax_y) {
auto mirrored = from_c(cs)->Mirror(glm::vec2(ax_x, ax_y));
double ax_x, double ax_y) {
auto mirrored = from_c(cs)->Mirror(vec2(ax_x, ax_y));
return to_c(new (mem) CrossSection(mirrored));
}

ManifoldCrossSection *manifold_cross_section_transform(void *mem,
ManifoldCrossSection *cs,
float x1, float y1,
float x2, float y2,
float x3, float y3) {
auto mat = glm::mat3x2(x1, y1, x2, y2, x3, y3);
double x1, double y1,
double x2, double y2,
double x3, double y3) {
auto mat = mat3x2(x1, y1, x2, y2, x3, y3);
auto transformed = from_c(cs)->Transform(mat);
return to_c(new (mem) CrossSection(transformed));
}

ManifoldCrossSection *manifold_cross_section_warp(
void *mem, ManifoldCrossSection *cs,
ManifoldVec2 (*fun)(float, float, void *), void *ctx) {
ManifoldVec2 (*fun)(double, double, void *), void *ctx) {
// Bind function with context argument to one without
using namespace std::placeholders;
std::function<ManifoldVec2(float, float)> f2 = std::bind(fun, _1, _2, ctx);
std::function<void(glm::vec2 & v)> warp = [f2](glm::vec2 &v) {
std::function<ManifoldVec2(double, double)> f2 = std::bind(fun, _1, _2, ctx);
std::function<void(vec2 & v)> warp = [f2](vec2 &v) {
v = from_c(f2(v.x, v.y));
};
auto warped = from_c(cs)->Warp(warp);
Expand Down
20 changes: 10 additions & 10 deletions bindings/c/include/conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ ManifoldMeshGL *to_c(manifold::MeshGL *m);
ManifoldBox *to_c(manifold::Box *m);
ManifoldRect *to_c(manifold::Rect *m);
ManifoldError to_c(manifold::Manifold::Error error);
ManifoldVec2 to_c(glm::vec2 v);
ManifoldVec3 to_c(glm::vec3 v);
ManifoldIVec3 to_c(glm::ivec3 v);
ManifoldVec2 to_c(vec2 v);
ManifoldVec3 to_c(vec3 v);
ManifoldIVec3 to_c(ivec3 v);
ManifoldProperties to_c(manifold::Properties p);

const manifold::Manifold *from_c(ManifoldManifold *m);
Expand All @@ -54,14 +54,14 @@ CrossSection::FillRule from_c(ManifoldFillRule fillrule);
CrossSection::JoinType from_c(ManifoldJoinType jt);
const manifold::Box *from_c(ManifoldBox *m);
const manifold::Rect *from_c(ManifoldRect *r);
glm::vec2 from_c(ManifoldVec2 v);
glm::vec3 from_c(ManifoldVec3 v);
glm::ivec3 from_c(ManifoldIVec3 v);
glm::vec4 from_c(ManifoldVec4 v);
vec2 from_c(ManifoldVec2 v);
vec3 from_c(ManifoldVec3 v);
ivec3 from_c(ManifoldIVec3 v);
vec4 from_c(ManifoldVec4 v);

std::vector<glm::vec3> vector_of_vec_array(ManifoldVec3 *vs, size_t length);
std::vector<glm::ivec3> vector_of_vec_array(ManifoldIVec3 *vs, size_t length);
std::vector<glm::vec4> vector_of_vec_array(ManifoldVec4 *vs, size_t length);
std::vector<vec3> vector_of_vec_array(ManifoldVec3 *vs, size_t length);
std::vector<ivec3> vector_of_vec_array(ManifoldIVec3 *vs, size_t length);
std::vector<vec4> vector_of_vec_array(ManifoldVec4 *vs, size_t length);

template <typename T>
std::vector<T> vector_of_array(T *ts, size_t length) {
Expand Down
Loading

0 comments on commit 492c3a8

Please sign in to comment.