mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-10-13 19:01:21 +00:00
* Add Missing Includes Across src/libslic3r Every libslic3r source and header now directly includes the headers declaring what it uses, rather than relying on the precompiled header or transitive includes. Generated with clang-tidy misc-include-cleaner, with libslic3r headers spelled libslic3r/... so they resolve outside the library's private include paths. MultiMaterialSegmentation.hpp, Support/SupportParameters.hpp and Format/STEP.hpp are made self-contained by hand. * Make the libslic3r Headers Compile on Their Own Each now includes, or forward-declares, what it uses instead of relying on what its includers happened to include first. Left out: I18N.hpp, which errors on purpose when included from GUI code, and VoxelizeCSGMesh.hpp and SLA/bicubic.h, which nothing includes and which no longer compile at all. * Add the Includes Missing From the Hand-Fixed libslic3r Headers clang-tidy would not edit these headers while they failed to compile on their own, so the first pass skipped them. With the headers now self-contained, a second pass adds the rest. * Keep Windows Setup Ahead of the Added libslic3r Includes Print.cpp and Thread.cpp open with a _WIN32 block that has to come first; without the precompiled header, Print.cpp otherwise reaches windows.h through OCCT with NONLS defined and boost/regex fails. OpenVDBUtils.cpp and SLA/SupportTreeBuilder.cpp had includes inside #ifndef NOMINMAX, which libslic3r defines on Windows, so those were skipped there. .clang-tidy also ignores the MSVC STL and UCRT internals, Boost.Multiprecision's fwd.hpp and CPython's Windows include directory. * Re-Add libslic3r Includes After the Clipper2 2.0.1 Migration Rebasing onto main took main's version of the files the Clipper2 migration rewrote, so their added includes are restored here, along with includes for main's new code. Clipper2's individual headers are now ignored by clang-tidy: they only build the Z variant through clipper2_z.hpp, which defines USINGZ first, so including clipper.core.h and the like directly broke ClipperZUtils.cpp.
74 lines
3.2 KiB
C++
74 lines
3.2 KiB
C++
#ifndef slic3r_Geometry_ArcWelder_hpp_
|
|
#define slic3r_Geometry_ArcWelder_hpp_
|
|
|
|
#include <Eigen/Core>
|
|
#include <assert.h>
|
|
#include <math.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include <Eigen/Geometry>
|
|
#include <type_traits>
|
|
#include <cassert>
|
|
|
|
#include "libslic3r/libslic3r.h"
|
|
|
|
namespace Slic3r { namespace Geometry { namespace ArcWelder {
|
|
|
|
// Calculate center point (center of a circle) of an arc given two points and a radius.
|
|
// positive radius: take shorter arc
|
|
// negative radius: take longer arc
|
|
// radius must NOT be zero!
|
|
template<typename Derived, typename Derived2, typename Float>
|
|
inline Eigen::Matrix<Float, 2, 1, Eigen::DontAlign> arc_center(
|
|
const Eigen::MatrixBase<Derived> &start_pos,
|
|
const Eigen::MatrixBase<Derived2> &end_pos,
|
|
const Float radius,
|
|
const bool is_ccw)
|
|
{
|
|
static_assert(Derived::IsVectorAtCompileTime && int(Derived::SizeAtCompileTime) == 2, "arc_center(): first parameter is not a 2D vector");
|
|
static_assert(Derived2::IsVectorAtCompileTime && int(Derived2::SizeAtCompileTime) == 2, "arc_center(): second parameter is not a 2D vector");
|
|
static_assert(std::is_same<typename Derived::Scalar, typename Derived2::Scalar>::value, "arc_center(): Both vectors must be of the same type.");
|
|
static_assert(std::is_same<typename Derived::Scalar, Float>::value, "arc_center(): Radius must be of the same type as the vectors.");
|
|
assert(radius != 0);
|
|
using Vector = Eigen::Matrix<Float, 2, 1, Eigen::DontAlign>;
|
|
auto v = end_pos - start_pos;
|
|
Float q2 = v.squaredNorm();
|
|
assert(q2 > 0);
|
|
Float t2 = sqr(radius) / q2 - Float(.25f);
|
|
// If the start_pos and end_pos are nearly antipodal, t2 may become slightly negative.
|
|
// In that case return a centroid of start_point & end_point.
|
|
Float t = t2 > 0 ? sqrt(t2) : Float(0);
|
|
auto mid = Float(0.5) * (start_pos + end_pos);
|
|
Vector vp{ -v.y() * t, v.x() * t };
|
|
return (radius > Float(0)) == is_ccw ? (mid + vp).eval() : (mid - vp).eval();
|
|
}
|
|
|
|
|
|
// Return number of linear segments necessary to interpolate arc of a given positive radius and positive angle to satisfy
|
|
// maximum deviation of an interpolating polyline from an analytic arc.
|
|
template<typename FloatType>
|
|
size_t arc_discretization_steps(const FloatType radius, const FloatType angle, const FloatType deviation)
|
|
{
|
|
assert(radius > 0);
|
|
assert(angle > 0);
|
|
assert(angle <= FloatType(2. * M_PI));
|
|
assert(deviation > 0);
|
|
|
|
FloatType d = radius - deviation;
|
|
return d < EPSILON ?
|
|
// Radius smaller than deviation.
|
|
( // Acute angle: a single segment interpolates the arc with sufficient accuracy.
|
|
angle < M_PI ||
|
|
// Obtuse angle: Test whether the furthest point (center) of an arc is closer than deviation to the center of a line segment.
|
|
radius * (FloatType(1.) + cos(M_PI - FloatType(.5) * angle)) < deviation ?
|
|
// Single segment is sufficient
|
|
1 :
|
|
// Two segments are necessary, the middle point is at the center of the arc.
|
|
2) :
|
|
size_t(ceil(angle / (2. * acos(d / radius))));
|
|
}
|
|
|
|
} } } // namespace Slic3r::Geometry::ArcWelder
|
|
|
|
#endif // slic3r_Geometry_ArcWelder_hpp_
|