Add some geometry and mesh.
This commit is contained in:
parent
1ee31596fb
commit
877d96462d
21 changed files with 126 additions and 33 deletions
|
@ -3,6 +3,7 @@ add_subdirectory(compression)
|
||||||
add_subdirectory(database)
|
add_subdirectory(database)
|
||||||
add_subdirectory(network)
|
add_subdirectory(network)
|
||||||
add_subdirectory(geometry)
|
add_subdirectory(geometry)
|
||||||
|
add_subdirectory(mesh)
|
||||||
add_subdirectory(audio)
|
add_subdirectory(audio)
|
||||||
add_subdirectory(fonts)
|
add_subdirectory(fonts)
|
||||||
add_subdirectory(image)
|
add_subdirectory(image)
|
||||||
|
|
|
@ -8,10 +8,12 @@ list(APPEND geometry_LIB_INCLUDES
|
||||||
Grid.cpp
|
Grid.cpp
|
||||||
Line.h
|
Line.h
|
||||||
Line.cpp
|
Line.cpp
|
||||||
|
LineSegment.cpp
|
||||||
Path.h
|
Path.h
|
||||||
Path.cpp
|
Path.cpp
|
||||||
Point.h
|
Point.h
|
||||||
Point.cpp
|
Point.cpp
|
||||||
|
Quad.cpp
|
||||||
Rectangle.h
|
Rectangle.h
|
||||||
Rectangle.cpp
|
Rectangle.cpp
|
||||||
Triangle.h
|
Triangle.h
|
||||||
|
|
28
src/geometry/LineSegment.cpp
Normal file
28
src/geometry/LineSegment.cpp
Normal 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();
|
||||||
|
}
|
27
src/geometry/LineSegment.h
Normal file
27
src/geometry/LineSegment.h
Normal 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;
|
||||||
|
};
|
|
@ -1,6 +1,5 @@
|
||||||
#include "Point.h"
|
#include "Point.h"
|
||||||
|
|
||||||
|
|
||||||
Point::Point(double x, double y)
|
Point::Point(double x, double y)
|
||||||
: mX(x),
|
: mX(x),
|
||||||
mY(y)
|
mY(y)
|
||||||
|
@ -11,8 +10,37 @@ Point::~Point()
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<Point> Point::Create(double x, double y)
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -11,37 +11,24 @@ public:
|
||||||
|
|
||||||
~Point();
|
~Point();
|
||||||
|
|
||||||
std::shared_ptr<Point> Create(double x, double y);
|
static std::shared_ptr<Point> Create(double x, double y);
|
||||||
|
|
||||||
double GetX() const
|
double getX() const;
|
||||||
{
|
|
||||||
return mX;
|
|
||||||
}
|
|
||||||
|
|
||||||
double GetY() const
|
double getY() const;
|
||||||
{
|
|
||||||
return mY;
|
|
||||||
}
|
|
||||||
|
|
||||||
double GetDistance(const Point& point) const
|
double getDistance(const Point& point) const;
|
||||||
{
|
|
||||||
return std::sqrt(mX*point.GetX() + mY*point.GetY());
|
|
||||||
}
|
|
||||||
|
|
||||||
double GetDeltaX(const Point& point) const
|
double getDistance(Point* point) const;
|
||||||
{
|
|
||||||
return point.GetX() - mX;
|
|
||||||
}
|
|
||||||
|
|
||||||
double GetDeltaY(const Point& point) const
|
double getDeltaX(const Point& point) const;
|
||||||
{
|
|
||||||
return point.GetY() - mY;
|
double getDeltaY(const Point& point) const;
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
double mX{0};
|
||||||
double mX;
|
double mY{0};
|
||||||
double mY;
|
double mZ{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
using PointPtr = std::shared_ptr<Point>;
|
using PointPtr = std::shared_ptr<Point>;
|
||||||
|
|
0
src/geometry/Quad.cpp
Normal file
0
src/geometry/Quad.cpp
Normal file
0
src/geometry/Quad.h
Normal file
0
src/geometry/Quad.h
Normal file
|
@ -26,12 +26,12 @@ public:
|
||||||
|
|
||||||
double GetHeight() const
|
double GetHeight() const
|
||||||
{
|
{
|
||||||
return mBottomLeft.GetDeltaY(mTopRight);
|
return mBottomLeft.getDeltaY(mTopRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
double GetWidth() const
|
double GetWidth() const
|
||||||
{
|
{
|
||||||
return mBottomLeft.GetDeltaX(mTopRight);
|
return mBottomLeft.getDeltaX(mTopRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
0
src/mesh/AbstractMesh.cpp
Normal file
0
src/mesh/AbstractMesh.cpp
Normal file
0
src/mesh/AbstractMesh.h
Normal file
0
src/mesh/AbstractMesh.h
Normal file
13
src/mesh/CMakeLists.txt
Normal file
13
src/mesh/CMakeLists.txt
Normal 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
0
src/mesh/Edge.cpp
Normal file
0
src/mesh/Edge.h
Normal file
0
src/mesh/Edge.h
Normal file
0
src/mesh/Face.cpp
Normal file
0
src/mesh/Face.cpp
Normal file
0
src/mesh/Face.h
Normal file
0
src/mesh/Face.h
Normal file
0
src/mesh/QuadMesh.cpp
Normal file
0
src/mesh/QuadMesh.cpp
Normal file
0
src/mesh/QuadMesh.h
Normal file
0
src/mesh/QuadMesh.h
Normal file
0
src/mesh/TriMesh.cpp
Normal file
0
src/mesh/TriMesh.cpp
Normal file
0
src/mesh/TriMesh.h
Normal file
0
src/mesh/TriMesh.h
Normal file
|
@ -5,9 +5,16 @@
|
||||||
#include "DrawingContext.h"
|
#include "DrawingContext.h"
|
||||||
#include "Grid.h"
|
#include "Grid.h"
|
||||||
#include "Rasterizer.h"
|
#include "Rasterizer.h"
|
||||||
|
#include "LineSegment.h"
|
||||||
|
#include "Point.h"
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
DrawingManager manager;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue