Cleaning for opengl rendering prep.
This commit is contained in:
parent
402f381d10
commit
7c6a92f4ec
58 changed files with 570 additions and 533 deletions
|
@ -1,15 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
class Rectangle;
|
||||
class Point;
|
||||
|
||||
template<class T>
|
||||
class Grid;
|
||||
|
||||
class AbstractGeometricItem
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~AbstractGeometricItem() = default;
|
||||
struct Bounds
|
||||
{
|
||||
Bounds(double width, double height)
|
||||
: mWidth(width),
|
||||
mHeight(height)
|
||||
{
|
||||
|
||||
//Rectangle GetBounds() const = 0;
|
||||
}
|
||||
|
||||
virtual void Sample(Grid* grid) const = 0;
|
||||
double mWidth{0.0};
|
||||
double mHeight{0.0};
|
||||
};
|
||||
|
||||
virtual ~AbstractGeometricItem() = default;
|
||||
|
||||
virtual Bounds getSize() const = 0;
|
||||
|
||||
virtual const Point& getLocation() const = 0;
|
||||
|
||||
virtual void sample(Grid<unsigned char>* grid) const = 0;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
#include "Grid.h"
|
||||
|
||||
template<typename T>
|
||||
Grid<T>::Grid(const Rectangle& bounds)
|
||||
: mBounds(bounds)
|
||||
{
|
||||
mValues = std::vector<T>(mNumX*mNumY, T());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const Rectangle& Grid<T>::getBounds() const
|
||||
{
|
||||
return mBounds;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
double Grid<T>::getXSpacing() const
|
||||
{
|
||||
return mBounds.getWidth()/double(mNumX);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
double Grid<T>::getYSpacing() const
|
||||
{
|
||||
return mBounds.getHeight()/double(mNumY);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const std::vector<T>& Grid<T>::getValues() const
|
||||
{
|
||||
return mValues;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Grid<T>::resetBounds(const Rectangle& bounds)
|
||||
{
|
||||
mBounds = bounds;
|
||||
mValues = std::vector<T>(mNumX*mNumY, T());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void Grid<T>::setValues(const std::vector<std::size_t>& indices, T value)
|
||||
{
|
||||
for (auto index : indices)
|
||||
{
|
||||
mValues[index] = value;
|
||||
}
|
||||
}
|
||||
|
||||
template class Grid<unsigned char>;
|
|
@ -3,54 +3,28 @@
|
|||
#include "Rectangle.h"
|
||||
#include <vector>
|
||||
|
||||
template<typename T>
|
||||
class Grid
|
||||
{
|
||||
public:
|
||||
|
||||
Grid(const Rectangle& bounds)
|
||||
: mBounds(bounds)
|
||||
{
|
||||
mValues = std::vector<double>(mNumX*mNumY, 0.0);
|
||||
}
|
||||
Grid(const Rectangle& bounds);
|
||||
|
||||
Rectangle GetBounds() const
|
||||
{
|
||||
return mBounds;
|
||||
}
|
||||
const Rectangle& getBounds() const;
|
||||
|
||||
double GetXSpacing() const
|
||||
{
|
||||
return mBounds.GetWidth()/double(mNumX);
|
||||
}
|
||||
double getXSpacing() const;
|
||||
|
||||
double GetYSpacing() const
|
||||
{
|
||||
return mBounds.GetHeight()/double(mNumY);
|
||||
}
|
||||
double getYSpacing() const;
|
||||
|
||||
std::vector<double> GetValues() const
|
||||
{
|
||||
return mValues;
|
||||
}
|
||||
const std::vector<T>& getValues() const;
|
||||
|
||||
void ResetBounds(const Rectangle& bounds)
|
||||
{
|
||||
mBounds = bounds;
|
||||
mValues = std::vector<double>(mNumX*mNumY, 0.0);
|
||||
}
|
||||
|
||||
void SetValues(const std::vector<std::size_t>& indices, double value)
|
||||
{
|
||||
for (auto index : indices)
|
||||
{
|
||||
mValues[index] = value;
|
||||
}
|
||||
}
|
||||
void resetBounds(const Rectangle& bounds);
|
||||
|
||||
void setValues(const std::vector<std::size_t>& indices, T value);
|
||||
|
||||
private:
|
||||
Rectangle mBounds;
|
||||
std::vector<double> mValues;
|
||||
std::vector<T> mValues;
|
||||
unsigned mNumX{5};
|
||||
unsigned mNumY{5};
|
||||
};
|
||||
|
|
|
@ -1,28 +1,43 @@
|
|||
#include "LineSegment.h"
|
||||
|
||||
LineSegment::LineSegment(PointPtr p0, PointPtr p1)
|
||||
LineSegment::LineSegment(const Point& p0, const Point& p1)
|
||||
: mP0(p0),
|
||||
mP1(p1)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
std::shared_ptr<LineSegment> LineSegment::Create(PointPtr p0, PointPtr p1)
|
||||
std::unique_ptr<LineSegment> LineSegment::Create(const Point& p0, const Point& p1)
|
||||
{
|
||||
return std::make_shared<LineSegment>(p0, p1);
|
||||
return std::make_unique<LineSegment>(p0, p1);
|
||||
}
|
||||
|
||||
double LineSegment::getLength() const
|
||||
{
|
||||
return mP0->getDistance(mP1.get());
|
||||
return mP0.getDistance(mP1);
|
||||
}
|
||||
|
||||
Point* LineSegment::getPoint0() const
|
||||
const Point& LineSegment::getPoint0() const
|
||||
{
|
||||
return mP0.get();
|
||||
return mP0;
|
||||
}
|
||||
|
||||
Point* LineSegment::getPoint1() const
|
||||
const Point& LineSegment::getPoint1() const
|
||||
{
|
||||
return mP1.get();
|
||||
return mP1;
|
||||
}
|
||||
|
||||
void LineSegment::sample(Grid<unsigned char>* grid) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
LineSegment::Bounds LineSegment::getSize() const
|
||||
{
|
||||
return {mP0.getDeltaX(mP1), mP0.getDeltaY(mP1)};
|
||||
}
|
||||
|
||||
const Point& LineSegment::getLocation() const
|
||||
{
|
||||
return mP0;
|
||||
}
|
||||
|
|
|
@ -3,25 +3,29 @@
|
|||
#include "AbstractGeometricItem.h"
|
||||
#include "Point.h"
|
||||
|
||||
template<class T>
|
||||
class Grid;
|
||||
|
||||
class LineSegment : public AbstractGeometricItem
|
||||
{
|
||||
public:
|
||||
LineSegment(PointPtr p0, PointPtr p1);
|
||||
LineSegment(const Point& p0, const Point& p1);
|
||||
|
||||
static std::shared_ptr<LineSegment> Create(PointPtr p0, PointPtr p1);
|
||||
static std::unique_ptr<LineSegment> Create(const Point& p0, const Point& p1);
|
||||
|
||||
double getLength() const;
|
||||
|
||||
Point* getPoint0() const;
|
||||
const Point& getPoint0() const;
|
||||
|
||||
Point* getPoint1() const;
|
||||
const Point& getPoint1() const;
|
||||
|
||||
void Sample(Grid* grid) const
|
||||
{
|
||||
void sample(Grid<unsigned char>* grid) const override;
|
||||
|
||||
}
|
||||
Bounds getSize() const override;
|
||||
|
||||
const Point& getLocation() const override;
|
||||
|
||||
private:
|
||||
PointPtr mP0;
|
||||
PointPtr mP1;
|
||||
Point mP0;
|
||||
Point mP1;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
#include "Rectangle.h"
|
||||
|
||||
Rectangle::Rectangle(const Point& bottomLeft, const Point& topRight)
|
||||
: mBottomLeft(bottomLeft)
|
||||
{
|
||||
mHeight = mBottomLeft.getDeltaY(topRight);
|
||||
mWidth = mBottomLeft.getDeltaX(topRight);
|
||||
}
|
||||
|
||||
Rectangle Rectangle::getBounds() const
|
||||
{
|
||||
return Rectangle(mBottomLeft, Point(mBottomLeft, mWidth, mHeight));
|
||||
}
|
||||
|
||||
void Rectangle::sample(Grid<unsigned char>* grid) const
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
double Rectangle::getHeight() const
|
||||
{
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
double Rectangle::getWidth() const
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
const Point& Rectangle::getLocation() const
|
||||
{
|
||||
return mBottomLeft;
|
||||
}
|
||||
|
||||
Rectangle::Bounds Rectangle::getSize() const
|
||||
{
|
||||
return {mWidth, mHeight};
|
||||
}
|
|
@ -3,43 +3,29 @@
|
|||
#include "AbstractGeometricItem.h"
|
||||
#include "Point.h"
|
||||
|
||||
template<class T>
|
||||
class Grid;
|
||||
|
||||
class Rectangle : public AbstractGeometricItem
|
||||
{
|
||||
public:
|
||||
|
||||
Rectangle(const Point& bottomLeft, const Point& topRight)
|
||||
: mBottomLeft(bottomLeft),
|
||||
mTopRight(topRight)
|
||||
{
|
||||
Rectangle(const Point& bottomLeft, const Point& topRight);
|
||||
|
||||
}
|
||||
double getHeight() const;
|
||||
|
||||
Rectangle GetBounds() const
|
||||
{
|
||||
return Rectangle(mBottomLeft, mTopRight);
|
||||
}
|
||||
double getWidth() const;
|
||||
|
||||
void Sample(Grid* grid) const override
|
||||
{
|
||||
const Point& getLocation() const override;
|
||||
|
||||
}
|
||||
Bounds getSize() const override;
|
||||
|
||||
double GetHeight() const
|
||||
{
|
||||
return mBottomLeft.getDeltaY(mTopRight);
|
||||
}
|
||||
Rectangle getBounds() const;
|
||||
|
||||
double GetWidth() const
|
||||
{
|
||||
return mBottomLeft.getDeltaX(mTopRight);
|
||||
}
|
||||
|
||||
Point getBottomLeft() const
|
||||
{
|
||||
return mBottomLeft;
|
||||
}
|
||||
void sample(Grid<unsigned char>* grid) const override;
|
||||
|
||||
private:
|
||||
Point mBottomLeft;
|
||||
Point mTopRight;
|
||||
double mWidth{0};
|
||||
double mHeight{0};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue