Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chores #833

Merged
merged 26 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/manifold.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ jobs:
timeout-minutes: 30
runs-on: ubuntu-22.04
if: github.event.pull_request.draft == false
strategy:
matrix:
exception: [ON, OFF]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason to build WASM with exceptions off? Maybe better to test one of the nix builds since they're fast?

Copy link
Contributor

@fire fire Jun 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If testing generally exceptions off is the test. then it could be linux.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fire I think your earlier comment mentioned you do build WASM with exceptions off - that requires special CMake instructions which I was considering removing since JS is generally exceptions-based. But if WASM sans exceptions is actually useful to someone, then @pca006132 has it set up properly now. Do you build for WASM without exceptions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect to build Godot Engine WASM without exceptions since the Godot Engine editor and Godot Engine game templates build without exceptions in the default configuration on all platforms.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Okay, let's leave it as is in this PR then.

steps:
- name: Install dependencies
run: |
Expand All @@ -128,7 +131,7 @@ jobs:
source ./emsdk/emsdk_env.sh
mkdir build
cd build
emcmake cmake -DCMAKE_BUILD_TYPE=Release .. && emmake make
emcmake cmake -DCMAKE_BUILD_TYPE=Release -DMANIFOLD_EXCEPTIONS=${{matrix.exception}} .. && emmake make
- name: Test WASM
run: |
cd build/test
Expand All @@ -142,6 +145,7 @@ jobs:
cp ../manifold.* ./dist/
- name: Upload WASM files
uses: actions/upload-artifact@v4
if: matrix.exception == 'ON'
with:
name: wasm
path: bindings/wasm/examples/dist/
Expand Down
14 changes: 10 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ option(MANIFOLD_DEBUG "Enable debug tracing/timing" OFF)
option(MANIFOLD_PYBIND "Build python bindings" OFF)
option(MANIFOLD_CBIND "Build C (FFI) bindings" ON)
option(MANIFOLD_JSBIND "Build js binding" ${EMSCRIPTEN})
option(MANIFOLD_EXCEPTIONS "Build manifold with exception enabled" ON)
option(BUILD_SHARED_LIBS "Build shared library" ON)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

Expand Down Expand Up @@ -59,8 +60,13 @@ endif()

