From aa02ff3faa4b17dcdd3051091958b85fde351de8 Mon Sep 17 00:00:00 2001 From: Karl-Wilfried Zimmer Date: Sun, 7 Jul 2024 20:42:39 +0200 Subject: [PATCH] added vector3 to project --- .idea/vcs.xml | 7 +++++ CMakeLists.txt | 10 +++---- apps/CMakeLists.txt | 2 +- apps/main.cpp | 21 ++----------- include/Block/block.h | 10 +++++-- include/Vector/vector3.h | 65 ++++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 7 +++-- src/block.cpp | 2 +- src/vector3.cpp | 45 ++++++++++++++++++++++++++++ 9 files changed, 138 insertions(+), 31 deletions(-) create mode 100644 .idea/vcs.xml create mode 100644 include/Vector/vector3.h create mode 100644 src/vector3.cpp diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..e014f95 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 31a8c80..666fc8c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,11 +21,11 @@ include(FetchContent) # Formatting library, adds fmt::fmt Always use the full git hash, not the tag, # safer and faster to recompile -FetchContent_Declare( - vector - GIT_REPOSITORY https://concreteserver.ddns.net/gitea/CarboHydra/Vector.git - GIT_TAG main) -FetchContent_MakeAvailable(vector) +#FetchContent_Declare( +# vector +# GIT_REPOSITORY https://concreteserver.ddns.net/gitea/CarboHydra/Vector.git +# GIT_TAG main) +#FetchContent_MakeAvailable(vector) add_subdirectory(${PROJECT_SOURCE_DIR}/src) diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 5945e25..e277ec2 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -1,3 +1,3 @@ add_executable(app main.cpp) -target_link_libraries(app PRIVATE vector) +target_link_libraries(app PRIVATE block vector) diff --git a/apps/main.cpp b/apps/main.cpp index 4512149..90111fa 100644 --- a/apps/main.cpp +++ b/apps/main.cpp @@ -1,25 +1,8 @@ #include -#include "Vector/vector3.h" +#include "Block/block.h" int main(int argc, char **argv) { std::cout << "Hello, world!" << std::endl; - Vector::Vector3 vec(1,2,3); - Vector::Vector3 vec2(2,1,3); - std::cout< +namespace Volumes{ + class Block{ + public: + virtual ~Block() = default; + + private: + Vector::Vector3 corners[8]; }; } diff --git a/include/Vector/vector3.h b/include/Vector/vector3.h new file mode 100644 index 0000000..4484d62 --- /dev/null +++ b/include/Vector/vector3.h @@ -0,0 +1,65 @@ +// +// Created by nb on 07.07.24. +// + +#ifndef VECTOR_VECTOR3_H +#define VECTOR_VECTOR3_H + +#include "iostream" +#include + +namespace Vector{ + class Vector3{ + public: + Vector3(double x,double y, double z):x(x),y(y),z(z){}; + Vector3(): Vector3(0,0,0){}; + + virtual ~Vector3() = default; + + Vector3 operator+(const Vector3& v) const; + + Vector3 operator-(const Vector3& v) const{ + Vector3 tmp=v*-1; + return *this+tmp; + }; + + Vector3 operator*(double s) const; + + Vector3 operator/(double s) const{ + return *this*(1/s); + }; + + Vector3& operator*=(double s); + + Vector3& operator/=(double s){ + return *this*=(1/s); + }; + + Vector3& operator+=(const Vector3& v); + + Vector3& operator-=(const Vector3& v); + + Vector3& operator=(const Vector3& v); + + + + Vector3& norm(); + + double dot(const Vector3& v) const; + + double len() const; + + Vector3 cross(const Vector3& v) const; + + friend std::ostream& operator<<(std::ostream& os, const Vector3& v){ + os<<"{"<len(); + return *this; + } +} \ No newline at end of file