Blender  V3.3
BLI_math_vec_mpq_types.hh
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
9 #include "BLI_math_vector.hh"
10 
11 #ifdef WITH_GMP
12 
13 # include "BLI_math_mpq.hh"
14 
15 namespace blender {
16 
17 using mpq2 = vec_base<mpq_class, 2>;
18 using mpq3 = vec_base<mpq_class, 3>;
19 
20 namespace math {
21 
22 uint64_t hash_mpq_class(const mpq_class &value);
23 
24 template<> inline uint64_t vector_hash(const mpq2 &vec)
25 {
26  return hash_mpq_class(vec.x) ^ (hash_mpq_class(vec.y) * 33);
27 }
28 
29 template<> inline uint64_t vector_hash(const mpq3 &vec)
30 {
31  return hash_mpq_class(vec.x) ^ (hash_mpq_class(vec.y) * 33) ^ (hash_mpq_class(vec.z) * 33 * 37);
32 }
33 
38 template<> inline mpq_class length(const mpq2 &a)
39 {
40  return mpq_class(sqrt(length_squared(a).get_d()));
41 }
42 
47 template<> inline mpq_class length(const mpq3 &a)
48 {
49  return mpq_class(sqrt(length_squared(a).get_d()));
50 }
51 
55 inline mpq_class distance_squared_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer)
56 {
57  buffer = a;
58  buffer -= b;
59  return dot(buffer, buffer);
60 }
61 
65 inline mpq_class dot_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer)
66 {
67  buffer = a;
68  buffer *= b;
69  buffer.x += buffer.y;
70  buffer.x += buffer.z;
71  return buffer.x;
72 }
73 
74 } // namespace math
75 
76 } // namespace blender
77 
78 #endif /* WITH_GMP */
sqrt(x)+1/max(0
ccl_global float * buffer
static unsigned a[3]
Definition: RandGen.cpp:78
T dot(const vec_base< T, Size > &a, const vec_base< T, Size > &b)
T length(const vec_base< T, Size > &a)
uint64_t vector_hash(const T &vec)
T length_squared(const vec_base< T, Size > &a)
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
unsigned __int64 uint64_t
Definition: stdint.h:90