1#ifndef BITSIM_GEOMETRY_GEOM_POINT_H
2#define BITSIM_GEOMETRY_GEOM_POINT_H
21template <
int spacedim,
typename T = real_t>
class GeomPoint
43 template <
typename Container>
explicit GeomPoint(
const Container &data);
87 void scale(
const std::vector<T> &factors);
150 std::array<T, spacedim> data_;
155 std::for_each(data_.begin(), data_.end(), [=](T &item) { item = val; });
158template <
int spacedim,
typename T>
159template <
typename Container>
162 for (
uint_t i = 0; i < data_.size(); ++i)
168template <
int spacedim,
typename T>
171 if (list.size() != spacedim)
174 msg +=
"Invalid initialization ";
175 msg +=
" list size for point construction. " + std::to_string(list.size());
176 msg +=
" not equal to " + std::to_string(spacedim);
177 throw std::logic_error(msg);
180 auto start = list.begin();
181 auto end = list.end();
184 for (; start != end; ++start)
190template <
int spacedim,
typename T>
195template <
int spacedim,
typename T>
217template <
int spacedim,
typename T>
221 for (
int i = 0; i < spacedim; ++i)
223 data_[i] += t.data_[i];
228template <
int spacedim,
typename T>
232 for (
int i = 0; i < spacedim; ++i)
234 data_[i] -= t.data_[i];
239template <
int spacedim,
typename T>
243 for (
int i = 0; i < spacedim; ++i)
251template <
int spacedim,
typename T>
255 (*this) *= (
static_cast<T
>(1) / factor);
259template <
int spacedim,
typename T>
264 if (list.size() != spacedim)
267 msg +=
"Invalid initialization ";
268 msg +=
" list size for point construction. " + std::to_string(list.size());
269 msg +=
" not equal to " + std::to_string(spacedim);
270 throw std::logic_error(msg);
273 auto start = list.begin();
274 auto end = list.end();
277 for (; start != end; ++start)
285template <
int spacedim,
typename T>
289 for (
int i = 0; i < spacedim; ++i)
291 data_[i] += p.data_[i] * factor;
298 T max_val = data_[0];
299 for (
int i = 1; i < spacedim; ++i)
301 max_val = std::max(max_val, data_[i]);
310 T min_val = data_[0];
312 for (
int i = 1; i < spacedim; ++i)
314 min_val = std::min(min_val, data_[i]);
320template <
int spacedim,
typename T>
328 for (
int i = 0; i < spacedim; ++i)
329 sum += (data_[i] - data[i]) * (data_[i] - data[i]);
331 return std::sqrt(sum);
334template <
int spacedim,
typename T>
337 for (
int i = 0; i < spacedim; ++i)
339 data_[i] *= factors[i];
347 std::for_each(data_.begin(), data_.end(), [&](
const T &value) { result += value * value; });
352template <
int spacedim,
typename T>
356 T result = (*this)[0] * other[0];
358 for (
uint_t i = 1; i < spacedim; ++i)
360 result += (*this)[i] * other[i];
368 for (
int i = 0; i < spacedim; ++i)
372template <
int spacedim,
typename T>
378 for (
int i = 0; i < spacedim; ++i)
382 if (i < spacedim - 1)
395 std::string rslt(
"");
396 auto end = data_.begin();
397 std::advance(end, spacedim - 1);
398 std::for_each(data_.begin(), end,
401 rslt += std::to_string(value);
405 rslt += std::to_string(data_[spacedim - 1]);
412template <
int spacedim,
typename T>
420template <
int spacedim,
typename T>
427template <
int spacedim,
typename T>
431 auto data = t.data();
433 for (
int i = 0; i < spacedim; ++i)
434 data[i] *= factors[i];
441template <
int spacedim,
typename T>
446 for (
int i = 0; i < spacedim; ++i)
447 data[i] = std::abs(data[i]);
453template <
int spacedim,
typename T>
460template <
int spacedim,
typename T>
467template <
int spacedim,
typename T>
474template <
int spacedim,
typename T>
482template <
int spacedim,
typename T>
489template <
int spacedim,
typename T>
494 for (
int i = 0; i < spacedim; ++i)
506template <
int spacedim,
typename T>
The basic types of bitsim. Code outside this file names Eigen's matrix and vector types only through ...
GeomPoint(T val=T())
ctor all dim data are assigned the given value
Definition geom_point.h:153
A class that describes a point with spacedim spatial dimension space.
Definition geom_point.h:22
std::ostream & print_point_info(std::ostream &out) const
print the point
Definition geom_point.h:373
T square_sum() const
Returns the square sum of the compontents.
Definition geom_point.h:343
GeomPoint & operator+=(const GeomPoint &)
Add another vector, i.e. move this point by the given offset.
Definition geom_point.h:218
void add_scaled(const GeomPoint &p, T factor)
Add the coordinates of the given point to this scaled by factor.
Definition geom_point.h:286
T entry(uint_t i) const
access the i-th coordinate of the point read-only
Definition geom_point.h:104
T max() const
Get the max element in the point.
Definition geom_point.h:295
T L2_norm() const
Return the distance from the origin.
Definition geom_point.h:125
real_t value_type
Definition geom_point.h:28
GeomPoint(const GeomPoint &t)
copy ctor
Definition geom_point.h:191
GeomPoint & operator-=(const GeomPoint &)
Definition geom_point.h:229
T distance(const GeomPoint &) const
Get the distance from the given point.
Definition geom_point.h:321
GeomPoint & operator=(const std::initializer_list< T > &list)
operator = Assign from the initializer list
Definition geom_point.h:261
T dot(const GeomPoint &other) const
Returns the dot product of this point and the given point.
Definition geom_point.h:353
GeomPoint(const std::initializer_list< T > &list)
Construct given an initializer_list.
Definition geom_point.h:169
GeomPoint & operator/=(T factor)
Scale the vector by factor.
Definition geom_point.h:252
T operator[](uint_t i) const
Access the i-th coordinate of the point read-only.
Definition geom_point.h:212
void zero()
Zero the entries of the tensor.
Definition geom_point.h:366
void scale(T factor)
scale with a given factor
auto coordinates() const
Get a copy of the data of this object.
Definition geom_point.h:107
const std::string to_string() const
Returns string representation of the point.
Definition geom_point.h:392
GeomPoint(T val=T())
ctor all dim data are assigned the given value
Definition geom_point.h:153
GeomPoint & operator=(const GeomPoint &t)
copy assignement operator
Definition geom_point.h:196
GeomPoint & operator*=(T factor)
Scale the point by factor.
Definition geom_point.h:240
static const int dimension
Definition geom_point.h:33
void scale(const std::vector< T > &factors)
scale this object by the given factors p factors should have size at least spacedim
Definition geom_point.h:335
virtual ~GeomPoint()
dtor
Definition geom_point.h:57
T & operator[](uint_t i)
Access the i-th coordinate of the point.
Definition geom_point.h:207
GeomPoint(const Container &data)
Create by passing a vector of data.
Definition geom_point.h:160
T min() const
Get the min element in the point.
Definition geom_point.h:307
Definition generic_line.h:16
const GeomPoint< spacedim, T > scale(const GeomPoint< spacedim, T > &t, T factor)
scale the given point by facto and returns a copyr. This function does not change the entries of t.
Definition geom_point.h:421
std::ostream & operator<<(std::ostream &out, const GeomPoint< spacedim, T > &p)
free functions that work on the GeomPoint<spacedim,T> class
Definition geom_point.h:413
const GeomPoint< spacedim, T > operator/(const GeomPoint< spacedim, T > &t, T factor)
Definition geom_point.h:468
bool operator==(const GeomPoint< spacedim, T > &t1, const GeomPoint< spacedim, T > &t2)
Definition geom_point.h:490
const GeomPoint< spacedim, T > operator*(T factor, const GeomPoint< spacedim, T > &t)
Allow multiplication from left with a factor.
Definition geom_point.h:454
const GeomPoint< spacedim, T > abs(const GeomPoint< spacedim, T > &t)
Return a point having the absolute values of the given point object.
Definition geom_point.h:442
bool operator!=(const GeomPoint< spacedim, T > &t1, const GeomPoint< spacedim, T > &t2)
Definition geom_point.h:507
const GeomPoint< spacedim, T > operator-(const GeomPoint< spacedim, T > &t1, const GeomPoint< spacedim, T > &t2)
Definition geom_point.h:483
const GeomPoint< spacedim, T > operator+(const GeomPoint< spacedim, T > &t1, const GeomPoint< spacedim, T > &t2)
Definition geom_point.h:475
Definition dc_motor_backend_base.h:9
std::size_t uint_t
uint_t
Definition bitsim_types.h:40