Skip to content

Commit

Permalink
Update to Clipper2 (openscad#5501)
Browse files Browse the repository at this point in the history
* Add Clipper2 as submodule, update manifold
* Port to Clipper2
  • Loading branch information
kintel authored Dec 20, 2024
1 parent f9274c2 commit 86e5429
Show file tree
Hide file tree
Showing 25 changed files with 312 additions and 5,355 deletions.
5 changes: 4 additions & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
url = https://github.com/microsoft/mimalloc.git
[submodule "submodules/manifold"]
path = submodules/manifold
url = https://github.com/elalish/manifold
url = https://github.com/elalish/manifold.git
[submodule "sanitizers-cmake"]
path = submodules/sanitizers-cmake
url = https://github.com/arsenm/sanitizers-cmake.git
[submodule "OpenCSG"]
path = submodules/OpenCSG
url = https://github.com/openscad/OpenCSG.git
[submodule "Clipper2"]
path = submodules/Clipper2
url = https://github.com/AngusJohnson/Clipper2.git
20 changes: 14 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ option(ENABLE_TESTS "Run testsuite after building." ON)
option(EXPERIMENTAL "Enable Experimental Features" OFF)
option(USE_MANIFOLD_TRIANGULATOR "Use Manifold's triangulator instead of CGAL's" ON)
option(USE_BUILTIN_MANIFOLD "Use manifold from submodule" ON)
option(USE_BUILTIN_CLIPPER2 "Use Clipper2 from submodule" ON)
option(USE_LEGACY_RENDERERS "Use legacy (non-VBO) OpenGL renderers" OFF)
option(SNAPSHOT "Create dev snapshot, uses nightly icons" OFF)
option(HEADLESS "Build without GUI frontend" OFF)
Expand Down Expand Up @@ -846,7 +847,6 @@ set(CORE_SOURCES
src/ext/libtess2/Source/sweep.c
src/ext/libtess2/Source/tess.c
src/ext/lodepng/lodepng.cpp
src/ext/polyclipping/clipper.cpp
src/geometry/ClipperUtils.cc
src/geometry/Geometry.cc
src/geometry/GeometryCache.cc
Expand Down Expand Up @@ -968,6 +968,19 @@ set(MANIFOLD_CGAL_SOURCES
src/geometry/manifold/manifold-applyops-minkowski.cc
)

if(USE_BUILTIN_CLIPPER2)
set(CLIPPER2_UTILS OFF)
set(CLIPPER2_EXAMPLES OFF)
set(CLIPPER2_TESTS OFF)
add_subdirectory("submodules/Clipper2/CPP" EXCLUDE_FROM_ALL)
set(Clipper2_FOUND "YES")
message(STATUS "Clipper2 submodule")
else()
find_package(Clipper2 REQUIRED QUIET)
message(STATUS "Clipper2: ${Clipper2_VERSION}")
endif()
target_link_libraries(OpenSCAD PRIVATE Clipper2::Clipper2)

if(ENABLE_MANIFOLD)
if(NOT DEFINED MANIFOLD_PAR)
# Note: currently only Manifold-related code makes use of TBB parallelization
Expand Down Expand Up @@ -1225,11 +1238,6 @@ set(GUI_UIS
src/gui/parameter/ParameterWidget.ui
)

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
# Ignore specific warning on external lib
set_source_files_properties("src/ext/polyclipping/clipper.cpp" PROPERTIES COMPILE_FLAGS "-Wno-class-memaccess")
endif()

if (ENABLE_MANIFOLD)
target_compile_definitions(OpenSCAD PRIVATE ENABLE_MANIFOLD)
list(APPEND Sources ${MANIFOLD_SOURCES})
Expand Down
9 changes: 5 additions & 4 deletions src/core/OffsetNode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include "core/Parameters.h"
#include "core/Builtins.h"

#include <clipper2/clipper.offset.h>
#include <ios>
#include <utility>
#include <memory>
Expand All @@ -53,15 +54,15 @@ static std::shared_ptr<AbstractNode> builtin_offset(const ModuleInstantiation *i
// radius takes precedence if both r and delta are given.
node->delta = 1;
node->chamfer = false;
node->join_type = ClipperLib::jtRound;
node->join_type = Clipper2Lib::JoinType::Round;
if (parameters["r"].isDefinedAs(Value::Type::NUMBER)) {
node->delta = parameters["r"].toDouble();
} else if (parameters["delta"].isDefinedAs(Value::Type::NUMBER)) {
node->delta = parameters["delta"].toDouble();
node->join_type = ClipperLib::jtMiter;
node->join_type = Clipper2Lib::JoinType::Miter;
if (parameters["chamfer"].isDefinedAs(Value::Type::BOOL) && parameters["chamfer"].toBool()) {
node->chamfer = true;
node->join_type = ClipperLib::jtSquare;
node->join_type = Clipper2Lib::JoinType::Square;
}
}

Expand All @@ -72,7 +73,7 @@ std::string OffsetNode::toString() const
{
std::ostringstream stream;

bool isRadius = this->join_type == ClipperLib::jtRound;
bool isRadius = this->join_type == Clipper2Lib::JoinType::Round;
auto var = isRadius ? "(r = " : "(delta = ";

stream << this->name() << var << std::dec << this->delta;
Expand Down
4 changes: 2 additions & 2 deletions src/core/OffsetNode.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "core/node.h"
#include "polyclipping/clipper.hpp"
#include "clipper2/clipper.h"

#include <string>

Expand All @@ -16,5 +16,5 @@ class OffsetNode : public AbstractPolyNode
bool chamfer{false};
double fn{0}, fs{0}, fa{0}, delta{1};
double miter_limit{1000000.0}; // currently fixed high value to disable chamfers with jtMiter
ClipperLib::JoinType join_type{ClipperLib::jtRound};
Clipper2Lib::JoinType join_type{Clipper2Lib::JoinType::Round};
};
2 changes: 1 addition & 1 deletion src/core/TextNode.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ static std::shared_ptr<AbstractNode> builtin_text(const ModuleInstantiation *ins
return node;
}

std::vector<std::shared_ptr<const Polygon2d>> TextNode::createGeometryList() const
std::vector<std::shared_ptr<const Polygon2d>> TextNode::createPolygonList() const
{
FreetypeRenderer renderer;
return renderer.render(this->get_params());
Expand Down
2 changes: 1 addition & 1 deletion src/core/TextNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TextNode : public AbstractPolyNode
std::string toString() const override;
std::string name() const override { return "text"; }

std::vector<std::shared_ptr<const Polygon2d>> createGeometryList() const;
std::vector<std::shared_ptr<const Polygon2d>> createPolygonList() const;

virtual FreetypeRenderer::Params get_params() const;

Expand Down
24 changes: 0 additions & 24 deletions src/ext/polyclipping/License.txt

This file was deleted.

Loading

0 comments on commit 86e5429

Please sign in to comment.