Commit ab95182c authored by Philip Trettner's avatar Philip Trettner
Browse files

made face.add(...) vertex order same as subsequent vertex iteration, added to_array method

parent 8aebd7f6
......@@ -24,7 +24,7 @@ inline face_index low_level_api_mutable::add_face(const vertex_handle *v_handles
{
m.mFaceInsertCache.resize(vcnt);
for (auto i = 0; i < vcnt; ++i)
m.mFaceInsertCache[i] = add_or_get_halfedge(v_handles[i].idx, v_handles[(i + 1) % vcnt].idx);
m.mFaceInsertCache[i] = add_or_get_halfedge(v_handles[(i + vcnt - 1) % vcnt].idx, v_handles[i].idx);
return add_face(m.mFaceInsertCache.data(), vcnt, res_idx);
}
......@@ -32,7 +32,7 @@ inline face_index low_level_api_mutable::add_face(const vertex_index *v_indices,
{
m.mFaceInsertCache.resize(vcnt);
for (auto i = 0; i < vcnt; ++i)
m.mFaceInsertCache[i] = add_or_get_halfedge(v_indices[i], v_indices[(i + 1) % vcnt]);
m.mFaceInsertCache[i] = add_or_get_halfedge(v_indices[(i + vcnt - 1) % vcnt], v_indices[i]);
return add_face(m.mFaceInsertCache.data(), vcnt, res_idx);
}
......
......@@ -313,31 +313,31 @@ auto smart_range<this_t, ElementT>::minmax(FuncT &&f) const -> polymesh::aabb<tm
}
template <class this_t, class ElementT>
std::vector<ElementT> smart_range<this_t, ElementT>::to_vector() const
template <class FuncT>
auto smart_range<this_t, ElementT>::to_vector(FuncT &&f) const -> std::vector<tmp::decayed_result_type_of<FuncT, ElementT>>
{
std::vector<ElementT> v;
std::vector<tmp::decayed_result_type_of<FuncT, ElementT>> v;
for (auto h : *static_cast<this_t const *>(this))
v.push_back(h);
v.push_back(f(h));
return v;
}
template <class this_t, class ElementT>
std::set<ElementT> smart_range<this_t, ElementT>::to_set() const
template <size_t N, class FuncT>
auto smart_range<this_t, ElementT>::to_array(FuncT &&f) const -> std::array<tmp::decayed_result_type_of<FuncT, ElementT>, N>
{
std::set<ElementT> s;
std::array<tmp::decayed_result_type_of<FuncT, ElementT>, N> a;
auto idx = 0;
for (auto h : *static_cast<this_t const *>(this))
s.insert(h);
return s;
}
{
if (idx >= N)
break;
template <class this_t, class ElementT>
template <class FuncT>
auto smart_range<this_t, ElementT>::to_vector(FuncT &&f) const -> std::vector<tmp::decayed_result_type_of<FuncT, ElementT>>
{
std::vector<tmp::decayed_result_type_of<FuncT, ElementT>> v;
for (auto h : *static_cast<this_t const *>(this))
v.push_back(f(h));
return v;
a[idx] = f(h);
++idx;
}
return a;
}
template <class this_t, class ElementT>
......@@ -706,9 +706,9 @@ template <class iterator>
face_handle face_collection<iterator>::add(vertex_handle v0, vertex_handle v1, vertex_handle v2) const
{
halfedge_index hs[3] = {
low_level_api(this->m).add_or_get_halfedge(v2.idx, v0.idx), //
low_level_api(this->m).add_or_get_halfedge(v0.idx, v1.idx), //
low_level_api(this->m).add_or_get_halfedge(v1.idx, v2.idx), //
low_level_api(this->m).add_or_get_halfedge(v2.idx, v0.idx), //
};
return this->m->handle_of(low_level_api(this->m).add_face(hs, 3));
}
......@@ -717,10 +717,10 @@ template <class iterator>
face_handle face_collection<iterator>::add(vertex_handle v0, vertex_handle v1, vertex_handle v2, vertex_handle v3) const
{
halfedge_index hs[4] = {
low_level_api(this->m).add_or_get_halfedge(v3.idx, v0.idx), //
low_level_api(this->m).add_or_get_halfedge(v0.idx, v1.idx), //
low_level_api(this->m).add_or_get_halfedge(v1.idx, v2.idx), //
low_level_api(this->m).add_or_get_halfedge(v2.idx, v3.idx), //
low_level_api(this->m).add_or_get_halfedge(v3.idx, v0.idx), //
};
return this->m->handle_of(low_level_api(this->m).add_face(hs, 4));
}
......@@ -745,7 +745,7 @@ face_handle face_collection<iterator>::add(const vertex_handle (&v_handles)[N])
{
halfedge_index hs[N];
for (auto i = 0; i < N; ++i)
hs[i] = low_level_api(this->m).add_or_get_halfedge(v_handles[i].idx, v_handles[(i + 1) % N].idx);
hs[i] = low_level_api(this->m).add_or_get_halfedge(v_handles[(i + N - 1) % N].idx, v_handles[i].idx);
return this->m->handle_of(low_level_api(this->m).add_face(hs, N));
}
......@@ -811,9 +811,9 @@ template <class iterator>
bool face_collection<iterator>::can_add(vertex_handle v0, vertex_handle v1, vertex_handle v2) const
{
halfedge_index hs[3] = {
low_level_api(this->m).can_add_or_get_halfedge(v2.idx, v0.idx), //
low_level_api(this->m).can_add_or_get_halfedge(v0.idx, v1.idx), //
low_level_api(this->m).can_add_or_get_halfedge(v1.idx, v2.idx), //
low_level_api(this->m).can_add_or_get_halfedge(v2.idx, v0.idx), //
};
return low_level_api(this->m).can_add_face(hs, 3);
}
......@@ -822,10 +822,10 @@ template <class iterator>
bool face_collection<iterator>::can_add(vertex_handle v0, vertex_handle v1, vertex_handle v2, vertex_handle v3) const
{
halfedge_index hs[4] = {
low_level_api(this->m).can_add_or_get_halfedge(v3.idx, v0.idx), //
low_level_api(this->m).can_add_or_get_halfedge(v0.idx, v1.idx), //
low_level_api(this->m).can_add_or_get_halfedge(v1.idx, v2.idx), //
low_level_api(this->m).can_add_or_get_halfedge(v2.idx, v3.idx), //
low_level_api(this->m).can_add_or_get_halfedge(v3.idx, v0.idx), //
};
return low_level_api(this->m).can_add_face(hs, 4);
}
......
......@@ -118,10 +118,6 @@ struct smart_range
template <class FuncT>
polymesh::aabb<ElementT> minmax_by(FuncT&& f) const;
/// converts this range to a vector
std::vector<ElementT> to_vector() const;
/// converts this range to a set
std::set<ElementT> to_set() const;
/// converts this range to a vector containing f(v) entries
template <class FuncT = tmp::identity>
auto to_vector(FuncT&& f = {}) const -> std::vector<tmp::decayed_result_type_of<FuncT, ElementT>>;
......@@ -131,6 +127,10 @@ struct smart_range
/// converts this range to a map containing {v, f(v)} entries
template <class FuncT = tmp::identity>
auto to_map(FuncT&& f = {}) const -> std::map<ElementT, tmp::decayed_result_type_of<FuncT, ElementT>>;
/// converts this range to a fixed size array containing f(v) entries
/// NOTE: if less elements are present, array is filled with default constructed elements
template <size_t N, class FuncT = tmp::identity>
auto to_array(FuncT&& f = {}) const -> std::array<tmp::decayed_result_type_of<FuncT, ElementT>, N>;
/// returns a new range that consists of all elements where p(x) is true
template <class PredT>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment