Library of Assembled Shared Sources
point_2d.h
Go to the documentation of this file.
1/** @file
2 * @author Bram de Greve (bram@cocamware.com)
3 * @author Tom De Muer (tom@cocamware.com)
4 *
5 * *** BEGIN LICENSE INFORMATION ***
6 *
7 * The contents of this file are subject to the Common Public Attribution License
8 * Version 1.0 (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 * http://lass.sourceforge.net/cpal-license. The License is based on the
11 * Mozilla Public License Version 1.1 but Sections 14 and 15 have been added to cover
12 * use of software over a computer network and provide for limited attribution for
13 * the Original Developer. In addition, Exhibit A has been modified to be consistent
14 * with Exhibit B.
15 *
16 * Software distributed under the License is distributed on an "AS IS" basis, WITHOUT
17 * WARRANTY OF ANY KIND, either express or implied. See the License for the specific
18 * language governing rights and limitations under the License.
19 *
20 * The Original Code is LASS - Library of Assembled Shared Sources.
21 *
22 * The Initial Developer of the Original Code is Bram de Greve and Tom De Muer.
23 * The Original Developer is the Initial Developer.
24 *
25 * All portions of the code written by the Initial Developer are:
26 * Copyright (C) 2004-2011 the Initial Developer.
27 * All Rights Reserved.
28 *
29 * Contributor(s):
30 *
31 * Alternatively, the contents of this file may be used under the terms of the
32 * GNU General Public License Version 2 or later (the GPL), in which case the
33 * provisions of GPL are applicable instead of those above. If you wish to allow use
34 * of your version of this file only under the terms of the GPL and not to allow
35 * others to use your version of this file under the CPAL, indicate your decision by
36 * deleting the provisions above and replace them with the notice and other
37 * provisions required by the GPL License. If you do not delete the provisions above,
38 * a recipient may use your version of this file under either the CPAL or the GPL.
39 *
40 * *** END LICENSE INFORMATION ***
41 */
42
43
44
45/** @struct lass::prim::Point_2d
46 * @brief 2D Point
47 * @author BdG
48 * @date 2003
49 */
50
51
52
53#ifndef LASS_GUARDIAN_OF_INCLUSION_PRIM_POINT_2D_H
54#define LASS_GUARDIAN_OF_INCLUSION_PRIM_POINT_2D_H
55
56
57
58
59#include "prim_common.h"
60#include "vector_2d.h"
62
63namespace lass
64{
65namespace prim
66{
67
68template<typename T>
69struct LASS_SIMD_ALIGN Point2D
70{
71public:
72
73 typedef Point2D<T> TSelf;
74
75 typedef Vector2D<T> TVector;
76
77 typedef typename TVector::TValue TValue;
78 typedef typename TVector::TParam TParam;
79 typedef typename TVector::TReference TReference;
80 typedef typename TVector::TConstReference TConstReference;
81 typedef typename TVector::TNumTraits TNumTraits;
82
83 enum { dimension = TVector::dimension }; /**< number of dimensions of vector */
84
85 template <typename U> struct Rebind
86 {
87 typedef Point2D<U> Type;
88 };
89
90 TValue x;
91 TValue y;
92
93 Point2D();
94 Point2D(TParam x, TParam y);
95 template <typename U> explicit Point2D(const Point2D<U>& other);
96 template <typename U> explicit Point2D(const Vector2D<U>& position);
97 template <typename U> explicit Point2D(const U& x, const U& y);
98
99 const TVector position() const;
100 TConstReference operator[](size_t index) const;
101 TReference operator[](size_t index);
102 TConstReference at(signed index) const;
103 TReference at(signed index);
104
105 Point2D<T>& operator+=(const Vector2D<T>& offset);
106 Point2D<T>& operator-=(const Vector2D<T>& offset);
107
108 bool isZero() const;
109 bool isNaN() const;
110};
111
112template<typename T> bool operator==(const Point2D<T>& a, const Point2D<T>& b);
113template<typename T> bool operator!=(const Point2D<T>& a, const Point2D<T>& b);
114
115template<typename T> Point2D<T> operator+(const Point2D<T>& a, const Vector2D<T>& b);
116template<typename T> Point2D<T> operator+(const Vector2D<T>& a, const Point2D<T>& b);
117template<typename T> Point2D<T> operator-(const Point2D<T>& a, const Vector2D<T>& b);
118template<typename T> Vector2D<T> operator-(const Point2D<T>& a, const Point2D<T>& b);
119
120template<typename T> typename Point2D<T>::TValue distance(const Point2D<T>& a, const Point2D<T>& b);
121template<typename T> typename Point2D<T>::TValue squaredDistance(const Point2D<T>& a, const Point2D<T>& b);
122template<typename T> Point2D<T> pointwiseMin(const Point2D<T>& a, const Point2D<T>& b);
123template<typename T> Point2D<T> pointwiseMax(const Point2D<T>& a, const Point2D<T>& b);
124template<typename T> Point2D<T> lerp(const Point2D<T>& a, const Point2D<T>& b, typename Point2D<T>::TParam t);
125
126template<typename T> std::ostream& operator<<(std::ostream& stream, const Point2D<T>& b);
127template<typename T> io::XmlOStream& operator<<(io::XmlOStream& stream, const Point2D<T>& b);
128template<typename T> std::istream& operator>>(std::istream& stream, Point2D<T>& b);
129template<typename T> lass::io::MatlabOStream& operator<<(lass::io::MatlabOStream& stream, const Point2D<T>& b);
130
131
132template<typename T> T doubleTriangleArea( const Point2D<T>& a, const Point2D<T>& b, const Point2D<T>& c );
133template<typename T> bool cw( const Point2D<T>& a, const Point2D<T>& b, const Point2D<T>& c );
134template<typename T> bool ccw( const Point2D<T>& a, const Point2D<T>& b, const Point2D<T>& c );
135template<typename T> bool weakCw( const Point2D<T>& a, const Point2D<T>& b, const Point2D<T>& c );
136template<typename T> bool weakCcw( const Point2D<T>& a, const Point2D<T>& b, const Point2D<T>& c );
137template<typename T> bool inCircle( const Point2D<T>& a, const Point2D<T>& b, const Point2D<T>& c, const Point2D<T>& d );
138
139}
140
141}
142
143#include "point_2d.inl"
144
145#define LASS_PRIM_HAVE_PY_EXPORT_TRAITS_POINT_2D
146#ifdef LASS_GUARDIAN_OF_INCLUSION_UTIL_PYOBJECT_PLUS_H
148#endif
149
150#endif
Output stream for writing a selection of geometric primitives to matlab M files.
T lerp(const T &a, const T &b, const T &f)
linear interpolation between a and b
#define LASS_SIMD_ALIGN
if LASS_SIMD_ALIGNMENT is set, use LASS_SIMD_ALIGN to align some structures on SIMD alignment boundar...
Library for Assembled Shared Sources.
Definition config.h:53