Skip to content

Commit

Permalink
Rename operator""_z to _uz per P0330R8, and move into namespace manif…
Browse files Browse the repository at this point in the history
…old (#869)

Rename operator""_z to _uz per P0330R8, and move into namespace manifold.
  • Loading branch information
BenFrantzDale authored Jul 18, 2024
1 parent 0617d34 commit ccb682f
Show file tree
Hide file tree
Showing 13 changed files with 54 additions and 47 deletions.
2 changes: 1 addition & 1 deletion extras/minimize_testcase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ bool safeToRemove(const Polygons &polys, size_t i, size_t j, float precision) {
#if MANIFOLD_PAR == 'T' && __has_include(<pstl/glue_execution_defs.h>)
std::execution::par,
#endif
countAt(0_z), countAt(polys[k].size()), [=](size_t l) {
countAt(0_uz), 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 Down
12 changes: 6 additions & 6 deletions src/manifold/src/boolean3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ SparseIndices Filter11(const Manifold::Impl &inP, const Manifold::Impl &inQ,
const SparseIndices &p1q2, const SparseIndices &p2q1) {
ZoneScoped;
SparseIndices p1q1(3 * p1q2.size() + 3 * p2q1.size());
for_each_n(autoPolicy(p1q2.size(), 1e5), countAt(0_z), p1q2.size(),
CopyFaceEdges<false>({p1q2, p1q1, inQ.halfedge_, 0_z}));
for_each_n(autoPolicy(p2q1.size(), 1e5), countAt(0_z), p2q1.size(),
for_each_n(autoPolicy(p1q2.size(), 1e5), countAt(0_uz), p1q2.size(),
CopyFaceEdges<false>({p1q2, p1q1, inQ.halfedge_, 0_uz}));
for_each_n(autoPolicy(p2q1.size(), 1e5), countAt(0_uz), p2q1.size(),
CopyFaceEdges<true>({p2q1, p1q1, inP.halfedge_, p1q2.size()}));
p1q1.Unique();
return p1q1;
Expand Down Expand Up @@ -263,7 +263,7 @@ std::tuple<Vec<int>, Vec<glm::vec4>> Shadow11(SparseIndices &p1q1,
Vec<int> s11(p1q1.size());
Vec<glm::vec4> xyzz11(p1q1.size());

for_each_n(autoPolicy(p1q1.size(), 1e4), countAt(0_z), p1q1.size(),
for_each_n(autoPolicy(p1q1.size(), 1e4), countAt(0_uz), p1q1.size(),
Kernel11({xyzz11, s11, inP.vertPos_, inQ.vertPos_, inP.halfedge_,
inQ.halfedge_, expandP, inP.vertNormal_, p1q1}));

Expand Down Expand Up @@ -355,7 +355,7 @@ std::tuple<Vec<int>, Vec<float>> Shadow02(const Manifold::Impl &inP,
Vec<float> z02(p0q2.size());

auto vertNormalP = forward ? inP.vertNormal_ : inQ.vertNormal_;
for_each_n(autoPolicy(p0q2.size(), 1e4), countAt(0_z), p0q2.size(),
for_each_n(autoPolicy(p0q2.size(), 1e4), countAt(0_uz), p0q2.size(),
Kernel02({s02, z02, inP.vertPos_, inQ.halfedge_, inQ.vertPos_,
expandP, vertNormalP, p0q2, forward}));

Expand Down Expand Up @@ -463,7 +463,7 @@ std::tuple<Vec<int>, Vec<glm::vec3>> Intersect12(
Vec<glm::vec3> v12(p1q2.size());

for_each_n(
autoPolicy(p1q2.size(), 1e4), countAt(0_z), p1q2.size(),
autoPolicy(p1q2.size(), 1e4), countAt(0_uz), p1q2.size(),
Kernel12({x12, v12, p0q2.AsVec64(), s02, z02, p1q1.AsVec64(), s11, xyzz11,
inP.halfedge_, inQ.halfedge_, inP.vertPos_, forward, p1q2}));

Expand Down
6 changes: 3 additions & 3 deletions src/manifold/src/boolean_result.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ std::tuple<Vec<int>, Vec<int>> SizeOutput(
outR.faceNormal_.resize(numFaceR);

Vec<size_t> tmpBuffer(outR.faceNormal_.size());
auto faceIds = TransformIterator(countAt(0_z), [&sidesPerFacePQ](size_t i) {
auto faceIds = TransformIterator(countAt(0_uz), [&sidesPerFacePQ](size_t i) {
if (sidesPerFacePQ[i] > 0) return i;
return std::numeric_limits<size_t>::max();
});
Expand All @@ -168,7 +168,7 @@ std::tuple<Vec<int>, Vec<int>> SizeOutput(
outR.faceNormal_.begin());

auto faceIdsQ =
TransformIterator(countAt(0_z), [&sidesPerFacePQ, &inP](size_t i) {
TransformIterator(countAt(0_uz), [&sidesPerFacePQ, &inP](size_t i) {
if (sidesPerFacePQ[i + inP.faceNormal_.size()] > 0) return i;
return std::numeric_limits<size_t>::max();
});
Expand Down Expand Up @@ -255,7 +255,7 @@ void AddNewEdgeVerts(
[&](size_t hash) { mutexes[hash % mutexes.size()].unlock(); },
std::placeholders::_1);
tbb::parallel_for(
tbb::blocked_range<size_t>(0_z, p1q2.size(), 32),
tbb::blocked_range<size_t>(0_uz, p1q2.size(), 32),
[&](const tbb::blocked_range<size_t> &range) {
for (size_t i = range.begin(); i != range.end(); i++) processFun(i);
},
Expand Down
6 changes: 3 additions & 3 deletions src/manifold/src/edge_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void Manifold::Impl::SimplifyTopology() {
ZoneScopedN("CollapseShortEdge");
numFlagged = 0;
ShortEdge se{halfedge_, vertPos_, precision_};
for_each_n(policy, countAt(0_z), nbEdges,
for_each_n(policy, countAt(0_uz), nbEdges,
[&](size_t i) { bflags[i] = se(i); });
for (size_t i = 0; i < nbEdges; ++i) {
if (bflags[i]) {
Expand All @@ -211,7 +211,7 @@ void Manifold::Impl::SimplifyTopology() {
ZoneScopedN("CollapseFlaggedEdge");
numFlagged = 0;
FlagEdge se{halfedge_, meshRelation_.triRef};
for_each_n(policy, countAt(0_z), nbEdges,
for_each_n(policy, countAt(0_uz), nbEdges,
[&](size_t i) { bflags[i] = se(i); });
for (size_t i = 0; i < nbEdges; ++i) {
if (bflags[i]) {
Expand All @@ -233,7 +233,7 @@ void Manifold::Impl::SimplifyTopology() {
ZoneScopedN("RecursiveEdgeSwap");
numFlagged = 0;
SwappableEdge se{halfedge_, vertPos_, faceNormal_, precision_};
for_each_n(policy, countAt(0_z), nbEdges,
for_each_n(policy, countAt(0_uz), nbEdges,
[&](size_t i) { bflags[i] = se(i); });
std::vector<int> edgeSwapStack;
std::vector<int> visited(halfedge_.size(), -1);
Expand Down
6 changes: 3 additions & 3 deletions src/manifold/src/face_op.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void Manifold::Impl::Face2Tri(const Vec<int>& faceEdge,
triCount.back() = 0;
// precompute number of triangles per face, and launch async tasks to
// triangulate complex faces
for_each(autoPolicy(faceEdge.size(), 1e5), countAt(0_z),
for_each(autoPolicy(faceEdge.size(), 1e5), countAt(0_uz),
countAt(faceEdge.size() - 1), [&](size_t face) {
triCount[face] = faceEdge[face + 1] - faceEdge[face] - 2;
DEBUG_ASSERT(triCount[face] >= 1, topologyErr,
Expand All @@ -154,7 +154,7 @@ void Manifold::Impl::Face2Tri(const Vec<int>& faceEdge,
});
group.wait();
// prefix sum computation (assign unique index to each face) and preallocation
exclusive_scan(triCount.begin(), triCount.end(), triCount.begin(), 0_z);
exclusive_scan(triCount.begin(), triCount.end(), triCount.begin(), 0_uz);
triVerts.resize(triCount.back());
triNormal.resize(triCount.back());
triRef.resize(triCount.back());
Expand All @@ -169,7 +169,7 @@ void Manifold::Impl::Face2Tri(const Vec<int>& faceEdge,
},
std::placeholders::_1);
// set triangles in parallel
for_each(autoPolicy(faceEdge.size(), 1e4), countAt(0_z),
for_each(autoPolicy(faceEdge.size(), 1e4), countAt(0_uz),
countAt(faceEdge.size() - 1), processFace2);
#else
triVerts.reserve(faceEdge.size());
Expand Down
6 changes: 3 additions & 3 deletions src/manifold/src/impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ void Manifold::Impl::RemoveUnreferencedVerts(Vec<glm::ivec3>& triVerts) {
const Vec<glm::vec3> oldVertPos = vertPos_;

Vec<size_t> tmpBuffer(oldVertPos.size());
auto vertIdIter = TransformIterator(countAt(0_z), [&vertOld2New](size_t i) {
auto vertIdIter = TransformIterator(countAt(0_uz), [&vertOld2New](size_t i) {
if (vertOld2New[i + 1] > 0) return i;
return std::numeric_limits<size_t>::max();
});
Expand Down Expand Up @@ -846,10 +846,10 @@ SparseIndices Manifold::Impl::EdgeCollisions(const Impl& Q,
q1p2 = collider_.Collisions<false, false>(QedgeBB.cview());

if (inverted)
for_each(policy, countAt(0_z), countAt(q1p2.size()),
for_each(policy, countAt(0_uz), countAt(q1p2.size()),
ReindexEdge<true>({edges, q1p2}));
else
for_each(policy, countAt(0_z), countAt(q1p2.size()),
for_each(policy, countAt(0_uz), countAt(q1p2.size()),
ReindexEdge<false>({edges, q1p2}));
return q1p2;
}
Expand Down
14 changes: 7 additions & 7 deletions src/manifold/src/properties.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ namespace manifold {
*/
bool Manifold::Impl::IsManifold() const {
if (halfedge_.size() == 0) return true;
return all_of(countAt(0_z), countAt(halfedge_.size()),
return all_of(countAt(0_uz), countAt(halfedge_.size()),
CheckHalfedges({halfedge_, vertPos_}));
}

Expand All @@ -214,7 +214,7 @@ bool Manifold::Impl::Is2Manifold() const {
stable_sort(halfedge.begin(), halfedge.end());

return all_of(
countAt(0_z), countAt(2 * NumEdge() - 1), [halfedge](size_t edge) {
countAt(0_uz), countAt(2 * NumEdge() - 1), [halfedge](size_t edge) {
const Halfedge h = halfedge[edge];
if (h.startVert == -1 && h.endVert == -1 && h.pairedHalfedge == -1)
return true;
Expand All @@ -228,7 +228,7 @@ bool Manifold::Impl::Is2Manifold() const {
*/
bool Manifold::Impl::MatchesTriNormals() const {
if (halfedge_.size() == 0 || faceNormal_.size() != NumTri()) return true;
return all_of(countAt(0_z), countAt(NumTri()),
return all_of(countAt(0_uz), countAt(NumTri()),
CheckCCW({halfedge_, vertPos_, faceNormal_, 2 * precision_}));
}

Expand All @@ -238,7 +238,7 @@ bool Manifold::Impl::MatchesTriNormals() const {
int Manifold::Impl::NumDegenerateTris() const {
if (halfedge_.size() == 0 || faceNormal_.size() != NumTri()) return true;
return count_if(
countAt(0_z), countAt(NumTri()),
countAt(0_uz), countAt(NumTri()),
CheckCCW({halfedge_, vertPos_, faceNormal_, -1 * precision_ / 2}));
}

Expand Down Expand Up @@ -275,7 +275,7 @@ void Manifold::Impl::CalculateCurvature(int gaussianIdx, int meanIdx) {
Vec<float> vertArea(NumVert(), 0);
Vec<float> degree(NumVert(), 0);
auto policy = autoPolicy(NumTri(), 1e4);
for_each(policy, countAt(0_z), countAt(NumTri()),
for_each(policy, countAt(0_uz), countAt(NumTri()),
CurvatureAngles({vertMeanCurvature, vertGaussianCurvature, vertArea,
degree, halfedge_, vertPos_, faceNormal_}));
for_each_n(policy, countAt(0), NumVert(),
Expand All @@ -296,7 +296,7 @@ void Manifold::Impl::CalculateCurvature(int gaussianIdx, int meanIdx) {
}

for_each_n(
policy, countAt(0_z), NumTri(),
policy, countAt(0_uz), NumTri(),
UpdateProperties({meshRelation_.triProperties, meshRelation_.properties,
oldProperties, halfedge_, vertMeanCurvature,
vertGaussianCurvature, oldNumProp, numProp, gaussianIdx,
Expand Down Expand Up @@ -382,7 +382,7 @@ float Manifold::Impl::MinGap(const Manifold::Impl& other,
SparseIndices collisions = collider_.Collisions(faceBoxOther.cview());

float minDistanceSquared = transform_reduce(
countAt(0_z), countAt(collisions.size()), searchLength * searchLength,
countAt(0_uz), countAt(collisions.size()), searchLength * searchLength,
[](float a, float b) { return std::min(a, b); },
[&collisions, this, &other](int i) {
const int tri = collisions.Get(i, 1);
Expand Down
3 changes: 2 additions & 1 deletion src/polygon/src/polygon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ bool IsConvex(const PolygonsIdx &polys, float precision) {
*/
std::vector<glm::ivec3> TriangulateConvex(const PolygonsIdx &polys) {
const size_t numTri = manifold::transform_reduce(
polys.begin(), polys.end(), 0_z, [](size_t a, size_t b) { return a + b; },
polys.begin(), polys.end(), 0_uz,
[](size_t a, size_t b) { return a + b; },
[](const SimplePolygonIdx &poly) { return poly.size() - 2; });
std::vector<glm::ivec3> triangles;
triangles.reserve(numTri);
Expand Down
2 changes: 1 addition & 1 deletion src/sdf/src/sdf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ Mesh LevelSet(std::function<float(glm::vec3)> sdf, Box bounds, float edgeLength,

while (1) {
Vec<int> index(1, 0);
for_each_n(pol, countAt(0_z), maxMorton + 1,
for_each_n(pol, countAt(0_uz), maxMorton + 1,
ComputeVerts({vertPos, index, gridVerts.D(), sdf, bounds.min,
gridSize + 1, spacing, level, precision}));

Expand Down
4 changes: 2 additions & 2 deletions src/utilities/include/hashtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ template <typename V, hash_fun_t H = hash64bit>
class HashTable {
public:
HashTable(size_t size, uint32_t step = 1)
: keys_{size == 0 ? 0 : 1_z << (int)ceil(log2(size)), kOpen},
values_{size == 0 ? 0 : 1_z << (int)ceil(log2(size)), {}},
: keys_{size == 0 ? 0 : 1_uz << (int)ceil(log2(size)), kOpen},
values_{size == 0 ? 0 : 1_uz << (int)ceil(log2(size)), {}},
step_(step) {}

HashTable(const HashTable& other)
Expand Down
24 changes: 12 additions & 12 deletions src/utilities/include/par.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,13 +598,13 @@ void transform(ExecutionPolicy policy, InputIter first, InputIter last,
"You can only parallelize RandomAccessIterator.");
#if MANIFOLD_PAR == 'T'
if (policy == ExecutionPolicy::Par) {
tbb::parallel_for(tbb::blocked_range<size_t>(
0_z, static_cast<size_t>(std::distance(first, last))),
[&](const tbb::blocked_range<size_t> &range) {
std::transform(first + range.begin(),
first + range.end(),
d_first + range.begin(), f);
});
tbb::parallel_for(
tbb::blocked_range<size_t>(
0_uz, static_cast<size_t>(std::distance(first, last))),
[&](const tbb::blocked_range<size_t> &range) {
std::transform(first + range.begin(), first + range.end(),
d_first + range.begin(), f);
});
return;
}
#endif
Expand Down Expand Up @@ -643,7 +643,7 @@ void copy(ExecutionPolicy policy, InputIter first, InputIter last,
#if MANIFOLD_PAR == 'T'
if (policy == ExecutionPolicy::Par) {
tbb::parallel_for(tbb::blocked_range<size_t>(
0_z, static_cast<size_t>(std::distance(first, last)),
0_uz, static_cast<size_t>(std::distance(first, last)),
details::kSeqThreshold),
[&](const tbb::blocked_range<size_t> &range) {
std::copy(first + range.begin(), first + range.end(),
Expand Down Expand Up @@ -723,7 +723,7 @@ size_t count_if(ExecutionPolicy policy, InputIter first, InputIter last,
#if MANIFOLD_PAR == 'T'
if (policy == ExecutionPolicy::Par) {
return reduce(policy, TransformIterator(first, pred),
TransformIterator(last, pred), 0_z, std::plus<size_t>());
TransformIterator(last, pred), 0_uz, std::plus<size_t>());
}
#endif
return std::count_if(first, last, pred);
Expand Down Expand Up @@ -1048,7 +1048,7 @@ template <typename InputIterator1, typename InputIterator2,
typename OutputIterator>
void scatter(ExecutionPolicy policy, InputIterator1 first, InputIterator1 last,
InputIterator2 mapFirst, OutputIterator outputFirst) {
for_each(policy, countAt(0_z),
for_each(policy, countAt(0_uz),
countAt(static_cast<size_t>(std::distance(first, last))),
[first, mapFirst, outputFirst](size_t i) {
outputFirst[mapFirst[i]] = first[i];
Expand Down Expand Up @@ -1080,7 +1080,7 @@ template <typename InputIterator, typename RandomAccessIterator,
void gather(ExecutionPolicy policy, InputIterator mapFirst,
InputIterator mapLast, RandomAccessIterator inputFirst,
OutputIterator outputFirst) {
for_each(policy, countAt(0_z),
for_each(policy, countAt(0_uz),
countAt(static_cast<size_t>(std::distance(mapFirst, mapLast))),
[mapFirst, inputFirst, outputFirst](size_t i) {
outputFirst[i] = inputFirst[mapFirst[i]];
Expand All @@ -1104,7 +1104,7 @@ void gather(InputIterator mapFirst, InputIterator mapLast,
// Write `[0, last - first)` to the range `[first, last)`.
template <typename Iterator>
void sequence(ExecutionPolicy policy, Iterator first, Iterator last) {
for_each(policy, countAt(0_z),
for_each(policy, countAt(0_uz),
countAt(static_cast<size_t>(std::distance(first, last))),
[first](size_t i) { first[i] = i; });
}
Expand Down
10 changes: 8 additions & 2 deletions src/utilities/include/public.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,16 @@
#include <sstream>
#endif

constexpr std::size_t operator""_z(unsigned long long n) { return n; }

namespace manifold {

/**
* Stand-in for C++23's operator""uz (P0330R8)[https://wg21.link/P0330R8].
*/
[[nodiscard]] constexpr std::size_t operator""_uz(
unsigned long long n) noexcept {
return n;
}

constexpr float kTolerance = 1e-5;

/** @defgroup Connections
Expand Down
6 changes: 3 additions & 3 deletions src/utilities/include/sparse.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class SparseIndices {
size_t offset = pOffset;
if (use_q) offset = 1 - offset;
const int* p = ptr();
for_each(autoPolicy(out.size()), countAt(0_z), countAt(out.size()),
for_each(autoPolicy(out.size()), countAt(0_uz), countAt(out.size()),
[&](size_t i) { out[i] = p[i * 2 + offset]; });
return out;
}
Expand Down Expand Up @@ -139,7 +139,7 @@ class SparseIndices {
Vec<size_t> new2Old(S.size());
sequence(new2Old.begin(), new2Old.end());

size_t size = copy_if(countAt(0_z), countAt(S.size()), new2Old.begin(),
size_t size = copy_if(countAt(0_uz), countAt(S.size()), new2Old.begin(),
[&S](const size_t i) { return S[i] != 0; }) -
new2Old.begin();
new2Old.resize(size);
Expand Down Expand Up @@ -172,7 +172,7 @@ class SparseIndices {
"Different number of values than indicies!");

Vec<int> new2Old(v.size());
size_t size = copy_if(countAt(0_z), countAt(v.size()), new2Old.begin(),
size_t size = copy_if(countAt(0_uz), countAt(v.size()), new2Old.begin(),
firstFinite<T>({v})) -
new2Old.begin();
new2Old.resize(size);
Expand Down

0 comments on commit ccb682f

Please sign in to comment.