This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
C:. | |
| .gitignore | |
| CMakeLists.txt (1) | |
| LICENSE | |
| README.md | |
| | |
+---build (2) | |
+---cmake (3) | |
| FindCatch.cmake | |
| |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 3.1...3.13) | |
if(${CMAKE_VERSION} VERSION_LESS 3.12) | |
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}) | |
endif() | |
project(gravity VERSION 0.1.0 | |
DESCRIPTION "N-Body-Problem project of https://thoughts-on-cpp.com" | |
LANGUAGES CXX) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
add_library(solver | |
SHARED | |
src/solver.cpp) | |
target_include_directories(solver | |
PUBLIC | |
include) | |
add_executable(solverTest | |
test/test-main.cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mkdir build //(1) We need a build directory | |
cd build | |
cmake .. //(2) Generating the the artifacts to build, if necesarry download Catch2 via -DDOWNLOAD_CATCH=1 parameter | |
make //(3) Build the binaries on linux, for windows you might need different commands, e.g. msbuild gravity.sln for a visual studio based build | |
ctest //(4) Running tests |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyClass { | |
public: | |
int * getArray() const { | |
arr[0]++; | |
return arr; | |
} | |
void setFirstVal(int val) { arr[0] = val; } | |
private: | |
int * arr = new int[10]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Complex { | |
double real; | |
double imaginary; | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<class RandomIt, class Compare> | |
constexpr void sort(RandomIt first, RandomIt last, Compare comp); //constexpr since C++ 20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
std::vector<Complex> vec = { { 3, 1}, | |
{ 1, 9 }, | |
{ 8, 2 }, | |
{ 3, 14 }}; | |
double Complex::*var; | |
auto comparator = [&var](const Complex &a, const Complex &b) { return a.*var < b.*var; }; | |
var = &Complex::real; //Sorting for real numbers | |
std::sort(vec.begin(), vec.end(), comparator); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TEST_CASE( "Explicit euler algorithm with two point mass", "[euler]" ) { | |
Solver solver; | |
ParticleBuilder particleBuilder; | |
Particle particleA = particleBuilder | |
.position() | |
.mass() | |
.build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double Inverse(double value) { return -value; } | |
Particle GenerateStandardParticle(double xPosition, double yPosition) | |
{ | |
ParticleBuilder particleBuilder; | |
return particleBuilder | |
.position({xPosition, yPosition}) | |
.mass(1e10) | |
.build(); |
OlderNewer