summaryrefslogtreecommitdiff
path: root/include/gal/opengl/glm/gtx/vector_query.inl
blob: c9553153545302137d64d22d4f197c957f3315e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
///////////////////////////////////////////////////////////////////////////////////////////////////
// OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
///////////////////////////////////////////////////////////////////////////////////////////////////
// Created : 2007-03-05
// Updated : 2010-02-16
// Licence : This source is under MIT License
// File    : glm/gtx/vector_query.inl
///////////////////////////////////////////////////////////////////////////////////////////////////
// Dependency:
// - GLM core
///////////////////////////////////////////////////////////////////////////////////////////////////

#include <cassert>

namespace glm
{
	template <typename T>
	GLM_FUNC_QUALIFIER bool areCollinear
	(
		detail::tvec2<T> const & v0, 
		detail::tvec2<T> const & v1, 
		typename detail::tvec2<T>::value_type const & epsilon
	)
	{
		return length(cross(detail::tvec3<T>(v0, T(0)), detail::tvec3<T>(v1, T(0)))) < epsilon;
	}

	template <typename T>
	GLM_FUNC_QUALIFIER bool areCollinear
	(
		detail::tvec3<T> const & v0, 
		detail::tvec3<T> const & v1, 
		typename detail::tvec3<T>::value_type const & epsilon
	)
	{
		return length(cross(v0, v1)) < epsilon;
	}

	template <typename T>
	GLM_FUNC_QUALIFIER bool areCollinear
	(
		detail::tvec4<T> const & v0, 
		detail::tvec4<T> const & v1, 
		typename detail::tvec4<T>::value_type const & epsilon
	)
	{
		return length(cross(detail::tvec3<T>(v0), detail::tvec3<T>(v1))) < epsilon;
	}

	template <typename genType>
	GLM_FUNC_QUALIFIER bool areOrthogonal
	(
		genType const & v0, 
		genType const & v1, 
		typename genType::value_type const & epsilon
	)
	{
		return abs(dot(v0, v1)) <= max(
			typename genType::value_type(1), 
			length(v0)) * max(
				typename genType::value_type(1), 
				length(v1)) * epsilon;
	}

	template <typename genType, template <typename> class vecType> 
	GLM_FUNC_QUALIFIER bool isNormalized
	(
		vecType<genType> const & v, 
		genType const & epsilon
	)
	{
		return abs(length(v) - genType(1)) <= genType(2) * epsilon;
	}

	template <typename valType> 
	GLM_FUNC_QUALIFIER bool isNull
	(
		detail::tvec2<valType> const & v, 
		valType const & epsilon
	)
	{
		return length(v) <= epsilon;
	}

	template <typename valType> 
	GLM_FUNC_QUALIFIER bool isNull
	(
		detail::tvec3<valType> const & v, 
		valType const & epsilon
	)
	{
		return length(v) <= epsilon;
	}

	template <typename valType> 
	GLM_FUNC_QUALIFIER bool isNull
	(
		detail::tvec4<valType> const & v, 
		valType const & epsilon
	)
	{
		return length(v) <= epsilon;
	}

	template <typename T> 
	GLM_FUNC_QUALIFIER bool isCompNull
	(
		T const & s, 
		T const & epsilon
	)
	{
		return abs(s) < epsilon;
	}

	template <typename T> 
	GLM_FUNC_QUALIFIER detail::tvec2<bool> isCompNull
	(
		detail::tvec2<T> const & v, 
		T const & epsilon)
	{
		return detail::tvec2<bool>(
			(abs(v.x) < epsilon),
			(abs(v.y) < epsilon));
	}

	template <typename T> 
	GLM_FUNC_QUALIFIER detail::tvec3<bool> isCompNull
	(
		detail::tvec3<T> const & v, 
		T const & epsilon
	)
	{
		return detail::tvec3<bool>(
			abs(v.x) < epsilon,
			abs(v.y) < epsilon,
			abs(v.z) < epsilon);
	}

	template <typename T> 
	GLM_FUNC_QUALIFIER detail::tvec4<bool> isCompNull
	(
		detail::tvec4<T> const & v, 
		T const & epsilon
	)
	{
		return detail::tvec4<bool>(
			abs(v.x) < epsilon,
			abs(v.y) < epsilon,
			abs(v.z) < epsilon,
			abs(v.w) < epsilon);
	}

	template <typename genType>
	GLM_FUNC_QUALIFIER bool areOrthonormal
	(
		genType const & v0, 
		genType const & v1, 
		typename genType::value_type const & epsilon
	)
	{
		return isNormalized(v0, epsilon) && isNormalized(v1, epsilon) && (abs(dot(v0, v1)) <= epsilon);
	}

}//namespace glm