15 #ifndef ALLIUM_MESH_POINT_HPP
16 #define ALLIUM_MESH_POINT_HPP
18 #include <allium/util/assert.hpp>
19 #include <allium/la/vector_trait.hpp>
30 template <
typename N,
int D>
35 Point(
const std::initializer_list<N> &entries) {
36 allium_assert(entries.size() == D,
"Correct initializer length.");
39 for (
auto e : entries) {
45 static Point full(N initial_value) {
47 std::fill(p.m_entries.begin(), p.m_entries.end(), initial_value);
51 size_t rows() {
return D; }
53 N& operator[] (
int i) {
57 const N& operator[] (
int i)
const {
61 bool operator== (
const Point& rhs)
const {
62 for (
int i = 0; i < D; ++i) {
63 if (m_entries[i] != rhs[i]) {
71 for (
int i = 0; i < D; ++i) {
72 m_entries[i] += rhs[i];
77 Point operator*= (N factor) {
78 for (
int i = 0; i < D; ++i) {
79 m_entries[i] *= factor;
86 for (
int i = 0; i < D; ++i) {
87 result[i] = (*this)[i];
93 template <
typename Pred>
94 bool all_of(Pred pred) {
95 return std::all_of(m_entries.begin(), m_entries.end(), pred);
99 return std::accumulate(m_entries.begin(), m_entries.end(),
101 [](N a, N b) {
return a*b; });
105 std::array<N, D> m_entries;
108 template <
typename N,
int D>
109 std::ostream& operator<< (std::ostream& os,
const Point<N, D>& p) {
112 for (
int i = 0; i < D; ++i) {
A point in D dimensions.
Definition: point.hpp:31
Generates common vector operations automatically.
Definition: vector_trait.hpp:31