Skip to content

m-tosch/mu

Repository files navigation

μ

codecov

A small, simple c++ math library

The goal of this repository is to provide a header library for fixed size vector and matrix math that is easy to use and fully verified by tests.

Demo

Example 1

Calculate the mean and standard deviation of a vector.

mu::Vector<3,float> v = {8.3F, 1.9F, 4.5F};
float mean = v.mean();
float std = v.std();
std::cout << "mean: " << mean << std::endl;
std::cout << "std: " << std << std::endl;

output

mean: 4.9
std: 2.62805

Example 2

Find the maximum value on a matrix diagonal.

code
mu::Matrix<3,3,int> m = { {3,5,7}, {6,1,9}, {4,8,6} };
int max = mu::max(m.diag());
std::cout << m << std::endl;
std::cout << "max element on diagonal: " << max << std::endl;

output

[ [ 3, 5, 7 ],
  [ 6, 1, 9 ],
  [ 4, 8, 6 ] ]
max element on diagonal: 6

Example 3

Rotate a 2D vector by π/2.

code
mu::Vector2D<float> v = {2.25F, 5.75F};
std::cout << "before: " << v << std::endl;
v.rotate(mu::pi / 2);
std::cout << "after: " << v << std::endl;

output

before: [ 2.25, 5.75 ]
after: [ -5.75, 2.25 ]

Usage

To use this code with cmake, include the source directory either directly or into your target.

target_include_directories(my_target PRIVATE ${CMAKE_SOURCE_DIR}/mu/include)

Afterwards, mu header files can be included like this

#include "mu/vector.h"
minmal example

structure

/dependencies
  /mu
CMakeLists.txt
main.cpp

CMakeLists.txt

cmake_minimum_required(VERSION 2.4)

project(hello_world)

add_executable(app main.cpp)

target_include_directories(app PRIVATE ${CMAKE_SOURCE_DIR}/dependencies/mu/include)

main.cpp

#include <iostream>
#include "mu/vector.h"

int main() {
    mu::Vector<2,int> v = {1,2};
    std::cout << v << std::endl;
    return 0;
}

commands

$ mkdir dependencies
$ cd dependencies
$ git clone https://github.com/m-tosch/mu.git
$ cd ..
$ mkdir build
$ cd build
$ cmake .
$ make
$ ./app

output

[ 1, 2 ]

Installation

*for developers

Tools

In Docker Desktop settings under "WSL Integration" you should see the Ubuntu distro you just installed. Enable it then restart docker.

In VS code, clone the repository into a container: View → Command Palette... → "Remote-Containers: Clone Repository in Container Volume" or open the repository as a remote folder inside a container. The second option runs slower because of the constant communication with the host filesystem.

The .devcontainer folder holds files that specify all additional Software required for development. It is automatically installed when running the container for the first time.

Documentation

The documentation can be found here

You can generate the documentation locally from the command line inside the doc folder:

doxygen Doxyfile

The documentation will be generated in html form inside a doc/html folder. View the report by opening the index.html file inside that folder in a browser.

Tests

The tests use googletest

After successfully building the project, you can run the tests locally from the command line inside the generated build/tests folder:

./mu_tests

Coverage

The coverage can be found here

The code coverage can be generated using gcov or llvm-cov. gcov uses the gcc compiler while llvm-cov uses clang. The latter was implemented to be able to inspect branch coverage or, the llvm equivalent, "region coverage".

You can generate both coverage reports locally from the command line inside the coverage folder:

For gcov (requires gcc)

bash coverage_gcov.sh

For llvm-cov (requires clang)

bash coverage_llvm.sh

The coverage report will be generated in html form in a coverage/html_gcov or a coverage/html_llvm folder respectively. View the report by opening the index.html file inside that folder in a browser.

About

A small, simple c++ math library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages