Skip to content

Commit

Permalink
v0.9.0 - added access to iterators for vector_base -- name refactored…
Browse files Browse the repository at this point in the history
… the duck type interface for the vectors -- added a few iterator tests
  • Loading branch information
davidbrowne committed Feb 15, 2023
1 parent f6e1a67 commit 00b308c
Show file tree
Hide file tree
Showing 5 changed files with 241 additions and 174 deletions.
26 changes: 13 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,11 @@ This may be a single header library, but if Visual Studio is being used, we reco

## Status

Current version: `v0.8.14`
Current version: `v0.9.0`

* **All the vector and matrix functionality is implemented.**
* First pass at test coverage. Everything major has some tests, but code coverage is not 100%.
* [Released v0.8.0](https://github.com/davidbrowne/dsga/releases/tag/v0.8.0)
* [Released v0.9.0](https://github.com/davidbrowne/dsga/releases/tag/v0.9.0)

### The next steps
* Example projects: need small, medium, and large examples. The quick peek at the top of this page is a start, as is a [more detailed generic version of the example](docs/DETAILS.md#detailed-generic-example).
Expand All @@ -195,7 +195,7 @@ More in depth explanation can be found in the [details](docs/DETAILS.md).

This project uses [doctest](https://github.com/onqtam/doctest) for testing. We occasionally use [nanobench](https://github.com/martinus/nanobench) for understanding implementation tradeoffs.

Both MSVC and gcc (for Windows and on Ubuntu on WSL2) pass all the tests. clang for Windows passes, but there are 2 assertions out of 1874 that fail for clang-15 on Ubuntu, which appears to have a problem with ```std::is_trivial_v<>```.
Both MSVC and gcc (for Windows and on Ubuntu on WSL2) pass all the tests. clang for Windows passes, but there are 2 assertions out of 1878 that fail for clang-15 on Ubuntu, which appears to have a problem with ```std::is_trivial_v<>```.

The tests have been most recently run on:

Expand All @@ -207,8 +207,8 @@ The tests have been most recently run on:
[doctest] doctest version is "2.4.9"
[doctest] run with "--help" for options
===============================================================================
[doctest] test cases: 84 | 84 passed | 0 failed | 0 skipped
[doctest] assertions: 1890 | 1890 passed | 0 failed |
[doctest] test cases: 85 | 85 passed | 0 failed | 0 skipped
[doctest] assertions: 1894 | 1894 passed | 0 failed |
[doctest] Status: SUCCESS!
```

Expand All @@ -218,8 +218,8 @@ The tests have been most recently run on:
[doctest] doctest version is "2.4.9"
[doctest] run with "--help" for options
===============================================================================
[doctest] test cases: 84 | 84 passed | 0 failed | 0 skipped
[doctest] assertions: 1890 | 1890 passed | 0 failed |
[doctest] test cases: 85 | 85 passed | 0 failed | 0 skipped
[doctest] assertions: 1894 | 1894 passed | 0 failed |
[doctest] Status: SUCCESS!
```

Expand All @@ -231,8 +231,8 @@ Performs all the unit tests except where there is lack of support for ```std::is
[doctest] doctest version is "2.4.9"
[doctest] run with "--help" for options
===============================================================================
[doctest] test cases: 84 | 84 passed | 0 failed | 0 skipped
[doctest] assertions: 1874 | 1874 passed | 0 failed |
[doctest] test cases: 85 | 85 passed | 0 failed | 0 skipped
[doctest] assertions: 1878 | 1878 passed | 0 failed |
[doctest] Status: SUCCESS!
```

Expand All @@ -244,8 +244,8 @@ Performs all the unit tests except where there is lack of support for ```std::is
[doctest] doctest version is "2.4.9"
[doctest] run with "--help" for options
===============================================================================
[doctest] test cases: 84 | 84 passed | 0 failed | 0 skipped
[doctest] assertions: 1890 | 1890 passed | 0 failed |
[doctest] test cases: 85 | 85 passed | 0 failed | 0 skipped
[doctest] assertions: 1894 | 1894 passed | 0 failed |
[doctest] Status: SUCCESS!
```

Expand Down Expand Up @@ -275,8 +275,8 @@ dsga/tests/swizzle_test.cxx:1849: ERROR: CHECK_UNARY( std::is_trivial_v<dmat4> )
values: CHECK_UNARY( false )
===============================================================================
[doctest] test cases: 84 | 83 passed | 1 failed | 0 skipped
[doctest] assertions: 1874 | 1872 passed | 2 failed |
[doctest] test cases: 85 | 84 passed | 1 failed | 0 skipped
[doctest] assertions: 1878 | 1876 passed | 2 failed |
[doctest] Status: FAILURE!
```

Expand Down
27 changes: 16 additions & 11 deletions docs/DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ vec4 big_vec;
vec3 smaller_vec(big_vec.zyx);
```
Swizzling uses dot notation, e.g., ```foo.xy, bar.zw, baz.xxyy```. This gives you a type of vector that is a view on the data of the original vector. The swizzles are part of the original vector, and they have the same lifetime. The "x" index means the first value in the vector, "y" means the second, "z" means the third, and "w" means the fourth, so "xyzw" are the possible values in a swizzle, depending on the size of the original vector. In [GLSL](https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.4.60.pdf), there are 3 different domains for swizzling: ```xyzw```, ```rgba```, and ```stpq```. We use "xyzw" when talking about spatial coordinates, "rgba" when talking about color coordinates, and "stpq" when talking about texture coordinates. Since dsga is intended for geometry and algebra, we only bothered supporting **xyzw** for swizzling.
Swizzling uses dot notation, e.g., ```foo.xy, bar.zw, baz.xxyy```. This gives you a type of vector that is a view on the data of the original vector. The swizzles are part of the original vector, and they have the same lifetime. The "x" index means the first value in the vector, "y" means the second, "z" means the third, and "w" means the fourth, so "xyzw" are the possible values in a swizzle, depending on the size of the original vector. In [GLSL](https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.4.60.pdf), there are 3 different domains for swizzling: ```xyzw```, ```rgba```, and ```stpq```. We use "xyzw" when talking about spatial coordinates, "rgba" when talking about color coordinates, and "stpq" when talking about texture coordinates. Since dsga is intended for geometry and algebra, we only felt the need to support the "xyzw" set for swizzling.
A length 1 vector can only refer to "x", but it can do so up to 4 times in a swizzle:
```c++
Expand Down Expand Up @@ -194,6 +194,7 @@ The matrix types are very generic. One can pre-mulitply (matrix on left, vector
# API

* Matrices and Vectors
* [Index Interface](#index-interface)
* [Iterators](#iterators)
* [Tuple Interface](#tuple-interface)
* [Low Level Pointer Access](#low-level-pointer-access)
Expand Down Expand Up @@ -221,16 +222,22 @@ We have [enumerated all the specific classes](#types-and-functions) we support i

Please look at what is in the [GLSL spec](https://www.khronos.org/registry/OpenGL/specs/gl/GLSLangSpec.4.60.pdf), especially Section 5 and Section 8, for a thorough look at the API. We will summarize what was implemented and how we supplemented matrix and vector.

### Index Interface

The vector structs closely model short versions of ```std::array```, including using ```operator []``` for access to scalar components. Matrix also has "operator []", but it is for accessing column vectors.

For vector swizzles, only *writable* swizzles can use ```operator []``` for write access to the vector.

### Iterators

Both the vector and matrix structs support **begin/cbegin/rbegin/crbegin** and **end/cend/rend/crend** iterator creation functions in order to provide non-const and const iterators. The ```indexed_vector``` iterators pass the ```std::random_access_iterator``` concept. This gives us access to:
Both the vector and matrix structs support ```begin()/cbegin()/rbegin()/crbegin()``` and ```end()/cend()/rend()/crend()``` iterator creation functions in order to provide non-const and const iterators. The ```indexed_vector``` iterators pass the ```std::random_access_iterator``` concept. This gives us access to:

* Standard Library Algorithms
* [Range-based for loop](https://en.cppreference.com/w/cpp/language/range-for)

### Tuple Interface

Both the vector and matrix structs support **std::tuple_element<>**, **std::tuple_size<>** and **get<>** in order to provide basic ```std::tuple``` support. This gives us access to:
Both the vector and matrix structs support ```std::tuple_element<>```, ```std::tuple_size<>``` and ```get<>``` in order to provide basic ```std::tuple``` support. This gives us access to:

* Data structures in same manner as ```tuple```
* [Structured Binding](https://en.cppreference.com/w/cpp/language/structured_binding)
Expand All @@ -239,9 +246,9 @@ Both the vector and matrix structs support **std::tuple_element<>**, **std::tupl

Both the vector and matrix structs support ```data()``` and ```size()``` in order to provide pointer access to the underlying data. The parameter pack returned by ```sequence()``` can also be helpful here to map the physical order from ```data()``` to the logical order (only useful for generic vector situations or when using ```indexed_vector```). *Hopefully*, no one wants to use pointer data to manipulate or access the data structures, but this approach exists if it is deemed appropriate:

* **T \*data()** gives a pointer to the underlying vector elements or matrix columns, in physical order.
* **std::size_t size()** gives the number of elements in the vector or number of columns in the matrix.
* **std::index_sequence<Is...> sequence()** (only for vectors) gives a parameter pack that maps the physical order to the logical order. For a ```basic_vector``` those are the same, but for an ```indexed_vector``` they are mostly not the same. Pack expansion and folding are tools that might help with the low-level pointer access for vectors.
* ```T *data()``` gives a pointer to the underlying vector elements or matrix columns, in physical order.
* ```std::size_t size()``` gives the number of elements in the vector or number of columns in the matrix.
* ```std::index_sequence<Is...> sequence()``` (only for vectors) gives a parameter pack that maps the physical order to the logical order. For a ```basic_vector``` those are the same, but for an ```indexed_vector``` they are mostly not the same. Pack expansion and folding are tools that might help with the low-level pointer access for vectors.

## Vector

Expand Down Expand Up @@ -308,12 +315,10 @@ This approach is exactly what ```basic_matrix``` does.
### Vector Member Functions
These are the members that are not part of the [iterator interface](#iterators), the [tuple interface](#tuple-interface), or the [low-level interface](#low-level-pointer-access).
These are the members that are not part of the [index interface](#index-interface), [iterator interface](#iterators), the [tuple interface](#tuple-interface), or the [low-level interface](#low-level-pointer-access).
* **operator =** - assignment operator. The vector needs to be the same length and underlying types must be convertible.
* **int length()** - returns the number of elements in a vector. This is part of the spec, and is the same as ```size()``` except it has a different return type.
* **operator []** - a generic way to access vector data. the ```x``` value is index 0, the ```y``` value is index 1, the ```z``` value is index 2, and the ```w``` value is index 3, assuming the vector is long enough to access those index values. Can be used for both reading and writing, assuming it isn't const or otherwise not allowed for writing.
* **set()** - this is the way of setting all the values for the vector at the same time. It takes the same number of scalar arguments as there are vector elements. This function is helpful at preventing trouble when there are potential aliasing problems.
* ```operator =``` - assignment operator. The vector needs to be the same length and underlying types must be convertible.
* ```int length()``` - returns the number of elements in a vector. This is part of the spec, and is the same as ```size()``` except it has a different return type.
### Vector Operators
The vector operators all work component-wise.
Expand Down
98 changes: 50 additions & 48 deletions docs/vec_base_uml.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 00b308c

Please sign in to comment.