26 #ifndef WFMATH_POINT_H
27 #define WFMATH_POINT_H
29 #include <wfmath/const.h>
39 Point<dim>& operator+=(Point<dim>& p,
const Vector<dim>& v);
41 Point<dim>& operator-=(Point<dim>& p,
const Vector<dim>& v);
44 Vector<dim> operator-(
const Point<dim>& c1,
const Point<dim>& c2);
46 Point<dim> operator+(
const Point<dim>& c,
const Vector<dim>& v);
48 Point<dim> operator+(
const Vector<dim>& v,
const Point<dim>& c);
50 Point<dim> operator-(
const Point<dim>& c,
const Vector<dim>& v);
53 CoordType SquaredDistance(
const Point<dim>& p1,
const Point<dim>& p2);
55 CoordType Distance(
const Point<dim>& p1,
const Point<dim>& p2)
56 {
return std::sqrt(SquaredDistance(p1, p2));}
58 CoordType SloppyDistance(
const Point<dim>& p1,
const Point<dim>& p2)
59 {
return (p1 - p2).sloppyMag();}
62 template<
int dim,
template<
class,
class>
class container>
63 Point<dim>
Barycenter(
const container<Point<dim>, std::allocator<Point<dim> > >& c);
71 template<
int dim,
template<
class,
class>
class container,
72 template<
class,
class>
class container2>
73 Point<dim>
Barycenter(
const container<Point<dim>, std::allocator<Point<dim> > >& c,
74 const container2<
CoordType, std::allocator<CoordType> >& weights);
78 Point<dim>
Midpoint(
const Point<dim>& p1,
const Point<dim>& p2,
82 std::ostream& operator<<(std::ostream& os,
const Point<dim>& m);
84 std::istream& operator>>(std::istream& is, Point<dim>& m);
86 template<
typename Shape>
100 Point () : m_elem{}, m_valid(false) {};
113 friend std::ostream& operator<< <dim>(std::ostream& os,
const Point& p);
114 friend std::istream&
operator>> <dim>(std::istream& is,
Point& p);
121 Point& operator= (
const Point& rhs) =
default;
124 bool operator== (
const Point& rhs)
const {
return isEqualTo(rhs);}
125 bool operator!= (
const Point& rhs)
const {
return !isEqualTo(rhs);}
127 bool isValid()
const {
return m_valid;}
129 void setValid(
bool valid =
true) {m_valid = valid;}
147 {
return (*
this = p +
Prod(*
this - p, m));}
151 size_t numCorners()
const {
return 1;}
152 Point<dim> getCorner(
size_t)
const {
return *
this;}
153 Point<dim> getCenter()
const {
return *
this;}
155 Point shift(
const Vector<dim>& v) {
return *
this += v;}
157 {
return operator=(p);}
158 Point moveCenterTo(
const Point& p) {
return operator=(p);}
160 Point& rotateCorner(
const RotMatrix<dim>&,
size_t)
162 Point& rotateCenter(
const RotMatrix<dim>&) {
return *
this;}
163 Point& rotatePoint(
const RotMatrix<dim>& m,
const Point& p) {
return rotate(m, p);}
167 Point& rotateCorner(
const Quaternion&,
size_t)
169 Point& rotateCenter(
const Quaternion&) {
return *
this;}
170 Point& rotatePoint(
const Quaternion& q,
const Point& p);
174 AxisBox<dim> boundingBox()
const;
175 Ball<dim> boundingSphere()
const;
176 Ball<dim> boundingSphereSloppy()
const;
179 const RotMatrix<dim>& rotation = RotMatrix<dim>().identity())
const
180 {
return origin + (*
this -
Point().setToOrigin()) * rotation;}
181 Point toParentCoords(
const AxisBox<dim>& coords)
const;
182 Point toParentCoords(
const RotBox<dim>& coords)
const;
189 const RotMatrix<dim>& rotation = RotMatrix<dim>().identity())
const
190 {
return Point().setToOrigin() + rotation * (*
this - origin);}
191 Point toLocalCoords(
const AxisBox<dim>& coords)
const;
192 Point toLocalCoords(
const RotBox<dim>& coords)
const;
258 const CoordType* elements()
const {
return m_elem;}
void asPolar(CoordType &r, CoordType &theta, CoordType &z) const
3D only: convert a vector to polar coordinates
CoordType x() const
access the first component of a point
Point(CoordType x, CoordType y)
2D only: construct a point from its (x, y) coordinates
CoordType & operator[](const int i)
Access the i'th coordinate of the point.
void asSpherical(CoordType &r, CoordType &theta, CoordType &phi) const
3D only: convert a vector to spherical coordinates
CoordType & x()
access the first component of a point
CoordType y() const
access the second component of a point
void setValid(bool valid=true)
make isValid() return true if you've initialized the point by hand
CoordType & z()
access the third component of a point
Point & polar(CoordType r, CoordType theta)
2D only: construct a vector from polar coordinates
static const Point< dim > & ZERO()
Provides a global instance preset to zero.
CoordType & y()
access the second component of a point
Point & polar(CoordType r, CoordType theta, CoordType z)
3D only: construct a vector from polar coordinates
Point(const Point &)=default
Construct a copy of a point.
Point & rotate(const RotMatrix< dim > &m, const Point &p)
Rotate about point p.
Point & setToOrigin()
Set point to (0,0,...,0)
Point()
Construct an uninitialized point.
void asPolar(CoordType &r, CoordType &theta) const
2D only: convert a vector to polar coordinates
Point & spherical(CoordType r, CoordType theta, CoordType phi)
3D only: construct a vector from spherical coordinates
CoordType z() const
access the third component of a point
CoordType operator[](const int i) const
Access the i'th coordinate of the point.
void fromAtlas(const AtlasInType &a)
Set the point's value to that given by an Atlas object.
AtlasOutType toAtlas() const
Create an Atlas object from the point.
Point(CoordType x, CoordType y, CoordType z)
3D only: construct a point from its (x, y, z) coordinates
A dim dimensional rotation matrix. Technically, a member of the group O(dim).
CoordType z() const
Access the third component of a vector.
CoordType x() const
Access the first component of a vector.
CoordType y() const
Access the second component of a vector.
Utility class for providing zero primitives. This class will only work with simple structures such as...
Generic library namespace.
double CoordType
Basic floating point type.
RotMatrix< dim > Prod(const RotMatrix< dim > &m1, const RotMatrix< dim > &m2)
returns m1 * m2
Point< dim > Barycenter(const container< Point< dim >, std::allocator< Point< dim > > > &c)
Find the center of a set of points, all weighted equally.
Point< dim > Midpoint(const Point< dim > &p1, const Point< dim > &p2, CoordType dist=0.5)