Blender V4.3
BLI_math_vector_mpq_types.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
11#include "BLI_math_vector.hh"
12
13#ifdef WITH_GMP
14
15# include "BLI_math_mpq.hh"
16
17namespace blender {
18
19using mpq2 = VecBase<mpq_class, 2>;
20using mpq3 = VecBase<mpq_class, 3>;
21
22namespace math {
23
24uint64_t hash_mpq_class(const mpq_class &value);
25
26template<> inline uint64_t vector_hash(const mpq2 &vec)
27{
28 return hash_mpq_class(vec.x) ^ (hash_mpq_class(vec.y) * 33);
29}
30
31template<> inline uint64_t vector_hash(const mpq3 &vec)
32{
33 return hash_mpq_class(vec.x) ^ (hash_mpq_class(vec.y) * 33) ^ (hash_mpq_class(vec.z) * 33 * 37);
34}
35
40template<> inline mpq_class length(const mpq2 &a)
41{
42 return mpq_class(sqrt(length_squared(a).get_d()));
43}
44
49template<> inline mpq_class length(const mpq3 &a)
50{
51 return mpq_class(sqrt(length_squared(a).get_d()));
52}
53
57inline mpq_class distance_squared_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer)
58{
59 buffer = a;
60 buffer -= b;
61 return dot(buffer, buffer);
62}
63
67inline mpq_class dot_with_buffer(const mpq3 &a, const mpq3 &b, mpq3 &buffer)
68{
69 buffer = a;
70 buffer *= b;
71 buffer.x += buffer.y;
72 buffer.x += buffer.z;
73 return buffer.x;
74}
75
76} // namespace math
77
78} // namespace blender
79
80#endif /* WITH_GMP */
SIMD_FORCE_INLINE btScalar length() const
Return the length of the vector.
Definition btVector3.h:257
local_group_size(16, 16) .push_constant(Type b
T length_squared(const VecBase< T, Size > &a)
T sqrt(const T &a)
uint64_t vector_hash(const T &vec)
unsigned __int64 uint64_t
Definition stdint.h:90