if(EMSCRIPTEN)
message("Building for Emscripten")
set(MANIFOLD_FLAGS -fexceptions -D_LIBCUDACXX_HAS_THREAD_API_EXTERNAL -D_LIBCUDACXX_HAS_THREAD_API_CUDA)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sALLOW_MEMORY_GROWTH=1 -fexceptions -sDISABLE_EXCEPTION_CATCHING=0")
if(MANIFOLD_EXCEPTIONS)
set(MANIFOLD_FLAGS -fexceptions -D_LIBCUDACXX_HAS_THREAD_API_EXTERNAL -D_LIBCUDACXX_HAS_THREAD_API_CUDA)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sALLOW_MEMORY_GROWTH=1 -fexceptions -sDISABLE_EXCEPTION_CATCHING=0")
else()
set(MANIFOLD_FLAGS -D_LIBCUDACXX_HAS_THREAD_API_EXTERNAL -D_LIBCUDACXX_HAS_THREAD_API_CUDA)
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -sALLOW_MEMORY_GROWTH=1")
endif()
set(MANIFOLD_PYBIND OFF)
set(BUILD_SHARED_LIBS OFF)
endif()
Expand All @@ -86,10 +92,10 @@ if (MSVC)
set(MANIFOLD_FLAGS ${MANIFOLD_FLAGS} /DNOMINMAX)
else()
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(WARNING_FLAGS -Werror -Wall -Wno-sign-compare -Wno-unused -Wno-array-bounds
set(WARNING_FLAGS -Werror -Wall -Wno-unused -Wno-array-bounds
-Wno-stringop-overflow -Wno-alloc-size-larger-than)
else()
set(WARNING_FLAGS -Werror -Wall -Wno-sign-compare -Wno-unused)
set(WARNING_FLAGS -Werror -Wall -Wno-unused)
endif()
set(MANIFOLD_FLAGS ${MANIFOLD_FLAGS} ${WARNING_FLAGS})
endif()
Expand Down
6 changes: 3 additions & 3 deletions bindings/c/conv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,23 +227,23 @@ glm::vec4 from_c(ManifoldVec4 v) { return glm::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>();
for (int i = 0; i < length; ++i) {
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>();
for (int i = 0; i < length; ++i) {
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>();
for (int i = 0; i < length; ++i) {
for (size_t i = 0; i < length; ++i) {
vec.push_back(from_c(vs[i]));
}
return vec;
Expand Down
2 changes: 1 addition & 1 deletion bindings/c/include/conv.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ std::vector<glm::vec4> vector_of_vec_array(ManifoldVec4 *vs, size_t length);
template <typename T>
std::vector<T> vector_of_array(T *ts, size_t length) {
auto vec = std::vector<T>();
for (int i = 0; i < length; ++i) {
for (size_t i = 0; i < length; ++i) {
vec.push_back(ts[i]);
}
return vec;
Expand Down
6 changes: 3 additions & 3 deletions bindings/c/manifoldc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ extern "C" {
ManifoldSimplePolygon *manifold_simple_polygon(void *mem, ManifoldVec2 *ps,
size_t length) {
auto vec = new (mem) std::vector<glm::vec2>;
for (int i = 0; i < length; ++i) {
for (size_t i = 0; i < length; ++i) {
vec->push_back({ps[i].x, ps[i].y});
}
return to_c(vec);
Expand All @@ -68,7 +68,7 @@ ManifoldPolygons *manifold_polygons(void *mem, ManifoldSimplePolygon **ps,
size_t length) {
auto vec = new (mem) std::vector<SimplePolygon>;
auto polys = reinterpret_cast<SimplePolygon **>(ps);
for (int i = 0; i < length; ++i) {
for (size_t i = 0; i < length; ++i) {
vec->push_back(*polys[i]);
}
return to_c(vec);
Expand Down Expand Up @@ -216,7 +216,7 @@ ManifoldManifold *manifold_batch_hull(void *mem, ManifoldManifoldVec *ms) {
ManifoldManifold *manifold_hull_pts(void *mem, ManifoldVec3 *ps,
size_t length) {
std::vector<glm::vec3> vec(length);
for (int i = 0; i < length; ++i) {
for (size_t i = 0; i < length; ++i) {
vec[i] = {ps[i].x, ps[i].y, ps[i].z};
}
auto hulled = Manifold::Hull(vec);
Expand Down
11 changes: 6 additions & 5 deletions bindings/python/manifold3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ struct nb::detail::type_caster<glm::vec<N, T, Q>> {
int size = PyObject_Size(src.ptr()); // negative on failure
if (size != N) return false;
make_caster<T> t_cast;
for (size_t i = 0; i < size; i++) {
for (int i = 0; i < size; i++) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems backwards?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, should fix this. Thanks.

if (!t_cast.from_python(src[i], flags, cleanup)) return false;
value[i] = t_cast.value;
}
Expand Down Expand Up @@ -155,7 +155,7 @@ struct nb::detail::type_caster<std::vector<glm::vec<N, T, Q>>> {
size_t num_vec = vec.size();
T *buffer = new T[num_vec * N];
nb::capsule mem_mgr(buffer, [](void *p) noexcept { delete[](T *) p; });
for (int i = 0; i < num_vec; i++) {
for (size_t i = 0; i < num_vec; i++) {
for (int j = 0; j < N; j++) {
buffer[i * N + j] = vec[i][j];
}
Expand Down Expand Up @@ -298,7 +298,8 @@ NB_MODULE(manifold3d, m) {
nb::ndarray<float, nb::shape<nb::any>> array;
std::vector<float> vec;
if (nb::try_cast(result, array)) {
if (array.ndim() != 1 || array.shape(0) != newNumProp)
if (array.ndim() != 1 ||
array.shape(0) != static_cast<size_t>(newNumProp))
throw std::runtime_error("Invalid vector shape, expected (" +
std::to_string(newNumProp) + ")");
for (int i = 0; i < newNumProp; i++) newProps[i] = array(i);
Expand Down Expand Up @@ -384,7 +385,7 @@ NB_MODULE(manifold3d, m) {
"sharpened_edges.size() != edge_smoothness.size()");
}
std::vector<Smoothness> vec(sharpened_edges.size());
for (int i = 0; i < vec.size(); i++) {
for (size_t i = 0; i < vec.size(); i++) {
vec[i] = {sharpened_edges[i], edge_smoothness[i]};
}
return Manifold::Smooth(mesh, vec);
Expand Down Expand Up @@ -517,7 +518,7 @@ NB_MODULE(manifold3d, m) {
.def_ro("run_original_id", &MeshGL::runOriginalID)
.def_ro("face_id", &MeshGL::faceID)
.def_static(
"level_set",
"level_set",
[](const std::function<float(float, float, float)> &f,
std::vector<float> bounds, float edgeLength, float level = 0.0) {
// Same format as Manifold.bounding_box
Expand Down
26 changes: 13 additions & 13 deletions extras/minimize_testcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ inline bool intersect(glm::vec2 p0, glm::vec2 p1, glm::vec2 q0, glm::vec2 q1,
// check if removing point j in polygon i will introduce self-intersection
// this checks if the new edge j-1 <-> j+1 intersects with any other edges,
// assuming the original polygon does not contain self-intersection
bool safeToRemove(const Polygons &polys, int i, int j, float precision) {
bool safeToRemove(const Polygons &polys, size_t i, size_t j, float precision) {
if (polys[i].size() == 3) return false;
glm::vec2 prev = polys[i][j == 0 ? polys[i].size() - 1 : (j - 1)];
glm::vec2 next = polys[i][j == (polys[i].size() - 1) ? 0 : (j + 1)];
for (int k = 0; k < polys.size(); k++) {
for (size_t k = 0; k < polys.size(); k++) {
auto ll = [&](size_t l) {
return l == (polys[k].size() - 1) ? 0 : (l + 1);
};
Expand All @@ -74,7 +74,7 @@ bool safeToRemove(const Polygons &polys, int i, int j, float precision) {
#if MANIFOLD_PAR == 'T' && __has_include(<pstl/glue_execution_defs.h>)
std::execution::par,
#endif
countAt((size_t)0), countAt(polys[k].size()), [=](size_t l) {
countAt(0_z), countAt(polys[k].size()), [=](size_t l) {
if (i == k && (l == j || ll(l) == j)) return true;
return !intersect(prev, next, polysk[l], polysk[ll(l)],
precision);
Expand All @@ -84,8 +84,8 @@ bool safeToRemove(const Polygons &polys, int i, int j, float precision) {
return true;
}

std::pair<int, int> findIndex(const Polygons &polys, int i) {
int outer = 0;
std::pair<int, int> findIndex(const Polygons &polys, size_t i) {
size_t outer = 0;
while (i >= polys[outer].size()) i -= polys[outer++].size();
return std::make_pair(outer, i);
}
Expand Down Expand Up @@ -139,9 +139,9 @@ bool rayHit(glm::vec2 point, glm::vec2 q0, glm::vec2 q1) {
// this enumerates over the first point in all other polygons,
// and check if they are inside the current polygon
// this algorithm assumes that polygons are non-intersecting
std::vector<int> getChildren(const Polygons &polys, int i) {
std::vector<int> getChildren(const Polygons &polys, size_t i) {
std::vector<int> results;
for (int j = 0; j < polys.size(); j++) {
for (size_t j = 0; j < polys.size(); j++) {
if (i == j) continue;
glm::vec2 point = polys[j][0];
auto k1 = [&](size_t k) {
Expand Down Expand Up @@ -173,7 +173,7 @@ void simplify(Polygons &polys, float precision = -1) {

removedSomething = false;
// try to remove simple polygons
for (int i = 0; i < polys.size(); i++) {
for (size_t i = 0; i < polys.size(); i++) {
std::vector<int> children = getChildren(polys, i);
// if there are children, we can't remove it or we will mess up with
// winding direction...
Expand All @@ -195,18 +195,18 @@ void simplify(Polygons &polys, float precision = -1) {
}
}

for (int i = 0; i < polys.size(); i++) {
for (size_t i = 0; i < polys.size(); i++) {
std::vector<int> children = getChildren(polys, i);
for (int j = 0; j < polys[i].size(); j++) {
for (size_t j = 0; j < polys[i].size(); j++) {
// removed vertex cannot change inclusion relation
// we just check if the vertex
// x: intersects with j0, j (original edge 1)
// y: intersects with j, j1 (original edge 2)
// z: intersects with j0, j1 (new edge)
// if (x ^ y ^ z) is true, it means that the count % 2 is changed,
// and we changed inclusion relation, so vertex j cannot be removed
int j0 = j == 0 ? polys[i].size() - 1 : j - 1;
int j1 = j == polys[i].size() - 1 ? 0 : j + 1;
size_t j0 = j == 0 ? polys[i].size() - 1 : j - 1;
size_t j1 = j == polys[i].size() - 1 ? 0 : j + 1;
if (std::any_of(children.begin(), children.end(), [&](int k) {
return rayHit(polys[k][0], polys[i][j0], polys[i][j]) ^
rayHit(polys[k][0], polys[i][j], polys[i][j1]) ^
Expand Down Expand Up @@ -318,7 +318,7 @@ int main(int argc, char **argv) {
SimplePolygon poly;
// search for precision first
while (std::getline(fin, line)) {
int index = line.find("Precision = ");
size_t index = line.find("Precision = ");
if (index != std::string::npos) {
std::istringstream iss(line.substr(index + 12));
if (!(iss >> precision)) {
Expand Down
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
{ parallel-backend = "none"; }
{
parallel-backend = "tbb";
build-tools = with pkgs; [ tbb_2021_8 pkg-config ];
build-tools = with pkgs; [ tbb pkg-config ];
pca006132 marked this conversation as resolved.
Show resolved Hide resolved
}
];
in
Expand Down Expand Up @@ -126,7 +126,7 @@
numpy
];
buildInputs = with pkgs; [
tbb_2021_8
tbb
glm
clipper2
];
Expand Down Expand Up @@ -156,7 +156,7 @@
devShell = pkgs.mkShell {
buildInputs = with pkgs; [
cmake
tbb_2021_8
tbb
gtest
];
};
Expand Down
14 changes: 7 additions & 7 deletions meshIO/src/meshIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,14 @@ Mesh ImportMesh(const std::string& filename, bool forceCleanup) {
ASSERT(scene, userErr, importer.GetErrorString());

Mesh mesh_out;
for (int i = 0; i < scene->mNumMeshes; ++i) {
for (size_t i = 0; i < scene->mNumMeshes; ++i) {
const aiMesh* mesh_i = scene->mMeshes[i];
for (int j = 0; j < mesh_i->mNumVertices; ++j) {
for (size_t j = 0; j < mesh_i->mNumVertices; ++j) {
const aiVector3D vert = mesh_i->mVertices[j];
mesh_out.vertPos.push_back(isYup ? glm::vec3(vert.z, vert.x, vert.y)
: glm::vec3(vert.x, vert.y, vert.z));
}
for (int j = 0; j < mesh_i->mNumFaces; ++j) {
for (size_t j = 0; j < mesh_i->mNumFaces; ++j) {
const aiFace face = mesh_i->mFaces[j];
ASSERT(face.mNumIndices == 3, userErr,
"Non-triangular face in " + filename);
Expand Down Expand Up @@ -214,7 +214,7 @@ void ExportMesh(const std::string& filename, const MeshGL& mesh,
ASSERT(validChannels, userErr, "Invalid colorChannels.");
if (hasColor) mesh_out->mColors[0] = new aiColor4D[mesh_out->mNumVertices];

for (int i = 0; i < mesh_out->mNumVertices; ++i) {
for (size_t i = 0; i < mesh_out->mNumVertices; ++i) {
glm::vec3 v;
for (int j : {0, 1, 2}) v[j] = mesh.vertProperties[i * mesh.numProp + j];
mesh_out->mVertices[i] =
Expand Down Expand Up @@ -242,7 +242,7 @@ void ExportMesh(const std::string& filename, const MeshGL& mesh,
mesh_out->mNumFaces = mesh.NumTri();
mesh_out->mFaces = new aiFace[mesh_out->mNumFaces];

for (int i = 0; i < mesh_out->mNumFaces; ++i) {
for (size_t i = 0; i < mesh_out->mNumFaces; ++i) {
aiFace& face = mesh_out->mFaces[i];
face.mNumIndices = 3;
face.mIndices = new glm::uint[face.mNumIndices];
Expand Down Expand Up @@ -295,7 +295,7 @@ void ExportMesh(const std::string& filename, const Mesh& mesh,
mesh_out->mColors[0] = new aiColor4D[mesh_out->mNumVertices];
}

for (int i = 0; i < mesh_out->mNumVertices; ++i) {
for (size_t i = 0; i < mesh_out->mNumVertices; ++i) {
const glm::vec3& v = mesh.vertPos[i];
mesh_out->mVertices[i] =
isYup ? aiVector3D(v.y, v.z, v.x) : aiVector3D(v.x, v.y, v.z);
Expand All @@ -313,7 +313,7 @@ void ExportMesh(const std::string& filename, const Mesh& mesh,
mesh_out->mNumFaces = mesh.triVerts.size();
mesh_out->mFaces = new aiFace[mesh_out->mNumFaces];

for (int i = 0; i < mesh_out->mNumFaces; ++i) {
for (size_t i = 0; i < mesh_out->mNumFaces; ++i) {
aiFace& face = mesh_out->mFaces[i];
face.mNumIndices = 3;
face.mIndices = new glm::uint[face.mNumIndices];
Expand Down
4 changes: 2 additions & 2 deletions src/collider/include/collider.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class Collider {
// even nodes are leaves, odd nodes are internal, root is 1
Vec<thrust::pair<int, int>> internalChildren_;

int NumInternal() const { return internalChildren_.size(); };
int NumLeaves() const {
size_t NumInternal() const { return internalChildren_.size(); };
size_t NumLeaves() const {
return internalChildren_.empty() ? 0 : (NumInternal() + 1);
};
};
Expand Down
2 changes: 1 addition & 1 deletion src/collider/src/collider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ struct CreateRadixTree {
}

int PrefixLength(int i, int j) const {
if (j < 0 || j >= leafMorton_.size()) {
if (j < 0 || j >= static_cast<int>(leafMorton_.size())) {
return -1;
} else {
int out;
Expand Down
Loading
Loading