initial commit

This commit is contained in:
L-Nafaryus 2022-09-22 20:43:06 +05:00
commit 45636e5662
35 changed files with 764 additions and 0 deletions

10
.dir-locals.el Normal file
View File

@ -0,0 +1,10 @@
((nil . (
(projectile-project-name . "hyporo")
(projectile-project-compilation-dir . "")
(projectile-enable-caching . t)
(projectile-project-configure-cmd . "cmake -S . -B build -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=DEBUG")
(projectile-project-compilation-cmd . "cmake --build build ")
(projectile-project-test-cmd . "ctest --test-dir build")
(projectile-project-run-cmd . "cd build/source/creator && ./hyporo")
(cmake-ide-build-dir . "build")
)))

6
.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
cmake-build-debug/
.idea/
build/
.ccls-cache/
compile_commands.json
.cache/

69
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,69 @@
{
"files.associations": {
"any": "cpp",
"array": "cpp",
"atomic": "cpp",
"bit": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"chrono": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"compare": "cpp",
"concepts": "cpp",
"condition_variable": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"map": "cpp",
"set": "cpp",
"string": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"numbers": "cpp",
"ostream": "cpp",
"semaphore": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"stop_token": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp",
"variant": "cpp"
}
}

23
CMakeLists.txt Normal file
View File

@ -0,0 +1,23 @@
cmake_minimum_required (VERSION 3.16)
project(
hyporo
VERSION 0.20.0
LANGUAGES CXX
)
option(WITH_GTESTS "Enable GTest unit testing" ON)
enable_testing()
if(WITH_GTESTS)
include(${CMAKE_SOURCE_DIR}/cmake/googletest.cmake)
include(GoogleTest)
endif()
add_definitions(-DPRECISION_FLOAT)
add_subdirectory(source)

0
README.md Normal file
View File

23
cmake/CPM.cmake Normal file
View File

