diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bb11427..8831600 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -3,6 +3,7 @@ add_subdirectory(compression) add_subdirectory(database) add_subdirectory(network) add_subdirectory(geometry) +add_subdirectory(mesh) add_subdirectory(audio) add_subdirectory(fonts) add_subdirectory(image) @@ -14,4 +15,4 @@ add_subdirectory(video) add_subdirectory(windows) add_subdirectory(web) add_subdirectory(ui_elements) -add_subdirectory(visual_elements) \ No newline at end of file +add_subdirectory(visual_elements) diff --git a/src/geometry/CMakeLists.txt b/src/geometry/CMakeLists.txt index 7a509da..377a5d0 100644 --- a/src/geometry/CMakeLists.txt +++ b/src/geometry/CMakeLists.txt @@ -8,10 +8,12 @@ list(APPEND geometry_LIB_INCLUDES Grid.cpp Line.h Line.cpp + LineSegment.cpp Path.h Path.cpp Point.h Point.cpp + Quad.cpp Rectangle.h Rectangle.cpp Triangle.h @@ -22,4 +24,4 @@ list(APPEND geometry_LIB_INCLUDES add_library(geometry SHARED ${geometry_LIB_INCLUDES}) set_target_properties( geometry PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON ) -set_property(TARGET geometry PROPERTY FOLDER src) \ No newline at end of file +set_property(TARGET geometry PROPERTY FOLDER src) diff --git a/src/geometry/LineSegment.cpp b/src/geometry/LineSegment.cpp new file mode 100644 index 0000000..10b1e12 --- /dev/null +++ b/src/geometry/LineSegment.cpp @@ -0,0 +1,28 @@ +#include "LineSegment.h" + +LineSegment::LineSegment(PointPtr p0, PointPtr p1) + : mP0(p0), + mP1(p1) +{ + +} + +std::shared_ptr LineSegment::Create(PointPtr p0, PointPtr p1) +{ + return std::make_shared(p0, p1); +} + +double LineSegment::getLength() const +{ + return mP0->getDistance(mP1.get()); +} + +Point* LineSegment::getPoint0() const +{ + return mP0.get(); +} + +Point* LineSegment::getPoint1() const +{ + return mP1.get(); +} diff --git a/src/geometry/LineSegment.h b/src/geometry/LineSegment.h new file mode 100644 index 0000000..3c14ba9 --- /dev/null +++ b/src/geometry/LineSegment.h @@ -0,0 +1,27 @@ +#pragma once + +#include "AbstractGeometricItem.h" +#include "Point.h" + +class LineSegment : public AbstractGeometricItem +{ +public: + LineSegment(PointPtr p0, PointPtr p1); + + static std::shared_ptr Create(PointPtr p0, PointPtr p1); + + double getLength() const; + + Point* getPoint0() const; + + Point* getPoint1() const; + + void Sample(Grid* grid) const + { + + } + +private: + PointPtr mP0; + PointPtr mP1; +}; diff --git a/src/geometry/Point.cpp b/src/geometry/Point.cpp index e4b5541..fc8e9db 100644 --- a/src/geometry/Point.cpp +++ b/src/geometry/Point.cpp @@ -1,9 +1,8 @@ #include "Point.h" - Point::Point(double x, double y) - : mX(x), - mY(y) + : mX(x), + mY(y) { } @@ -11,8 +10,37 @@ Point::~Point() { }; - std::shared_ptr Point::Create(double x, double y) { - return std::make_shared(x, y); + return std::make_shared(x, y); +} + +double Point::getX() const +{ + return mX; +} + +double Point::getY() const +{ + return mY; +} + +double Point::getDistance(const Point& point) const +{ + return std::sqrt(mX*point.getX() + mY*point.getY()); +} + +double Point::getDistance(Point* point) const +{ + return std::sqrt(mX*point->getX() + mY*point->getY()); +} + +double Point::getDeltaX(const Point& point) const +{ + return point.getX() - mX; +} + +double Point::getDeltaY(const Point& point) const +{ + return point.getY() - mY; } diff --git a/src/geometry/Point.h b/src/geometry/Point.h index 8eaf359..335cfcc 100644 --- a/src/geometry/Point.h +++ b/src/geometry/Point.h @@ -11,37 +11,24 @@ public: ~Point(); - std::shared_ptr Create(double x, double y); + static std::shared_ptr Create(double x, double y); - double GetX() const - { - return mX; - } + double getX() const; - double GetY() const - { - return mY; - } + double getY() const; - double GetDistance(const Point& point) const - { - return std::sqrt(mX*point.GetX() + mY*point.GetY()); - } + double getDistance(const Point& point) const; - double GetDeltaX(const Point& point) const - { - return point.GetX() - mX; - } + double getDistance(Point* point) const; - double GetDeltaY(const Point& point) const - { - return point.GetY() - mY; - } + double getDeltaX(const Point& point) const; + + double getDeltaY(const Point& point) const; private: - - double mX; - double mY; + double mX{0}; + double mY{0}; + double mZ{0}; }; using PointPtr = std::shared_ptr; diff --git a/src/geometry/Quad.cpp b/src/geometry/Quad.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/geometry/Quad.h b/src/geometry/Quad.h new file mode 100644 index 0000000..e69de29 diff --git a/src/geometry/Rectangle.h b/src/geometry/Rectangle.h index ae7fee4..ea7c469 100644 --- a/src/geometry/Rectangle.h +++ b/src/geometry/Rectangle.h @@ -26,12 +26,12 @@ public: double GetHeight() const { - return mBottomLeft.GetDeltaY(mTopRight); + return mBottomLeft.getDeltaY(mTopRight); } double GetWidth() const { - return mBottomLeft.GetDeltaX(mTopRight); + return mBottomLeft.getDeltaX(mTopRight); } private: diff --git a/src/mesh/AbstractMesh.cpp b/src/mesh/AbstractMesh.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/mesh/AbstractMesh.h b/src/mesh/AbstractMesh.h new file mode 100644 index 0000000..e69de29 diff --git a/src/mesh/CMakeLists.txt b/src/mesh/CMakeLists.txt new file mode 100644 index 0000000..e6c73f7 --- /dev/null +++ b/src/mesh/CMakeLists.txt @@ -0,0 +1,13 @@ +list(APPEND mesh_LIB_INCLUDES + AbstractMesh.cpp + Edge.cpp + Face.cpp + QuadMesh.cpp + TriMesh.cpp) + + +# add the library +add_library(mesh SHARED ${mesh_LIB_INCLUDES}) + +set_target_properties( mesh PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON ) +set_property(TARGET mesh PROPERTY FOLDER src) diff --git a/src/mesh/Edge.cpp b/src/mesh/Edge.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/mesh/Edge.h b/src/mesh/Edge.h new file mode 100644 index 0000000..e69de29 diff --git a/src/mesh/Face.cpp b/src/mesh/Face.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/mesh/Face.h b/src/mesh/Face.h new file mode 100644 index 0000000..e69de29 diff --git a/src/mesh/QuadMesh.cpp b/src/mesh/QuadMesh.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/mesh/QuadMesh.h b/src/mesh/QuadMesh.h new file mode 100644 index 0000000..e69de29 diff --git a/src/mesh/TriMesh.cpp b/src/mesh/TriMesh.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/mesh/TriMesh.h b/src/mesh/TriMesh.h new file mode 100644 index 0000000..e69de29 diff --git a/test/graphics/TestRasterizer.cpp b/test/graphics/TestRasterizer.cpp index 0f33f99..91fd4d7 100644 --- a/test/graphics/TestRasterizer.cpp +++ b/test/graphics/TestRasterizer.cpp @@ -5,9 +5,16 @@ #include "DrawingContext.h" #include "Grid.h" #include "Rasterizer.h" +#include "LineSegment.h" +#include "Point.h" int main() { DrawingManager manager; + manager.InitalizeSurface(200, 200); + manager.InitializeContext(); + + auto line = LineSegment::Create(Point::Create(10.0, 10.0), Point::Create(190.0, 190.0)); + return 0; }