diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..468d90c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*build*/ diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..e2e962e --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +vector \ No newline at end of file diff --git a/.idea/Vector.iml b/.idea/Vector.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/Vector.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0b76fe5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..e689a51 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.kdev4/Vector.kdev4 b/.kdev4/Vector.kdev4 new file mode 100644 index 0000000..e022c60 --- /dev/null +++ b/.kdev4/Vector.kdev4 @@ -0,0 +1,19 @@ +[Buildset] +BuildItems=@Variant(\x00\x00\x00\t\x00\x00\x00\x00\x01\x00\x00\x00\x0b\x00\x00\x00\x00\x01\x00\x00\x00\x0c\x00V\x00e\x00c\x00t\x00o\x00r) + +[CMake] +Build Directory Count=1 +Current Build Directory Index-Host-System=0 + +[CMake][CMake Build Directory 0] +Build Directory Path=/home/nb/projects/Vector/build +Build Type=Debug +CMake Binary=/usr/bin/cmake +CMake Executable=/usr/bin/cmake +Environment Profile= +Extra Arguments= +Install Directory=/usr/local +Runtime=Host-System + +[Project] +VersionControlSupport=kdevgit diff --git a/CMakeLists.txt b/CMakeLists.txt index ad0d5bf..036e57d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,34 @@ -cmake_minimum_required(VERSION 3.0) +cmake_minimum_required(VERSION 3.15..3.30) -project(vector) +project(vector + VERSION 0.1 + LANGUAGES CXX) -add_executable(vector main.cpp) +if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME) + set_property(GLOBAL PROPERTY USE_FOLDERDS ON) + find_package(Doxygen) + if(Doxygen_FOUND) + #add_subdirectory(docs) + else() + message(STATUS "Doxygen not found, not building docs") + endif() -install(TARGETS vector RUNTIME DESTINATION bin) + add_subdirectory(apps/) + +endif() + +include(FetchContent) + +# Formatting library, adds fmt::fmt Always use the full git hash, not the tag, +# safer and faster to recompile +#FetchContent_Declare( +# fmtlib +# GIT_REPOSITORY https://github.com/fmtlib/fmt.git +# GIT_TAG 8.0.1) +#FetchContent_MakeAvailable(fmtlib) + +add_subdirectory(${PROJECT_SOURCE_DIR}/src) + +#add_executable(vector main.cpp) + +#install(TARGETS vector RUNTIME DESTINATION bin) diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt new file mode 100644 index 0000000..5945e25 --- /dev/null +++ b/apps/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(app main.cpp) + +target_link_libraries(app PRIVATE vector) diff --git a/apps/main.cpp b/apps/main.cpp new file mode 100644 index 0000000..4512149 --- /dev/null +++ b/apps/main.cpp @@ -0,0 +1,25 @@ +#include +#include "Vector/vector3.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 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<<"{"< - -int main(int argc, char **argv) { - std::cout << "Hello, world!" << std::endl; - return 0; -} diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..b70a2f6 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,10 @@ +file(GLOB HEADER_LIST CONFIGURE_DEPENDS "${ModernCMakeExample_SOURCE_DIR}/include/Vector/*.hpp") + +add_library(vector vector3.cpp ${HEADER_LIST}) + +target_include_directories(vector PUBLIC "../include") + +source_group( + TREE "${PROJECT_SOURCE_DIR}/include" + PREFIX "Header files" + FILES ${HEADER_LIST}) diff --git a/src/vector3.cpp b/src/vector3.cpp new file mode 100644 index 0000000..7b7b7b1 --- /dev/null +++ b/src/vector3.cpp @@ -0,0 +1,45 @@ +#include "Vector/vector3.h" + +namespace Vector{ + Vector3 Vector3::operator+(const Vector::Vector3 &v) const { + return {x+v.x,y+v.y,z+v.z}; + } + + Vector3& Vector3::operator=(const Vector::Vector3 &v) = default; + + Vector3& Vector3::operator+=(const Vector::Vector3 &v) { + *this=*this+v; + return *this; + } + + double Vector3::dot(const Vector::Vector3 &v) const { + return x*v.x+y*v.y+z*v.z; + } + + Vector3 Vector3::cross(const Vector::Vector3& v) const { + return {y*v.z-v.y*z,z*v.x-v.z*x,x*v.y-v.x*y}; + } + + double Vector3::len() const { + return std::sqrt(x*x+y*y+z*z); + } + + Vector3 Vector3::operator*(double s) const { + return {x*s, y*s, z*s}; + } + + Vector3& Vector3::operator*=(double s) { + *this=*this*s; + return *this; + } + + Vector3 &Vector3::operator-=(const Vector::Vector3 &v) { + *this=*this-v; + return *this; + } + + Vector3 &Vector3::norm() { + *this=*this/=this->len(); + return *this; + } +} \ No newline at end of file