31 const Vector3i64 x( a - d );
32 const Vector3i64 y( b - d );
33 const Vector3i64 z( c - d );
48 [[nodiscard]] std::int64_t
degree(
int i )
const
50 constexpr std::int64_t w[3] = { 9, 3, 1 };
67template <
int N = cMaxPerturbedPo
ints,
bool Bounded = false>
69 std::int64_t * places =
nullptr )
76 assert( n > 0 && n <= N );
77 std::array<VertN, N> as;
78 for (
int i = 0; i < n; ++i )
79 as[i] = { vs[i].
id, i };
80 std::sort( as.begin(), as.begin() + n, [](
const auto & a,
const auto & b ) { return a.v < b.v; } );
86 for (
int i = 0; i < n; ++i )
88 const auto k = as[i].n;
89 if constexpr ( Bounded )
91 if ( d > std::numeric_limits<std::int64_t>::max() / radices[k] )
94 for (
int j = i; j < n; ++j )
95 res[as[j].n] = { vs[as[j].n].
pt, 0 };
99 res[k] = { vs[k].
pt, d };
102 const auto r = radices[k];
103 if ( as[i].v < as[i+1].v )
105 assert( d <= std::numeric_limits<std::int64_t>::max() / r );
112 assert( r == radices[as[i+1].n] );
118constexpr std::int64_t
cMaxPolyDAll = std::numeric_limits<std::int64_t>::max();
135template <
int N,
bool Bounded>
147 [[nodiscard]]
int numStages()
const {
return numStages_; }
150 [[nodiscard]] std::int64_t
place(
int s )
const {
return places_[s - 1]; }
159 [[nodiscard]]
bool startsAt(
int i,
int s )
const {
return points_[i].d ==
place( s ); }
163 template <
typename F>
166 for (
int s = 1; s <= numStages_ &&
place( s ) <= maxDeg; ++s )
167 if (
auto res = f( s ) )
173 std::array<PointDegree, N> points_;
174 std::array<std::int64_t, N> places_;
183template <std::
int64_t M>
187template <std::
int64_t M>
199 for (
int r = 0; r < 3; ++r )
200 for (
int col = 0; col < 3; ++col )
202 auto & e = m[r][col];
203 if (
const std::int64_t delta = std::int64_t( rows[r]->pt[col] ) - d.
pt[col] )
204 e.terms[e.numTerms++] = { 0, delta };
206 e.terms[e.numTerms++] = { rows[r]->
degree( col ), 1 };
208 e.terms[e.numTerms++] = { d.
degree( col ), -1 };
213 constexpr int perms[6][4] = { { 0, 1, 2, 1 }, { 1, 2, 0, 1 }, { 2, 0, 1, 1 }, { 0, 2, 1, -1 }, { 2, 1, 0, -1 }, { 1, 0, 2, -1 } };
214 std::vector<typename VolumePoly<M>::Term> terms;
215 terms.reserve( 6 * 26 );
216 for (
const auto & p : perms )
218 const Element & e0 = m[0][p[0]];
219 const Element & e1 = m[1][p[1]];
220 const Element & e2 = m[2][p[2]];
221 for (
int k0 = 0; k0 < e0.numTerms; ++k0 )
222 for (
int k1 = 0; k1 < e1.numTerms; ++k1 )
225 const std::int64_t c01 = p[3] * std::int64_t( e0.terms[k0].second ) * std::int64_t( e1.terms[k1].second );
226 const std::int64_t d01 = e0.terms[k0].first + e1.terms[k1].first;
227 const int last2 = d.
d && k0 + 1 == e0.numTerms && k1 + 1 == e1.numTerms ? e2.numTerms - 1 : e2.numTerms;
228 for (
int k2 = 0; k2 < last2; ++k2 )
229 if (
const auto deg = d01 + e2.terms[k2].first; deg <=
M )
#define MR_FORCE_INLINE
Definition MRMacros.h:47
Definition MRInt64Mul128.h:22
Definition MRSparsePolynomial.h:75
segmentIntersectionTriPlaneOrder: it reaches the polynomial path with all three largest ids in the pl...
Definition MRPrecisePredicates3Poly.h:137
const PointDegree & operator[](int i) const
point i with its degree, as perturbed at the last stage (if Bounded, with the degree 0 if no stage pe...
Definition MRPrecisePredicates3Poly.h:153
PointDegree at(int i, int s) const
point i as perturbed at stage s
Definition MRPrecisePredicates3Poly.h:156
bool startsAt(int i, int s) const
whether point i is perturbed first at stage s
Definition MRPrecisePredicates3Poly.h:159
MR_FORCE_INLINE PerturbationStagesOf(const PreciseVertCoords *vs, const std::int64_t *radices, int n)
the stages of points vs[0..n-1] with the degrees from getPointDegrees
Definition MRPrecisePredicates3Poly.h:140
auto firstStage(F &&f, std::int64_t maxDeg=cMaxPolyDAll) const -> std::invoke_result_t< F &, int >
Definition MRPrecisePredicates3Poly.h:164
std::int64_t place(int s) const
the degree of the points perturbed first at stage s: every term with them has at least this degree,...
Definition MRPrecisePredicates3Poly.h:150
int numStages() const
the number of stages, which is the number of different ids (if Bounded, of those before the first one...
Definition MRPrecisePredicates3Poly.h:147
Vector3i pt
integer coordinates of the vertex
Definition MRPrecisePredicates3.h:40
std::pair< std::int64_t, FastInt128 > Term
Definition MRSparsePolynomial.h:79
static SparsePolynomial fromUnsortedTerms(std::vector< Term > &&terms)
VertId id
unique id of the vertex (in both meshes)
Definition MRPrecisePredicates3.h:39
for internal use: namespace detail is not bound to other languages
Definition MRFastInt.h:19
VolumePoly< M > orient3dPoly(const PointDegree &a, const PointDegree &b, const PointDegree &c, const PointDegree &d)
the volume of tetrahedron abcd (see orient3dVolume) of the perturbed points as a polynomial of eps,...
Definition MRPrecisePredicates3Poly.h:188
SparsePolynomial< FastInt128, std::int64_t, M > VolumePoly
Definition MRPrecisePredicates3Poly.h:184
constexpr int cMaxPerturbedPoints
the largest number of points of one predicate that getPointDegrees and PerturbationStages take by def...
Definition MRPrecisePredicates3Poly.h:56
PerturbationStagesOf< cMaxPerturbedPoints, false > PerturbationStages
the stages of at most cMaxPerturbedPoints points, whose degrees the caller makes fit in int64
Definition MRPrecisePredicates3Poly.h:179
MR_FORCE_INLINE int getPointDegrees(const PreciseVertCoords *vs, const std::int64_t *radices, int n, PointDegree *res, std::int64_t *places=nullptr)
Definition MRPrecisePredicates3Poly.h:68
MR_FORCE_INLINE FastInt128 orient3dVolume(const Vector3i &a, const Vector3i &b, const Vector3i &c, const Vector3i &d)
Definition MRPrecisePredicates3Poly.h:29
constexpr std::int64_t cMaxPolyDAll
the largest degree that no term exceeds: a polynomial with it keeps all its terms
Definition MRPrecisePredicates3Poly.h:118
constexpr std::int64_t cMaxPolyDTriTri
Definition MRPrecisePredicates3Poly.h:125
constexpr std::int64_t cMaxPolyDTriPlane
segmentIntersectionOrder
Definition MRPrecisePredicates3Poly.h:126
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8
__int128_t FastInt128
Definition MRFastInt128.h:22
Definition MRPrecisePredicates3.h:38
a point with the degree of its perturbation: its coordinates z, y, x get eps^d, eps^(3*d),...
Definition MRPrecisePredicates3Poly.h:43
Vector3i pt
Definition MRPrecisePredicates3Poly.h:44
std::int64_t degree(int i) const
the degree of epsilon for coordinate i
Definition MRPrecisePredicates3Poly.h:48
std::int64_t d
degree of epsilon for pt.z; 0 leaves the point unperturbed
Definition MRPrecisePredicates3Poly.h:45