added files

This commit is contained in:
Karl-Wilfried Zimmer 2024-07-07 17:17:26 +02:00
parent d72cda2619
commit c423a616f0
15 changed files with 231 additions and 10 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*build*/

8
.idea/.gitignore generated vendored Normal file
View File

@ -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

1
.idea/.name generated Normal file
View File

@ -0,0 +1 @@
vector

2
.idea/Vector.iml generated Normal file
View File

@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />

7
.idea/misc.xml generated Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
</component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>

8
.idea/modules.xml generated Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Vector.iml" filepath="$PROJECT_DIR$/.idea/Vector.iml" />
</modules>
</component>
</project>

6
.idea/vcs.xml generated Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

19
.kdev4/Vector.kdev4 Normal file
View File

@ -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

View File

@ -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)

3
apps/CMakeLists.txt Normal file
View File

@ -0,0 +1,3 @@
add_executable(app main.cpp)
target_link_libraries(app PRIVATE vector)

25
apps/main.cpp Normal file
View File

@ -0,0 +1,25 @@
#include <iostream>
#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<<vec<<std::endl;
std::cout<<vec.len()<<std::endl;
vec*=2;
std::cout<<vec<<std::endl;
std::cout<<vec.len()<<std::endl;
vec/=2;
std::cout<<vec<<std::endl;
std::cout<<vec.len()<<std::endl;
std::cout<<vec.dot(vec)<<std::endl;
std::cout<<vec.cross(vec2)<<std::endl;
vec.norm();
std::cout<<vec<<std::endl;
std::cout<<vec.len()<<std::endl;
vec-=vec;
std::cout<<vec<<std::endl;
std::cout<<vec.len()<<std::endl;
return 0;
}

65
include/Vector/vector3.h Normal file
View File

@ -0,0 +1,65 @@
//
// Created by nb on 07.07.24.
//
#ifndef VECTOR_VECTOR3_H
#define VECTOR_VECTOR3_H
#include "iostream"
#include <cmath>
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<<"{"<<v.x<<", "<<v.y<<", "<<v.z<<"}";
return os;
}
private:
double x,y,z;
};
}
#endif //VECTOR_VECTOR3_H

View File

@ -1,6 +0,0 @@
#include <iostream>
int main(int argc, char **argv) {
std::cout << "Hello, world!" << std::endl;
return 0;
}

10
src/CMakeLists.txt Normal file
View File

@ -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})

45
src/vector3.cpp Normal file
View File

@ -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;
}
}