diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml
new file mode 100644
index 0000000..6be8aea
--- /dev/null
+++ b/.github/workflows/docs.yaml
@@ -0,0 +1,41 @@
+name: Deploy docs
+
+on:
+ push:
+ branches: ["master"]
+ workflow_dispatch:
+
+permissions:
+ contents: read
+ pages: write
+ id-token: write
+
+concurrency:
+ group: "pages"
+ cancel-in-progress: false
+
+jobs:
+ deploy:
+ environment:
+ name: github-pages
+ url: ${{ steps.deployment.outputs.page_url }}
+ runs-on: ubuntu-latest
+ steps:
+ - name: Checkout
+ uses: actions/checkout@v3
+ - name: Install doxygen
+ run: |
+ sudo apt install doxygen graphviz -y
+ - name: Setup Pages
+ uses: actions/configure-pages@v3
+ - name: Build documentation
+ run: |
+ doxygen
+ touch docs/html/.nojekyll
+ - name: Upload artifact
+ uses: actions/upload-pages-artifact@v2
+ with:
+ path: 'docs/html'
+ - name: Deploy to GitHub Pages
+ id: deployment
+ uses: actions/deploy-pages@v2
diff --git a/.github/workflows/unit_testing.yaml b/.github/workflows/unit_testing.yaml
new file mode 100644
index 0000000..cf71eef
--- /dev/null
+++ b/.github/workflows/unit_testing.yaml
@@ -0,0 +1,116 @@
+name: Unit Testing
+
+on:
+ push:
+ branches: [master]
+ pull_request:
+ types: [opened, synchronize, reopened]
+
+jobs:
+ ensure_tests:
+ name: Ensure No Missing Tests
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ name: Checkout repository
+ - run: |
+ ./scripts/test_generator.sh
+ name: Run test generator script
+
+ unit_test_gcc_linux:
+ name: Linux (GCC=v${{ matrix.version }})
+ needs: [ ensure_tests ]
+ strategy:
+ matrix:
+ version: [9, 10, 11, 12, 13]
+ runs-on: ubuntu-latest
+ env:
+ CC: gcc-${{ matrix.version }}
+ CXX: g++-${{ matrix.version }}
+ steps:
+ - uses: actions/checkout@v3
+ name: Checkout repository
+ - uses: egor-tensin/setup-gcc@v1.3
+ name: Install GCC
+ with:
+ version: ${{ matrix.version }}
+ - run: |
+ cmake -Bbuild -DFirefly_ENABLE_TESTS=ON
+ cmake --build build -- -j `nproc`
+ name: Configure and build binaries
+ - run: |
+ ctest --test-dir build/tests/ --verbose
+ name: Run tests
+
+ unit_test_llvm_linux:
+ name: Linux (LLVM=v${{ matrix.version }})
+ needs: [ ensure_tests ]
+ strategy:
+ matrix:
+ version: [11, 12, 13, 14, 15, 16]
+ runs-on: ubuntu-latest
+ env:
+ CC: clang-${{ matrix.version }}
+ CXX: clang++-${{ matrix.version }}
+ steps:
+ - uses: actions/checkout@v3
+ name: Checkout repository
+ - uses: egor-tensin/setup-clang@v1.4
+ name: Install LLVM
+ with:
+ version: ${{ matrix.version }}
+ - run: |
+ cmake -Bbuild -DFirefly_ENABLE_TESTS=ON
+ cmake --build build -- -j `nproc`
+ name: Configure and build binaries
+ - run: |
+ ctest --test-dir build/tests/ --verbose
+ name: Run tests
+
+ unit_test_gcc_macos:
+ name: MacOS (GCC=v${{ matrix.version }})
+ needs: [ ensure_tests ]
+ strategy:
+ matrix:
+ version: [10, 11, 12, 13]
+ runs-on: macos-latest
+ env:
+ CC: gcc-${{ matrix.version }}
+ CXX: g++-${{ matrix.version }}
+ steps:
+ - uses: actions/checkout@v3
+ name: Checkout repository
+ - run: |
+ brew install gcc@${{ matrix.version }}
+ name: Install GCC
+ - run: |
+ cmake -Bbuild -DFirefly_ENABLE_TESTS=ON
+ cmake --build build -- -j `nproc`
+ name: Configure and build binaries
+ - run: |
+ ctest --test-dir build/tests/ --verbose
+ name: Run tests
+
+ unit_test_llvm_macos:
+ name: MacOS (LLVM=v${{ matrix.version }})
+ needs: [ ensure_tests ]
+ strategy:
+ matrix:
+ version: [12, 13, 14, 15, 16]
+ runs-on: macos-latest
+ env:
+ CC: /usr/local/opt/llvm@${{ matrix.version }}/bin/clang
+ CXX: /usr/local/opt/llvm@${{ matrix.version }}/bin/clang++
+ steps:
+ - uses: actions/checkout@v3
+ name: Checkout repository
+ - run: |
+ brew install llvm@${{ matrix.version }}
+ name: Install LLVM
+ - run: |
+ cmake -Bbuild -DFirefly_ENABLE_TESTS=ON
+ cmake --build build -- -j `nproc`
+ name: Configure and build binaries
+ - run: |
+ ctest --test-dir build/tests/ --verbose
+ name: Run tests
diff --git a/.gitignore b/.gitignore
index 1108029..a343eb4 100644
--- a/.gitignore
+++ b/.gitignore
@@ -66,4 +66,10 @@ _deps
# Ignore all local history of files
.history
+### Clangd
+.cache
+
+### Doxygen
+docs
+
# End of https://www.gitignore.io/api/c++,cmake,visualstudiocode
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 6a66170..b37945f 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,5 +1,6 @@
{
"cmake.configureOnOpen": false,
+ "cmake.configureOnEdit": false,
"[cmake]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "twxs.cmake"
@@ -10,7 +11,7 @@
"editor.defaultFormatter": "llvm-vs-code-extensions.vscode-clangd",
"editor.tabSize": 2
},
- "files.associations": {
- "/Doxfile": "doxygen"
- }
+ "clangd.arguments": [
+ "--header-insertion=never"
+ ]
}
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 9f5ef0e..005a742 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,12 +1,14 @@
cmake_minimum_required(VERSION 3.10)
-project(firefly LANGUAGES CXX VERSION 2.0.0)
+project(firefly)
+set(PROJECT_VERSION 2.1.0)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
-add_compile_options(-std=c++17)
+cmake_policy(SET CMP0135 NEW)
-option(Firefly_ENABLE_DOUBLE_PRECISION "Whether or not to enable double precision. If this is false, float will be used." OFF)
+option(Firefly_ENABLE_DOUBLE_PRECISION "Whether or not to enable double precision. If this is false, float will be used." ON)
option(Firefly_ENABLE_EXAMPLES "Whether or not to enable examples" OFF)
+option(Firefly_ENABLE_TESTS "Whether or not to enable tests" OFF)
if (${Firefly_ENABLE_DOUBLE_PRECISION})
add_definitions(-DDOUBLE_PRECISION=1)
@@ -30,5 +32,23 @@ if (${Firefly_ENABLE_EXAMPLES})
add_subdirectory(examples)
endif()
+if (${Firefly_ENABLE_TESTS})
+ message(STATUS "Enabling tests")
+ set(gtest_force_shared_crt ON CACHE BOOL "" FORCE)
+
+ include(FetchContent)
+ FetchContent_Declare(
+ googletest
+ URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
+ )
+ FetchContent_MakeAvailable(googletest)
+ FetchContent_GetProperties(googletest)
+
+ include(GoogleTest)
+ include_directories("${googletest_SOURCE_DIR}/googlemock/include")
+ enable_testing()
+ add_subdirectory(tests)
+endif()
+
install(TARGETS ${PROJECT_NAME}_static ${PROJECT_NAME}_shared)
install(DIRECTORY headers/ DESTINATION include)
diff --git a/Doxfile b/Doxyfile
similarity index 80%
rename from Doxfile
rename to Doxyfile
index 97a5363..76d6714 100644
--- a/Doxfile
+++ b/Doxyfile
@@ -3,8 +3,8 @@
#---------------------------------------------------------------------------
PROJECT_NAME = "Firefly"
-PROJECT_BRIEF = "Standalone library for vector and matrix calculations"
-PROJECT_NUMBER = "2.0"
+PROJECT_BRIEF = "Standalone library for vector calculations"
+PROJECT_NUMBER = "2.1"
FILE_PATTERNS = *.cpp *.hpp
@@ -25,5 +25,5 @@ UML_LOOK = YES
GENERATE_HTML = YES
-HTML_OUTPUT = ./
+HTML_OUTPUT = html
diff --git a/README.md b/README.md
index 5d1c042..4180562 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,11 @@ This is a standalone C++ vector calculation library. It performs addition, subtr
The library was designed to help people learn C++ and its concepts. It's a simple implementation, but it's a good place to start if you want to learn more about linear algebra and C++.
+## Supported Platforms and Compilers
+
+**Linux** GCC v9+ or Clang v11+
+**MacOS** GCC v10+ or Clang v12+
+
## Build and Install
> **Note** Ensure CMake 3.10+ and either Make or Ninja build systems are installed before following the steps.
@@ -19,17 +24,36 @@ The library was designed to help people learn C++ and its concepts. It's a simpl
2. Configure the cmake build
```console
- cmake -Bbuild -DFirefly_ENABLE_EXAMPLES=ON -DFirefly_ENABLE_DOUBLE_PRECISION=ON
+ cmake -Bbuild -DFirefly_ENABLE_EXAMPLES=ON
```
- The given CMake command allows you to enable the compilation of examples using double precision. To disable examples, you can either omit `-DFirefly_ENABLE_EXAMPLES=ON` or explicitly set it to `-DFirefly_ENABLE_EXAMPLES=OFF`. Additionally, if you prefer using single precision (float) instead of double precision, you can either omit `-DFirefly_ENABLE_DOUBLE_PRECISION=ON` or set it to `-DFirefly_ENABLE_DOUBLE_PRECISION=OFF`.
+
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
#include "firefly/vector.hpp"
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
#include "firefly/vector.hpp"
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
This is the complete list of members for Firefly::Vector, including all inherited members.
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
Represents a mathematical vector in n-dimensional space. - More...
- -#include <vector.hpp>
-Public Member Functions | |
Vector ()=delete | |
~Vector ()=default | |
Vector (std::size_t _size) | |
Constructs a vector of a specific size. | |
Vector (VectorType const &_vec) | |
Constructs a vector from a given VectorType (std::vector). | |
Vector (Vector const &_fvec) | |
Copy constructor to create a new vector from an existing one. | |
std::string | View () const |
Returns a string representation of the vector. | |
Real | At (std::size_t idx) const |
Retrieves the value at a specific index in the vector (const version). | |
Real & | At (std::size_t idx) |
Retrieves a reference to the value at a specific index in the vector. | |
Real | operator[] (std::size_t idx) const |
Overloaded subscript operator to access the value at a specific index (const version). | |
Real & | operator[] (std::size_t idx) |
Overloaded subscript operator to access the value at a specific index. | |
std::size_t | Size () const |
Returns the size (number of elements) of the vector. | |
std::size_t | Rank () const |
Returns the rank (dimensionality) of the vector. It is same as Size() method. | |
Vector | Add (Vector const &_fvec) const |
Performs vector addition with another vector and returns the result as a new vector. | |
Vector | Add (Real const &_scalar) const |
Performs scalar addition with a real value and returns the result as a new vector. | |
Vector | operator+ (Vector const &_fvec) const |
Overloaded operator to perform vector addition. | |
Vector | operator+ (Real const &_scalar) const |
Overloaded operator to perform scalar addition. | |
Vector | operator++ () const |
Overloaded prefix increment operator to increment all elements of the vector by one. | |
Vector | Scale (Real const &_fvec) const |
Performs vector scaling by a real value and returns the result as a new vector. | |
Vector | operator* (Real const &_scalar) const |
Overloaded operator to perform vector scaling. | |
Vector | Subtract (Vector const &_fvec) const |
Performs vector subtraction with another vector and returns the result as a new vector. | |
Vector | Subtract (Real const &_scalar) const |
Performs scalar subtraction with a real value and returns the result as a new vector. | |
Vector | operator- (Vector const &_fvec) const |
Overloaded operator to perform vector subtraction. | |
Vector | operator- (Real const &_scalar) const |
Overloaded operator to perform scalar subtraction. | |
Vector | operator-- () const |
Overloaded prefix decrement operator to decrement all elements of the vector by one. | |
Vector | operator- () const |
Overload unary negation operator to negate the original vector, giving anti-parallel vector. | |
Real | Dot (Vector const &_fvec) const |
Calculates the dot product between this vector and another vector. | |
Vector | Cross (Vector const &_fvec) const |
Calculates the cross product between this vector and another vector. Both vectors must have three dimensions. | |
Real | ElemSum () const |
Calculates the sum of all elements in the vector. | |
Real | Magnitude () const |
Calculates the magnitude (Euclidean norm) of the vector. | |
Vector | Normalize () const |
Returns a new vector that is the normalized version of this vector. | |
Real | AngleWith (Vector const &_fvec) const |
Calculates the angle between this vector and another vector in radians. | |
bool | IsZero () |
Checks if the vector is a zero vector (all elements are zero). | |
bool | IsNormalized () |
Checks if the vector is a unit vector (normalized with a magnitude of 1). | |
bool | IsParallel (Vector const &_fvec) |
Checks if this vector is parallel to another vector. | |
bool | IsOrthogonal (Vector const &_fvec) |
Checks if this vector is orthogonal (perpendicular) to another vector. | |
Real | ParallelogramArea (Vector const &_fvec) const |
Calculates the area of the parallelogram spanned by this vector and another vector. | |
Real | TriangleArea (Vector const &_fvec) const |
Calculates the area of the triangle formed by this vector and another vector. | |
-Friends | |
std::ostream & | operator<< (std::ostream &os, Vector const &_fvec) |
Overloaded stream insertion operator to print the vector to an output stream. | |
Represents a mathematical vector in n-dimensional space.
-The Vector class provides various operations on vectors, such as addition, subtraction, scaling, dot product, cross product, normalization, angle calculation, and more.
-
-
|
- -delete | -
-
|
- -default | -
Firefly::Vector::Vector | -( | -std::size_t | -_size | ) | -- |
Constructs a vector of a specific size.
-_size | The size of the vector. |
Firefly::Vector::Vector | -( | -VectorType const & | -_vec | ) | -- |
Constructs a vector from a given VectorType (std::vector).
-_vec | The VectorType representing the vector. |
Firefly::Vector::Vector | -( | -Vector const & | -_fvec | ) | -- |
Copy constructor to create a new vector from an existing one.
-_f | The source vector to copy from. |
Performs scalar addition with a real value and returns the result as a new vector.
-_scalar | The scalar value to add. |
Performs vector addition with another vector and returns the result as a new vector.
-_fvec | The vector to add. |
Calculates the angle between this vector and another vector in radians.
-_fvec | The other vector to calculate the angle with. |
Real & Firefly::Vector::At | -( | -std::size_t | -idx | ) | -- |
Retrieves a reference to the value at a specific index in the vector.
-idx | The index of the element to retrieve. |
Real Firefly::Vector::At | -( | -std::size_t | -idx | ) | -const | -
Retrieves the value at a specific index in the vector (const version).
-idx | The index of the element to retrieve. |
Calculates the cross product between this vector and another vector. Both vectors must have three dimensions.
-_fvec | The other vector to calculate the cross product with. |
Calculates the dot product between this vector and another vector.
-_fvec | The other vector to calculate the dot product with. |
Real Firefly::Vector::ElemSum | -( | -) | -const | -
Calculates the sum of all elements in the vector.
-bool Firefly::Vector::IsNormalized | -( | -) | -- |
Checks if the vector is a unit vector (normalized with a magnitude of 1).
-bool Firefly::Vector::IsOrthogonal | -( | -Vector const & | -_fvec | ) | -- |
Checks if this vector is orthogonal (perpendicular) to another vector.
-Two vectors are considered orthogonal if their dot product is 0, indicating a 90-degree angle between them.
-_fvec | The other vector to check for orthogonality. |
bool Firefly::Vector::IsParallel | -( | -Vector const & | -_fvec | ) | -- |
Checks if this vector is parallel to another vector.
-Two vectors are considered parallel if their direction is the same or opposite. To determine parallelism, the function calculates the angle between the vectors and checks if it is either 0 degrees or 180 degrees (pi radians).
-_fvec | The other vector to check for parallelism. |
bool Firefly::Vector::IsZero | -( | -) | -- |
Checks if the vector is a zero vector (all elements are zero).
-Real Firefly::Vector::Magnitude | -( | -) | -const | -
Calculates the magnitude (Euclidean norm) of the vector.
-Vector Firefly::Vector::Normalize | -( | -) | -const | -
Returns a new vector that is the normalized version of this vector.
-Overloaded operator to perform vector scaling.
-_scalar | The scalar value to scale the vector by. |
Overloaded operator to perform scalar addition.
-_scalar | The scalar value to add. |
Overloaded operator to perform vector addition.
-_fvec | The vector to add. |
Vector Firefly::Vector::operator++ | -( | -) | -const | -
Overloaded prefix increment operator to increment all elements of the vector by one.
-Vector Firefly::Vector::operator- | -( | -) | -const | -
Overload unary negation operator to negate the original vector, giving anti-parallel vector.
-It negates all components of the vector, effectively reversing its direction while keeping its magnitude unchanged. The resulting vector points in the opposite direction of the original vector.
-For a 2D vector v = (x, y), the negation -v = (-x, -y). For a 3D vector v = (x, y, z), the negation -v = (-x, -y, -z).
-Overloaded operator to perform scalar subtraction.
-_scalar | The scalar value to subtract. |
Overloaded operator to perform vector subtraction.
-_fvec | The vector to subtract. |
Vector Firefly::Vector::operator-- | -( | -) | -const | -
Overloaded prefix decrement operator to decrement all elements of the vector by one.
-Real & Firefly::Vector::operator[] | -( | -std::size_t | -idx | ) | -- |
Overloaded subscript operator to access the value at a specific index.
-idx | The index of the element to retrieve. |
Real Firefly::Vector::operator[] | -( | -std::size_t | -idx | ) | -const | -
Overloaded subscript operator to access the value at a specific index (const version).
-idx | The index of the element to retrieve. |
Calculates the area of the parallelogram spanned by this vector and another vector.
-_fvec | The other vector forming the parallelogram. |
std::size_t Firefly::Vector::Rank | -( | -) | -const | -
Returns the rank (dimensionality) of the vector. It is same as Size() method.
-Performs vector scaling by a real value and returns the result as a new vector.
-_scalar | The scalar value to scale the vector by. |
std::size_t Firefly::Vector::Size | -( | -) | -const | -
Returns the size (number of elements) of the vector.
-Performs scalar subtraction with a real value and returns the result as a new vector.
-_scalar | The scalar value to subtract. |
Performs vector subtraction with another vector and returns the result as a new vector.
-_fvec | The vector to subtract. |
Calculates the area of the triangle formed by this vector and another vector.
-_fvec | The other vector forming the triangle. |
std::string Firefly::Vector::View | -( | -) | -const | -
Returns a string representation of the vector.
-
-
|
- -friend | -
Overloaded stream insertion operator to print the vector to an output stream.
-os | The output stream. |
_fvec | The vector to print. |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
#include "firefly/vector.hpp"
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
#include "firefly/vector.hpp"
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
This is the complete list of members for Firefly::Vector, including all inherited members.
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
#include "firefly/vector.hpp"
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
#include "firefly/vector.hpp"
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Macros | |
#define | __has_include(x) 0 |
#define | COMPILER_ID "" |
#define | STRINGIFY_HELPER(X) #X |
#define | STRINGIFY(X) STRINGIFY_HELPER(X) |
#define | PLATFORM_ID |
#define | ARCHITECTURE_ID |
#define | DEC(n) |
#define | HEX(n) |
#define | CXX_STD __cplusplus |
-Functions | |
int | main (int argc, char *argv[]) |
-Variables | |
char const * | info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]" |
char const * | info_platform = "INFO" ":" "platform[" PLATFORM_ID "]" |
char const * | info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]" |
const char * | info_language_standard_default |
const char * | info_language_extensions_default |
#define __has_include | -( | -- | x | ) | -0 | -
#define ARCHITECTURE_ID | -
#define COMPILER_ID "" | -
#define CXX_STD __cplusplus | -
#define DEC | -( | -- | n | ) | -- |
#define HEX | -( | -- | n | ) | -- |
#define PLATFORM_ID | -
#define STRINGIFY | -( | -- | X | ) | -STRINGIFY_HELPER(X) | -
#define STRINGIFY_HELPER | -( | -- | X | ) | -#X | -
int main | -( | -int | -argc, | -
- | - | char * | -argv[] | -
- | ) | -- |
char const* info_arch = "INFO" ":" "arch[" ARCHITECTURE_ID "]" | -
char const* info_compiler = "INFO" ":" "compiler[" COMPILER_ID "]" | -
const char* info_language_extensions_default | -
const char* info_language_standard_default | -
char const* info_platform = "INFO" ":" "platform[" PLATFORM_ID "]" | -
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Classes | |
class | Vector |
Represents a mathematical vector in n-dimensional space. More... | |
-Typedefs | |
using | VectorType = std::vector< Real > |
-Functions | |
std::ostream & | operator<< (std::ostream &os, Firefly::Vector const &_fvec) |
using Firefly::VectorType = typedef std::vector<Real> | -
std::ostream & Firefly::operator<< | -( | -std::ostream & | -os, | -
- | - | Firefly::Vector const & | -_fvec | -
- | ) | -- |
os | The output stream. |
_fvec | The vector to print. |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
#include <cstddef>
#include <memory>
#include <ostream>
#include <vector>
Go to the source code of this file.
--Classes | |
class | Firefly::Vector |
Represents a mathematical vector in n-dimensional space. More... | |
-Namespaces | |
namespace | Firefly |
-Typedefs | |
using | Real = float |
using | Firefly::VectorType = std::vector< Real > |
using Real = float | -
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
Represents a mathematical vector in n-dimensional space. - More...
- -#include <vector.hpp>
-Public Member Functions | |
Vector (Vector &&)=delete | |
Vector ()=delete | |
~Vector ()=default | |
Vector (std::size_t _size) | |
Constructs a vector of a specific size. | |
Vector (VectorType const &_vec) | |
Constructs a vector from a given VectorType (std::vector). | |
Vector (Vector const &_fvec) | |
Copy constructor to create a new vector from an existing one. | |
std::string | View () const |
Returns a string representation of the vector. | |
Real | At (std::size_t idx) const |
Retrieves the value at a specific index in the vector (const version). | |
Real & | At (std::size_t idx) |
Retrieves a reference to the value at a specific index in the vector. | |
Real | operator[] (std::size_t idx) const |
Overloaded subscript operator to access the value at a specific index (const version). | |
Real & | operator[] (std::size_t idx) |
Overloaded subscript operator to access the value at a specific index. | |
std::size_t | Size () const |
Returns the size (number of elements) of the vector. | |
std::size_t | Rank () const |
Returns the rank (dimensionality) of the vector. It is same as Size() method. | |
std::unique_ptr< Vector > | Add (Vector const &_fvec) const |
Performs vector addition with another vector and returns the result as a new vector. | |
std::unique_ptr< Vector > | Add (Real const &_scalar) const |
Performs scalar addition with a real value and returns the result as a new vector. | |
std::unique_ptr< Vector > | operator+ (Vector const &_fvec) const |
Overloaded operator to perform vector addition. | |
std::unique_ptr< Vector > | operator+ (Real const &_scalar) const |
Overloaded operator to perform scalar addition. | |
std::unique_ptr< Vector > | operator++ () const |
Overloaded prefix increment operator to increment all elements of the vector by one. | |
std::unique_ptr< Vector > | Scale (Real const &_fvec) const |
Performs vector scaling by a real value and returns the result as a new vector. | |
std::unique_ptr< Vector > | operator* (Real const &_scalar) const |
Overloaded operator to perform vector scaling. | |
std::unique_ptr< Vector > | Subtract (Vector const &_fvec) const |
Performs vector subtraction with another vector and returns the result as a new vector. | |
std::unique_ptr< Vector > | Subtract (Real const &_scalar) const |
Performs scalar subtraction with a real value and returns the result as a new vector. | |
std::unique_ptr< Vector > | operator- (Vector const &_fvec) const |
Overloaded operator to perform vector subtraction. | |
std::unique_ptr< Vector > | operator- (Real const &_scalar) const |
Overloaded operator to perform scalar subtraction. | |
std::unique_ptr< Vector > | operator-- () const |
Overloaded prefix decrement operator to decrement all elements of the vector by one. | |
Real | Dot (Vector const &_fvec) const |
Calculates the dot product between this vector and another vector. | |
std::unique_ptr< Vector > | Cross (Vector const &_fvec) const |
Calculates the cross product between this vector and another vector. Both vectors must have three dimensions. | |
Real | ElemSum () const |
Calculates the sum of all elements in the vector. | |
Real | Magnitude () const |
Calculates the magnitude (Euclidean norm) of the vector. | |
std::unique_ptr< Vector > | Normalize () const |
Returns a new vector that is the normalized version of this vector. | |
Real | AngleWith (Vector const &_fvec) const |
Calculates the angle between this vector and another vector in radians. | |
bool | IsZero () |
Checks if the vector is a zero vector (all elements are zero). | |
bool | IsNormalized () |
Checks if the vector is a unit vector (normalized with a magnitude of 1). | |
bool | IsParallel (Vector const &_fvec) |
Checks if this vector is parallel to another vector. | |
bool | IsOrthogonal (Vector const &_fvec) |
Checks if this vector is orthogonal (perpendicular) to another vector. | |
Real | ParallelogramArea (Vector const &_fvec) const |
Calculates the area of the parallelogram spanned by this vector and another vector. | |
Real | TriangleArea (Vector const &_fvec) const |
Calculates the area of the triangle formed by this vector and another vector. | |
-Friends | |
std::ostream & | operator<< (std::ostream &os, Vector const &_fvec) |
Overloaded stream insertion operator to print the vector to an output stream. | |
Represents a mathematical vector in n-dimensional space.
-The Vector class provides various operations on vectors, such as addition, subtraction, scaling, dot product, cross product, normalization, angle calculation, and more.
-
-
|
- -delete | -
-
|
- -delete | -
-
|
- -default | -
Firefly::Vector::Vector | -( | -std::size_t | -_size | ) | -- |
Constructs a vector of a specific size.
-_size | The size of the vector. |
Firefly::Vector::Vector | -( | -VectorType const & | -_vec | ) | -- |
Constructs a vector from a given VectorType (std::vector).
-_vec | The VectorType representing the vector. |
Firefly::Vector::Vector | -( | -Vector const & | -_fvec | ) | -- |
Copy constructor to create a new vector from an existing one.
-_f | The source vector to copy from. |
Performs scalar addition with a real value and returns the result as a new vector.
-_scalar | The scalar value to add. |
Performs vector addition with another vector and returns the result as a new vector.
-_fvec | The vector to add. |
Calculates the angle between this vector and another vector in radians.
-_fvec | The other vector to calculate the angle with. |
Real & Firefly::Vector::At | -( | -std::size_t | -idx | ) | -- |
Retrieves a reference to the value at a specific index in the vector.
-idx | The index of the element to retrieve. |
Real Firefly::Vector::At | -( | -std::size_t | -idx | ) | -const | -
Retrieves the value at a specific index in the vector (const version).
-idx | The index of the element to retrieve. |
Calculates the cross product between this vector and another vector. Both vectors must have three dimensions.
-_fvec | The other vector to calculate the cross product with. |
Calculates the dot product between this vector and another vector.
-_fvec | The other vector to calculate the dot product with. |
Real Firefly::Vector::ElemSum | -( | -) | -const | -
Calculates the sum of all elements in the vector.
-bool Firefly::Vector::IsNormalized | -( | -) | -- |
Checks if the vector is a unit vector (normalized with a magnitude of 1).
-bool Firefly::Vector::IsOrthogonal | -( | -Vector const & | -_fvec | ) | -- |
Checks if this vector is orthogonal (perpendicular) to another vector.
-Two vectors are considered orthogonal if their dot product is 0, indicating a 90-degree angle between them.
-_fvec | The other vector to check for orthogonality. |
bool Firefly::Vector::IsParallel | -( | -Vector const & | -_fvec | ) | -- |
Checks if this vector is parallel to another vector.
-Two vectors are considered parallel if their direction is the same or opposite. To determine parallelism, the function calculates the angle between the vectors and checks if it is either 0 degrees or 180 degrees (pi radians).
-_fvec | The other vector to check for parallelism. |
bool Firefly::Vector::IsZero | -( | -) | -- |
Checks if the vector is a zero vector (all elements are zero).
-Real Firefly::Vector::Magnitude | -( | -) | -const | -
Calculates the magnitude (Euclidean norm) of the vector.
-std::unique_ptr< Vector > Firefly::Vector::Normalize | -( | -) | -const | -
Returns a new vector that is the normalized version of this vector.
-std::unique_ptr< Vector > Firefly::Vector::operator* | -( | -Real const & | -_scalar | ) | -const | -
Overloaded operator to perform vector scaling.
-_scalar | The scalar value to scale the vector by. |
std::unique_ptr< Vector > Firefly::Vector::operator+ | -( | -Real const & | -_scalar | ) | -const | -
Overloaded operator to perform scalar addition.
-_scalar | The scalar value to add. |
std::unique_ptr< Vector > Firefly::Vector::operator+ | -( | -Vector const & | -_fvec | ) | -const | -
Overloaded operator to perform vector addition.
-_fvec | The vector to add. |
std::unique_ptr< Vector > Firefly::Vector::operator++ | -( | -) | -const | -
Overloaded prefix increment operator to increment all elements of the vector by one.
-std::unique_ptr< Vector > Firefly::Vector::operator- | -( | -Real const & | -_scalar | ) | -const | -
Overloaded operator to perform scalar subtraction.
-_scalar | The scalar value to subtract. |
std::unique_ptr< Vector > Firefly::Vector::operator- | -( | -Vector const & | -_fvec | ) | -const | -
Overloaded operator to perform vector subtraction.
-_fvec | The vector to subtract. |
std::unique_ptr< Vector > Firefly::Vector::operator-- | -( | -) | -const | -
Overloaded prefix decrement operator to decrement all elements of the vector by one.
-Real & Firefly::Vector::operator[] | -( | -std::size_t | -idx | ) | -- |
Overloaded subscript operator to access the value at a specific index.
-idx | The index of the element to retrieve. |
Real Firefly::Vector::operator[] | -( | -std::size_t | -idx | ) | -const | -
Overloaded subscript operator to access the value at a specific index (const version).
-idx | The index of the element to retrieve. |
Calculates the area of the parallelogram spanned by this vector and another vector.
-_fvec | The other vector forming the parallelogram. |
std::size_t Firefly::Vector::Rank | -( | -) | -const | -
Returns the rank (dimensionality) of the vector. It is same as Size() method.
-Performs vector scaling by a real value and returns the result as a new vector.
-_scalar | The scalar value to scale the vector by. |
std::size_t Firefly::Vector::Size | -( | -) | -const | -
Returns the size (number of elements) of the vector.
-std::unique_ptr< Vector > Firefly::Vector::Subtract | -( | -Real const & | -_scalar | ) | -const | -
Performs scalar subtraction with a real value and returns the result as a new vector.
-_scalar | The scalar value to subtract. |
std::unique_ptr< Vector > Firefly::Vector::Subtract | -( | -Vector const & | -_fvec | ) | -const | -
Performs vector subtraction with another vector and returns the result as a new vector.
-_fvec | The vector to subtract. |
Calculates the area of the triangle formed by this vector and another vector.
-_fvec | The other vector forming the triangle. |
std::string Firefly::Vector::View | -( | -) | -const | -
Returns a string representation of the vector.
-
-
|
- -friend | -
Overloaded stream insertion operator to print the vector to an output stream.
-os | The output stream. |
_fvec | The vector to print. |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
#include "firefly/vector.hpp"
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
#include "firefly/vector.hpp"
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
#include "firefly/vector.hpp"
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Namespaces | |
namespace | Firefly |
-Functions | |
std::ostream & | Firefly::operator<< (std::ostream &os, Firefly::Vector const &_fvec) |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
#include "firefly/vector.hpp"
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
#include "firefly/vector.hpp"
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Functions | |
int | main () |
int main | -( | -) | -- |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
#include <iostream>
#include <vector>
#include <cassert>
#include <firefly.hpp>
-Functions | |
int | main () |
int main | -( | -) | -- |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
File in examples | Includes file in headers |
---|---|
main.cpp | firefly / vector.hpp |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Files | |
add.cpp | |
angle_with.cpp | |
anti_parallel.cpp | |
area.cpp | |
cross.cpp | |
dot.cpp | |
elem_sum.cpp | |
indexers.cpp | |
is_normalized.cpp | |
is_orthogonal.cpp | |
is_parallel.cpp | |
is_zero.cpp | |
magnitude.cpp | |
normalize.cpp | |
rank.cpp | |
scale.cpp | |
subtract.cpp | |
vector.cpp | |
view.cpp | |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Directories | |
CMakeFiles | |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Files | |
test.cpp | |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Directories | |
vector | |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Files | |
vector.hpp | |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Directories | |
firefly | |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
▼ headers | |
▼ firefly | |
vector.hpp | |
▼ src | |
▼ vector | |
add.cpp | |
angle_with.cpp | |
anti_parallel.cpp | |
area.cpp | |
cross.cpp | |
dot.cpp | |
elem_sum.cpp | |
indexers.cpp | |
is_normalized.cpp | |
is_orthogonal.cpp | |
is_parallel.cpp | |
is_zero.cpp | |
magnitude.cpp | |
normalize.cpp | |
rank.cpp | |
scale.cpp | |
subtract.cpp | |
vector.cpp | |
view.cpp |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
This page explains how to interpret the graphs that are generated by doxygen.
-Consider the following example:
This will result in the following graph:
-The boxes in the above graph have the following meaning:
-The arrows have the following meaning:
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
#include "firefly/vector.hpp"
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
#include "firefly/vector.hpp"
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Namespaces | |
namespace | Firefly |
- Firefly 2.0
-
- Standalone library for vector and matrix calculations
- |
-
-Namespaces | |
namespace | Firefly |