@ -0,0 +1,23 @@
set(CPM_DOWNLOAD_VERSION 0.35.1)
if(CPM_SOURCE_CACHE)
# Expand relative path. This is important if the provided path contains a tilde (~)
get_filename_component(CPM_SOURCE_CACHE ${CPM_SOURCE_CACHE} ABSOLUTE)
set(CPM_DOWNLOAD_LOCATION "${CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
elseif(DEFINED ENV{CPM_SOURCE_CACHE})
set(CPM_DOWNLOAD_LOCATION "$ENV{CPM_SOURCE_CACHE}/cpm/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
else()
set(CPM_DOWNLOAD_LOCATION "${CMAKE_BINARY_DIR}/cmake/CPM_${CPM_DOWNLOAD_VERSION}.cmake")
endif()
if(NOT (EXISTS ${CPM_DOWNLOAD_LOCATION}))
message(STATUS "Downloading CPM.cmake to ${CPM_DOWNLOAD_LOCATION}")
file(DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v${CPM_DOWNLOAD_VERSION}/CPM.cmake
${CPM_DOWNLOAD_LOCATION}
)
endif()
include(${CPM_DOWNLOAD_LOCATION})

7
cmake/googletest.cmake Normal file
View File

@ -0,0 +1,7 @@
include(${CMAKE_CURRENT_LIST_DIR}/CPM.cmake)
CPMAddPackage(
NAME googletest
GIT_REPOSITORY https://github.com/google/googletest.git
GIT_TAG release-1.12.1
)

2
source/CMakeLists.txt Normal file
View File

@ -0,0 +1,2 @@
add_subdirectory(hyporo)
add_subdirectory(creator)

View File

@ -0,0 +1,17 @@
include_directories(
../hyporo/hyplib/vector
../hyporo/hyplib/scalar
../hyporo/hyplib/integer
../hyporo/hyplib/matrix
)
add_executable(hyporo
# Source files
creator.cpp
)
target_link_libraries(hyporo
PUBLIC
hyporo-hyplib)

View File

@ -0,0 +1,22 @@
#include "scalar.hpp"
#include "vector.hpp"
#include <algorithm>
#include <iostream>
#include "matrix.hpp"
int main(void)
{
hyporo::vec3 v1 {1, 3, 2};
hyporo::vec3 v2 {7, 4, 5};
std::cout << -v1 << std::endl;
std::cout << ((v1 + v2) == hyporo::vec3(8, 7, 7)) << std::endl;
std::cout << v1 - v2 << std::endl;
std::cout << v1 * 2 << std::endl;
std::cout << v1 / 2 << std::endl;
std::cout << (v1 == v2) << std::endl;
std::cout << (v1 == v1) << std::endl;
hyporo::mat3 m1 {1, 3, 2, 5, 3, 6, 7, 2, 0};
hyporo::mat3 m2 {7, 4, 5, 5, 7, 3, 1, 4, 6};
std::cout << m1 + m2 << std::endl;
return 0;
}

View File

@ -0,0 +1,6 @@
add_subdirectory(csg)
add_subdirectory(gpu)
add_subdirectory(hmesh)
add_subdirectory(hyplib)
add_subdirectory(io)
add_subdirectory(windowmanager)

View File

View File

View File

@ -0,0 +1,32 @@
include_directories(
.
../hyplib/integer
../hyplib/scalar
../hyplib/vector
)
add_library(hyporo-hmesh STATIC
# Header files
Vertex.hpp
Edge.hpp
Face.hpp
Cell.hpp
Mesh.hpp
# Source files
Mesh.cpp
)
if(WITH_GTESTS)
add_executable(hyporo-hmesh-test
tests/hmesh-test.cpp
)
target_link_libraries(hyporo-hmesh-test
GTest::gtest_main
)
gtest_add_tests(TARGET hyporo-hmesh-test)
endif()

View File

@ -0,0 +1,9 @@
#pragma once
#include "Face.hpp"
namespace hyporo
{
} // end namespace hyporo

View File

@ -0,0 +1,9 @@
#pragma once
#include "Vertex.hpp"
namespace hyporo
{
} // end namespace hyporo

View File

@ -0,0 +1,9 @@
#pragma once
#include "Edge.hpp"
namespace hyporo
{
} // end namespace hyporo

View File

View File

@ -0,0 +1,31 @@
#pragma once
#include "Cell.hpp"
namespace hyporo
{
class Mesh
{
mutable list<shared_ptr<Vertex>> vertices_;
mutable list<shared_ptr<Edge>> edges_;
mutable list<shared_ptr<Face>> faces_;
mutable list<shared_ptr<Cell>> cells_;
public:
// Constructors
//- Desctuctor
virtual ~Mesh();
// Mesh size parameters
inline sizet nPoints() const;
inline sizet nEdges() const;
inline sizet nFaces() const;
inline sizet nCells() const;
};
} // end namespace hyporo

View File

@ -0,0 +1,47 @@
#pragma once
#include "vector.hpp"
#include <memory>
#include <vector>
namespace hyporo
{
template <class T>
using list = std::vector<T>;
using std::shared_ptr;
using std::weak_ptr;
// Forward declaration
class Edge;
class Mesh;
// Class declaration
class Vertex : public VectorSpace<scalar, 3>
{
//- List of weak pointers to edges that use this vertex
mutable list<weak_ptr<Edge>> edges_;
public:
// Constructors
inline Vertex(Mesh& mesh, const scalar& x, const scalar& y, const scalar& z);
// Member functions
inline const scalar& x() const;
inline const scalar& y() const;
inline const scalar& z() const;
};
} // end namespace hyporo
#include "Vertex.hxx"

View File

@ -0,0 +1,27 @@
namespace hyporo
{
Vertex::Point(const scalar& x, const scalar& y, const scalar& z)
{
row[0] = x;
row[1] = y;
row[2] = z;
}
const scalar& Vertex::x() const
{
return row[0];
}
const scalar& Vertex::y() const;
{
return row[1];
}
const scalar& Vertex::z() const;
{
return row[2];
}
} // end namespace hyporo

View File

@ -0,0 +1,6 @@
#include <gtest/gtest.h>
#include "Mesh.hpp"
TEST(hmeshTest, MeshCreation)
{
}

View File

@ -0,0 +1,33 @@
include_directories(
integer
scalar
vector
matrix
)
add_library(hyporo-hyplib STATIC
# Header files
integer/integer.hpp
scalar/scalar.hpp
vector/VectorSpace.hpp
vector/vector.hpp
matrix/MatrixSpace.hpp
matrix/matrix.hpp
# Source files
scalar/scalar.cpp
)
if(WITH_GTESTS)
add_executable(hyporo-hyplib-test
tests/hyplib-test.cpp
)
target_link_libraries(hyporo-hyplib-test
GTest::gtest_main
)
gtest_add_tests(TARGET hyporo-hyplib-test)
endif()

View File

@ -0,0 +1,12 @@
#include <cstddef>
namespace hyporo
{
using uint = unsigned int;
using sizet = std::size_t;
} // end namespace hyporo

View File

@ -0,0 +1,33 @@
#include "VectorSpace.hpp"
namespace hyporo
{
template <class C, sizet Mrows, sizet Ncols>
class MatrixSpace : public VectorSpace<C, Mrows * Ncols>
{
public:
// Member constants
static const sizet mRows = Mrows;
static const sizet nColumns = Ncols;
// Constructors
inline MatrixSpace();
template <class... Args>
inline MatrixSpace(const Args... components);
// Member operators
inline const C& operator()(const sizet& n, const sizet& m);
};
} // end namespace hyporo
#include "MatrixSpace.hxx"

View File

@ -0,0 +1,27 @@
namespace hyporo
{
// Constructors
template <class C, sizet Mrows, sizet Ncols>
inline MatrixSpace<C, Mrows, Ncols>::MatrixSpace()
{}
template <class C, sizet Mrows, sizet Ncols>
template <class... Args>
inline MatrixSpace<C, Mrows, Ncols>::MatrixSpace(const Args... components)
//: row { static_cast<C>(components)... }
{
this->row = { static_cast<C>(components)... };
}
// Member operators
template <class C, sizet Mrows, sizet Ncols>
inline const C& MatrixSpace<C, Mrows, Ncols>::operator()(const sizet& n, const sizet& m)
{
return this->row[n * Ncols + m];
}
} // end namespace hyporo

View File

@ -0,0 +1,11 @@
#include "MatrixSpace.hpp"
namespace hyporo
{
using mat3 = MatrixSpace<scalar, 3, 3>;
using mat4 = MatrixSpace<scalar, 4, 4>;
} // end namespace hyporo

View File

@ -0,0 +1,3 @@
#include "scalar.hpp"

View File

@ -0,0 +1,47 @@
#pragma once
#include <cmath>
#include <limits>
namespace hyporo
{
#if defined(PRECISION_FLOAT)
using scalar = float;
#elif defined(PRECISION_DOUBLE)
using scalar = double;
#elif defined(PRECISION_LONGDOUBLE)
using scalar = long double;
#else
using scalar = float;
#endif
static const scalar small = std::numeric_limits<scalar>::epsilon();
static const scalar great = 1.0 / small;
static const scalar valueSmall = std::numeric_limits<scalar>::min();
static const scalar valueGreat = std::numeric_limits<scalar>::max() * 0.1;
static const scalar NaN = std::numeric_limits<scalar>::signaling_NaN();
//- Return 1 if s is positive or 0 otherwise -1
inline int sign(const scalar s)
{
return (s >= 0) ? 1: -1;
}
inline scalar mag(const scalar s)
{
return std::fabs(s);
}
} // end namespace hyporo

View File

@ -0,0 +1,20 @@
#include <gtest/gtest.h>
#include "vector.hpp"
TEST(hyplibTest, VectorCreation)
{
hyporo::vec3 v {1, 3, 2};
EXPECT_EQ(v[0], 1);
EXPECT_EQ(v[1], 3);
EXPECT_EQ(v[2], 2);
}
TEST(hyplibTest, VectorOperations)
{
using hyporo::vec3;
vec3 v1 {1, 3, 2};
vec3 v2 {5, 7, -1};
EXPECT_EQ(-v1, vec3(-1, -3, -2));
EXPECT_EQ(v1 + v2, vec3(6, 10, 1));
EXPECT_EQ(v1 - v2, vec3(-4, -4, 3));
}

View File

@ -0,0 +1,66 @@
#pragma once
/** \file
* \ingroup hyplib
**/
#include "integer.hpp"
#include "scalar.hpp"
#include <array>
#include <ostream>
namespace hyporo
{
// Forward declaration of friend functions and operators
template <class C, sizet NC> class VectorSpace;
template <class C, sizet NC>
std::ostream& operator<<(std::ostream&, const VectorSpace<C, NC>&);
// Class declaration
template <class C, sizet NC>
class VectorSpace
{
public:
//- The components of this vector space
std::array<C, NC> row;
// Static constants
static const sizet nComponents = NC;
// Constructors
inline VectorSpace();
//inline VectorSpace(const VectorSpace<C, NC>&);
template <class... Args>
inline VectorSpace(const Args... components);
// Member functions
inline static sizet size();
// Member operators
inline C& operator[](const sizet);
inline VectorSpace<C, NC>& operator*=(const scalar);
inline VectorSpace<C, NC>& operator/=(const scalar);
// Friend operators
friend std::ostream& operator<< <C, NC>(std::ostream&, const VectorSpace<C, NC>&);
};
} // end namespace hyporo
#include "VectorSpace.hxx"

View File

@ -0,0 +1,143 @@
#include <algorithm>
namespace hyporo
{
// Constructors
template <class C, sizet NC>
inline VectorSpace<C, NC>::VectorSpace()
{}
template <class C, sizet NC>
template <class... Args>
inline VectorSpace<C, NC>::VectorSpace(const Args... components)
: row { static_cast<C>(components)... }
{}
// Member functions
template <class C, sizet NC>
inline sizet VectorSpace<C, NC>::size()
{
return NC;
}
// Member operators
template <class C, sizet NC>
inline C& VectorSpace<C, NC>::operator[](const sizet n)
{
return row[n];
}
template <class C, sizet NC>
inline VectorSpace<C, NC>& VectorSpace<C, NC>::operator*=(const scalar s)
{
for (C& v : row)
v *= s;
return *this;
}
template <class C, sizet NC>
inline VectorSpace<C, NC>& VectorSpace<C, NC>::operator/=(const scalar s)
{
for (C& v : row)
v /= s;
return *this;
}
// Friend operators
template <class C, sizet NC>
std::ostream& operator<<(std::ostream& os, const VectorSpace<C, NC>& vs)
{
os << "(";
for (sizet n = 0; n < NC; n++)
{
os << vs.row[n];
if (n != NC - 1)
os << ", ";
}
os << ")";
return os;
}
// Global operators
template <class C, sizet NC>
inline VectorSpace<C, NC> operator-(const VectorSpace<C, NC>& vs)
{
VectorSpace<C, NC> nvs;
for (sizet n = 0; n < NC; n++)
nvs.row[n] = -vs.row[n];
return nvs;
}
template <class C, sizet NC>
inline VectorSpace<C, NC> operator+(const VectorSpace<C, NC>& vs1, const VectorSpace<C, NC>& vs2)
{
VectorSpace<C, NC> nvs;
for (sizet n = 0; n < NC; n++)
nvs.row[n] = vs1.row[n] + vs2.row[n];
return nvs;
}
template <class C, sizet NC>
inline VectorSpace<C, NC> operator-(const VectorSpace<C, NC>& vs1, const VectorSpace<C, NC>& vs2)
{
VectorSpace<C, NC> nvs;
for (sizet n = 0; n < NC; n++)
nvs.row[n] = vs1.row[n] - vs2.row[n];
return nvs;
}
template <class C, sizet NC>
inline VectorSpace<C, NC> operator*(const scalar& s, const VectorSpace<C, NC>& vs)
{
VectorSpace<C, NC> nvs;
for (sizet n = 0; n < NC; n++)
nvs.row[n] = s * vs.row[n];
return nvs;
}
template <class C, sizet NC>
inline VectorSpace<C, NC> operator*(const VectorSpace<C, NC>& vs, const scalar& s)
{
VectorSpace<C, NC> nvs;
for (sizet n = 0; n < NC; n++)
nvs.row[n] = vs.row[n] * s;
return nvs;
}
template <class C, sizet NC>
inline VectorSpace<C, NC> operator/(const VectorSpace<C, NC>& vs, const scalar& s)
{
VectorSpace<C, NC> nvs;
for (sizet n = 0; n < NC; n++)
nvs.row[n] = vs.row[n] / s;
return nvs;
}
template <class C, sizet NC>
inline bool operator==(const VectorSpace<C, NC>& vs1, const VectorSpace<C, NC>& vs2)
{
bool eq = true;
for (sizet n = 0; n < NC; n++)
if (!(eq &= (vs1.row[n] == vs2.row[n])))
break;
return eq;
}
template <class C, sizet NC>
inline bool operator!=(const VectorSpace<C, NC>& vs1, const VectorSpace<C, NC>& vs2)
{
return !(vs1 == vs2);
}
} // end namespace hyporo

View File

@ -0,0 +1,14 @@
#include "scalar.hpp"
#include "VectorSpace.hpp"
namespace hyporo
{
using vec2 = VectorSpace<scalar, 2>;
using vec3 = VectorSpace<scalar, 3>;
using vec4 = VectorSpace<scalar, 4>;
} // end namespace hyporo

View File