Skip to content

Commit 6749e0d

Browse files
committed
allow dot(), cross(), and distance() to have arguments that are different floating point types
1 parent 2ad85fd commit 6749e0d

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ The following links to the shading specification should help with understanding
211211
* [Angle and Trigonometry Functions](https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.60.html#angle-and-trigonometry-functions): there are also scalar versions of these functions, but where c++ does the same thing, it might be easier to use the ```std::``` version instead of the ```dsga::``` version.
212212
* [Exponential Functions](https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.60.html#exponential-functions): there are also scalar versions of these functions, but where c++ does the same thing, it might be easier to use the ```std::``` version instead of the ```dsga::``` version.
213213
214-
```dsga::sqrt()``` and ```dsga::inversesqrt()``` for ```double``` scalars and vectors have constexpr versions that are not exact matches for the output of ```std::sqrt()```. They are both very close, where most cases are exact, and they are off by 1 or 2 ulps at most when not exact.
214+
```dsga::sqrt()``` and ```dsga::inversesqrt()``` for ```double``` scalars and vectors have constexpr context versions that are not exact matches for the output of ```std::sqrt()```. They are both very close, where most cases are exact, and they are off by 1 or 2 ulps at most when not exact.
215215
216216
* [Common Functions](https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.60.html#common-functions): there are also scalar versions of these functions, but where c++ does the same thing, it might be easier to use the ```std::``` version instead of the ```dsga::``` version.
217217
* [Geometric Functions](https://registry.khronos.org/OpenGL/specs/gl/GLSLangSpec.4.60.html#geometric-functions): ```ftransform()``` is not implemented as it is only for GLSL vertex shader programs.
@@ -236,7 +236,7 @@ Remember, this is a c++20 library, so that needs to be the minimum standard that
236236
237237
## Status
238238
239-
Current version: `v0.10.7`
239+
Current version: `v0.10.8`
240240
241241
* **All the intended vector and matrix functionality from the GLSL specification is implemented.** We keep refining the implementation, and we keep expanding the API to better support ```c++20``` idioms and usage as we go.
242242
* First pass at test coverage. Everything major has some tests, but code coverage is not 100%.
@@ -291,7 +291,7 @@ The tests have been most recently run on:
291291
[doctest] Status: SUCCESS!
292292
```
293293
294-
* **clang 16.0.2** on Windows, [official binaries](https://github.com/llvm/llvm-project/releases/tag/llvmorg-16.0.2), with MSVC installed:
294+
* **clang 16.0.3** on Windows, [official binaries](https://github.com/llvm/llvm-project/releases/tag/llvmorg-16.0.3), with MSVC installed:
295295
296296
Performs all the unit tests except where there is lack of support for ```std::is_corresponding_member<>```, and this is protected with a feature test macro.
297297
@@ -304,6 +304,19 @@ Performs all the unit tests except where there is lack of support for ```std::is
304304
[doctest] Status: SUCCESS!
305305
```
306306
307+
### Mint LMDE 5 running in WSL2 for Windows 11
308+
309+
* **gcc 13.1.0**
310+
311+
```
312+
[doctest] doctest version is "2.4.11"
313+
[doctest] run with "--help" for options
314+
===============================================================================
315+
[doctest] test cases: 100 | 100 passed | 0 failed | 0 skipped
316+
[doctest] assertions: 2397 | 2397 passed | 0 failed |
317+
[doctest] Status: SUCCESS!
318+
```
319+
307320
### Ubuntu 22.04 running in WSL2 for Windows 11
308321
309322
* **gcc 12.1.0**
@@ -317,7 +330,7 @@ Performs all the unit tests except where there is lack of support for ```std::is
317330
[doctest] Status: SUCCESS!
318331
```
319332
320-
* **clang 16.0.3**
333+
* **clang 16.0.4**
321334
322335
Performs all the unit tests except where there is lack of support for ```std::is_corresponding_member<>```, and this is protected with a feature test macro.
323336

include/dsga.hxx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ inline void dsga_constexpr_assert_failed(Assert &&a) noexcept
5858

5959
constexpr inline int DSGA_MAJOR_VERSION = 0;
6060
constexpr inline int DSGA_MINOR_VERSION = 10;
61-
constexpr inline int DSGA_PATCH_VERSION = 7;
61+
constexpr inline int DSGA_PATCH_VERSION = 8;
6262

6363
namespace dsga
6464
{
@@ -5015,23 +5015,24 @@ namespace dsga
50155015
// 8.5 - geometric
50165016
//
50175017

5018-
template <bool W1, floating_point_scalar T, std::size_t C, typename D1, bool W2, typename D2>
5019-
[[nodiscard]] constexpr auto dot(const vector_base<W1, T, C, D1> &x,
5020-
const vector_base<W2, T, C, D2> &y) noexcept
5018+
template <bool W1, floating_point_scalar T1, std::size_t C, typename D1, bool W2, floating_point_scalar T2, typename D2>
5019+
[[nodiscard]] constexpr auto dot(const vector_base<W1, T1, C, D1> &x,
5020+
const vector_base<W2, T2, C, D2> &y) noexcept
50215021
{
50225022
return [&]<std::size_t ...Is>(std::index_sequence<Is...>) noexcept
50235023
{
50245024
return ((x[Is] * y[Is]) + ...);
50255025
}(std::make_index_sequence<C>{});
50265026
}
50275027

5028-
template <bool W1, floating_point_scalar T, typename D1, bool W2, typename D2>
5029-
[[nodiscard]] constexpr auto cross(const vector_base<W1, T, 3u, D1> &x,
5030-
const vector_base<W2, T, 3u, D2> &y) noexcept
5028+
template <bool W1, floating_point_scalar T1, typename D1, bool W2, floating_point_scalar T2, typename D2>
5029+
[[nodiscard]] constexpr auto cross(const vector_base<W1, T1, 3u, D1> &x,
5030+
const vector_base<W2, T2, 3u, D2> &y) noexcept
50315031
{
5032-
return basic_vector<T, 3u>((x[1] * y[2]) - (y[1] * x[2]),
5033-
(x[2] * y[0]) - (y[2] * x[0]),
5034-
(x[0] * y[1]) - (y[0] * x[1]));
5032+
using Common = std::common_type_t<T1, T2>;
5033+
return basic_vector<Common, 3u>((x[1] * y[2]) - (y[1] * x[2]),
5034+
(x[2] * y[0]) - (y[2] * x[0]),
5035+
(x[0] * y[1]) - (y[0] * x[1]));
50355036
}
50365037

50375038
template <bool W, floating_point_scalar T, std::size_t C, typename D>
@@ -5046,9 +5047,9 @@ namespace dsga
50465047
return cxcm::abs(x[0u]);
50475048
}
50485049

5049-
template <bool W1, floating_point_scalar T, std::size_t C, typename D1, bool W2, typename D2>
5050-
[[nodiscard]] constexpr auto distance(const vector_base<W1, T, C, D1> &p0,
5051-
const vector_base<W2, T, C, D2> &p1) noexcept
5050+
template <bool W1, floating_point_scalar T1, std::size_t C, typename D1, bool W2, floating_point_scalar T2, typename D2>
5051+
[[nodiscard]] constexpr auto distance(const vector_base<W1, T1, C, D1> &p0,
5052+
const vector_base<W2, T2, C, D2> &p1) noexcept
50525053
{
50535054
return length(p1 - p0);
50545055
}

0 commit comments

Comments
 (0)