Add some geometry and mesh.

This commit is contained in:
jmsgrogan 2022-08-03 21:05:01 +01:00
parent 1ee31596fb
commit 877d96462d
21 changed files with 126 additions and 33 deletions

View file

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

View file

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

View file

@ -0,0 +1,28 @@
#include "LineSegment.h"
LineSegment::LineSegment(PointPtr p0, PointPtr p1)
: mP0(p0),
mP1(p1)
{
}
std::shared_ptr<LineSegment> LineSegment::Create(PointPtr p0, PointPtr p1)
{
return std::make_shared<LineSegment>(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();
}

View file

@ -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<LineSegment> Create(PointPtr p0, PointPtr p1);
double getLength() const;
Point* getPoint0() const;
Point* getPoint1() const;
void Sample(Grid* grid) const
{
}
private:
PointPtr mP0;
PointPtr mP1;
};

View file

@ -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> Point::Create(double x, double y)
{
return std::make_shared<Point>(x, y);
return std::make_shared<Point>(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;
}

View file

@ -11,37 +11,24 @@ public:
~Point();
std::shared_ptr<Point> Create(double x, double y);
static std::shared_ptr<Point> 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<Point>;

0
src/geometry/Quad.cpp Normal file
View file

0
src/geometry/Quad.h Normal file
View file

View file

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

View file

0
src/mesh/AbstractMesh.h Normal file
View file

13
src/mesh/CMakeLists.txt Normal file
View file

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

0
src/mesh/Edge.cpp Normal file
View file

0
src/mesh/Edge.h Normal file
View file

0
src/mesh/Face.cpp Normal file
View file

0
src/mesh/Face.h Normal file
View file

0
src/mesh/QuadMesh.cpp Normal file
View file

0
src/mesh/QuadMesh.h Normal file
View file

0
src/mesh/TriMesh.cpp Normal file
View file

0
src/mesh/TriMesh.h Normal file
View file

View file

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