[DEV] change Vector2D ==> etk::Vector2D

This commit is contained in:
Edouard DUPIN 2012-10-26 16:59:08 +02:00
parent 18e51a5e97
commit 4c65a1049a
2 changed files with 66 additions and 66 deletions

View File

@ -39,7 +39,7 @@ draw::Image::Image(void) :
Init(); Init();
} }
draw::Image::Image(Vector2D<int32_t> size) : draw::Image::Image(etk::Vector2D<int32_t> size) :
m_renderingBuffer(NULL), m_renderingBuffer(NULL),
m_pixFrame(NULL), m_pixFrame(NULL),
m_renderBase(NULL), m_renderBase(NULL),
@ -120,7 +120,7 @@ draw::Image::~Image(void)
} }
} }
void draw::Image::Resize(Vector2D<int32_t> size) void draw::Image::Resize(etk::Vector2D<int32_t> size)
{ {
if (NULL != m_renderArea) { if (NULL != m_renderArea) {
delete(m_renderArea); delete(m_renderArea);
@ -196,22 +196,22 @@ void draw::Image::End(void)
} }
void draw::Image::MoveTo(Vector2D<float> pos) void draw::Image::MoveTo(etk::Vector2D<float> pos)
{ {
} }
void draw::Image::MoveToAbs(Vector2D<float> pos) void draw::Image::MoveToAbs(etk::Vector2D<float> pos)
{ {
} }
void draw::Image::LineTo(Vector2D<float> pos) void draw::Image::LineTo(etk::Vector2D<float> pos)
{ {
} }
void draw::Image::LineToAbs(Vector2D<float> pos) void draw::Image::LineToAbs(etk::Vector2D<float> pos)
{ {
} }
@ -226,18 +226,18 @@ void draw::Image::Draw(void)
} }
void draw::Image::Dot(Vector2D<float> pos) void draw::Image::Dot(etk::Vector2D<float> pos)
{ {
/* /*
Begin(); Begin();
MoveTo(pos); MoveTo(pos);
LineTo(pos+Vector2D<float>(1,1)); LineTo(pos+etk::Vector2D<float>(1,1));
End(); End();
*/ */
Set(pos, m_fillColor); Set(pos, m_fillColor);
} }
void draw::Image::Line(Vector2D<float> posStart, Vector2D<float> posEnd) void draw::Image::Line(etk::Vector2D<float> posStart, etk::Vector2D<float> posEnd)
{ {
Begin(); Begin();
MoveTo(posStart); MoveTo(posStart);
@ -245,10 +245,10 @@ void draw::Image::Line(Vector2D<float> posStart, Vector2D<float> posEnd)
End(); End();
} }
void draw::Image::Rectangle(Vector2D<float> pos, Vector2D<float> size) void draw::Image::Rectangle(etk::Vector2D<float> pos, etk::Vector2D<float> size)
{ {
Begin(); Begin();
Vector2D<float> tmp = pos; etk::Vector2D<float> tmp = pos;
MoveTo(pos); MoveTo(pos);
tmp.x += size.x; tmp.x += size.x;
LineTo(tmp); LineTo(tmp);
@ -260,12 +260,12 @@ void draw::Image::Rectangle(Vector2D<float> pos, Vector2D<float> size)
End(); End();
} }
void draw::Image::Circle(Vector2D<float> pos, float radius, float angleStart, float angleStop) void draw::Image::Circle(etk::Vector2D<float> pos, float radius, float angleStart, float angleStop)
{ {
} }
void draw::Image::Disc(Vector2D<float> pos, float radius, float angleStart, float angleStop) void draw::Image::Disc(etk::Vector2D<float> pos, float radius, float angleStart, float angleStop)
{ {
} }
@ -274,10 +274,10 @@ void draw::Image::Disc(Vector2D<float> pos, float radius, float angleStart, floa
void Grid::GenerateSDF() void Grid::GenerateSDF()
{ {
// Pass 0 // Pass 0
Vector2D<int32_t> tmpPos; etk::Vector2D<int32_t> tmpPos;
for (tmpPos.y=1 ; tmpPos.y<m_size.y-1 ; tmpPos.y++) { for (tmpPos.y=1 ; tmpPos.y<m_size.y-1 ; tmpPos.y++) {
for (tmpPos.x=1 ; tmpPos.x<m_size.x-1 ; tmpPos.x++) { for (tmpPos.x=1 ; tmpPos.x<m_size.x-1 ; tmpPos.x++) {
Vector2D<int32_t> p = Get(tmpPos); etk::Vector2D<int32_t> p = Get(tmpPos);
Compare(p, tmpPos, -1, 0 ); Compare(p, tmpPos, -1, 0 );
Compare(p, tmpPos, 0, -1 ); Compare(p, tmpPos, 0, -1 );
Compare(p, tmpPos, -1, -1 ); Compare(p, tmpPos, -1, -1 );
@ -285,7 +285,7 @@ void Grid::GenerateSDF()
Set(tmpPos, p); Set(tmpPos, p);
} }
for (tmpPos.x=m_size.x-2 ; tmpPos.x>0 ; tmpPos.x--) { for (tmpPos.x=m_size.x-2 ; tmpPos.x>0 ; tmpPos.x--) {
Vector2D<int32_t> p = Get(tmpPos); etk::Vector2D<int32_t> p = Get(tmpPos);
Compare(p, tmpPos, 1, 0 ); Compare(p, tmpPos, 1, 0 );
Set(tmpPos, p ); Set(tmpPos, p );
} }
@ -293,7 +293,7 @@ void Grid::GenerateSDF()
// Pass 1 // Pass 1
for (tmpPos.y=m_size.y-2 ; tmpPos.y>0 ; tmpPos.y--) { for (tmpPos.y=m_size.y-2 ; tmpPos.y>0 ; tmpPos.y--) {
for (tmpPos.x=m_size.x-2 ; tmpPos.x>1 ; tmpPos.x--) { for (tmpPos.x=m_size.x-2 ; tmpPos.x>1 ; tmpPos.x--) {
Vector2D<int32_t> p = Get(tmpPos); etk::Vector2D<int32_t> p = Get(tmpPos);
Compare(p, tmpPos, 1, 0 ); Compare(p, tmpPos, 1, 0 );
Compare(p, tmpPos, 0, 1 ); Compare(p, tmpPos, 0, 1 );
Compare(p, tmpPos, -1, 1 ); Compare(p, tmpPos, -1, 1 );
@ -301,7 +301,7 @@ void Grid::GenerateSDF()
Set(tmpPos, p); Set(tmpPos, p);
} }
for (tmpPos.x=1 ; tmpPos.x<m_size.x-1 ; tmpPos.x++) { for (tmpPos.x=1 ; tmpPos.x<m_size.x-1 ; tmpPos.x++) {
Vector2D<int32_t> p = Get(tmpPos); etk::Vector2D<int32_t> p = Get(tmpPos);
Compare(p, tmpPos, -1, 0 ); Compare(p, tmpPos, -1, 0 );
Set(tmpPos, p); Set(tmpPos, p);
} }
@ -312,18 +312,18 @@ void Grid::GenerateSDF()
void draw::Image::DistanceField(void) void draw::Image::DistanceField(void)
{ {
DistanceField(Vector2D<int32_t>(0,0), m_size); DistanceField(etk::Vector2D<int32_t>(0,0), m_size);
} }
#endif #endif
#define META_DIST (8) #define META_DIST (8)
void draw::Image::DistanceField(Vector2D<int32_t> pos, Vector2D<int32_t> size, int32_t upscaler, int32_t startPos) void draw::Image::DistanceField(etk::Vector2D<int32_t> pos, etk::Vector2D<int32_t> size, int32_t upscaler, int32_t startPos)
{ {
#ifndef BASIC_GRADIENT #ifndef BASIC_GRADIENT
float maxVal = 1/(1000.0*sqrt(META_DIST*META_DIST+META_DIST*META_DIST)); float maxVal = 1/(1000.0*sqrt(META_DIST*META_DIST+META_DIST*META_DIST));
Vector2D<int32_t> tmpPos; etk::Vector2D<int32_t> tmpPos;
// generate distance system ... matrix ... // generate distance system ... matrix ...
Grid grid2(Vector2D<int32_t>(META_DIST*2,META_DIST*2)); Grid grid2(etk::Vector2D<int32_t>(META_DIST*2,META_DIST*2));
for(tmpPos.y=0 ; tmpPos.y<META_DIST*2 ; tmpPos.y++ ) { for(tmpPos.y=0 ; tmpPos.y<META_DIST*2 ; tmpPos.y++ ) {
for(tmpPos.x=0 ; tmpPos.x<META_DIST*2 ; tmpPos.x++ ) { for(tmpPos.x=0 ; tmpPos.x<META_DIST*2 ; tmpPos.x++ ) {
int32_t val = 1000.0*sqrt((tmpPos.x-META_DIST)*(tmpPos.x-META_DIST) + (tmpPos.y-META_DIST)*(tmpPos.y-META_DIST)); int32_t val = 1000.0*sqrt((tmpPos.x-META_DIST)*(tmpPos.x-META_DIST) + (tmpPos.y-META_DIST)*(tmpPos.y-META_DIST));
@ -351,14 +351,14 @@ void draw::Image::DistanceField(Vector2D<int32_t> pos, Vector2D<int32_t> size, i
// when out no distance find ... // when out no distance find ...
grid1.SetErrorVal(insideOrOutsideCurrentPixel); grid1.SetErrorVal(insideOrOutsideCurrentPixel);
Vector2D<int32_t> tmpPos2; etk::Vector2D<int32_t> tmpPos2;
int32_t newDist = 50000000; int32_t newDist = 50000000;
for(tmpPos2.y=-META_DIST ; tmpPos2.y<META_DIST ; tmpPos2.y++ ) { for(tmpPos2.y=-META_DIST ; tmpPos2.y<META_DIST ; tmpPos2.y++ ) {
for(tmpPos2.x=-META_DIST ; tmpPos2.x<META_DIST ; tmpPos2.x++ ) { for(tmpPos2.x=-META_DIST ; tmpPos2.x<META_DIST ; tmpPos2.x++ ) {
// we have an opposite factor ... // we have an opposite factor ...
if (insideOrOutsideCurrentPixel != grid1.Get(tmpPos+tmpPos2)) { if (insideOrOutsideCurrentPixel != grid1.Get(tmpPos+tmpPos2)) {
// get new distance // get new distance
int32_t tmpDist = grid2.Get(tmpPos2 + Vector2D<int32_t>(META_DIST,META_DIST)); int32_t tmpDist = grid2.Get(tmpPos2 + etk::Vector2D<int32_t>(META_DIST,META_DIST));
if (newDist > tmpDist) { if (newDist > tmpDist) {
newDist = tmpDist; newDist = tmpDist;
} }
@ -384,7 +384,7 @@ void draw::Image::DistanceField(Vector2D<int32_t> pos, Vector2D<int32_t> size, i
grid1.SetErrorVal(0); grid1.SetErrorVal(0);
grid2.SetErrorVal(500000); grid2.SetErrorVal(500000);
Vector2D<int32_t> tmpPos; etk::Vector2D<int32_t> tmpPos;
for(tmpPos.y=0 ; tmpPos.y<size.y ; tmpPos.y++ ) { for(tmpPos.y=0 ; tmpPos.y<size.y ; tmpPos.y++ ) {
for(tmpPos.x=0 ; tmpPos.x<size.x ; tmpPos.x++ ) { for(tmpPos.x=0 ; tmpPos.x<size.x ; tmpPos.x++ ) {
draw::Color tmpColor = Get(pos+tmpPos); draw::Color tmpColor = Get(pos+tmpPos);
@ -405,8 +405,8 @@ void draw::Image::DistanceField(Vector2D<int32_t> pos, Vector2D<int32_t> size, i
for(tmpPos.y=startPos ; tmpPos.y<size.y ; tmpPos.y+=upscaler ) { for(tmpPos.y=startPos ; tmpPos.y<size.y ; tmpPos.y+=upscaler ) {
for(tmpPos.x=startPos ; tmpPos.x<size.x ; tmpPos.x+=upscaler ) { for(tmpPos.x=startPos ; tmpPos.x<size.x ; tmpPos.x+=upscaler ) {
Vector2D<int32_t> elem1 = grid1.Get(tmpPos); etk::Vector2D<int32_t> elem1 = grid1.Get(tmpPos);
Vector2D<int32_t> elem2 = grid2.Get(tmpPos); etk::Vector2D<int32_t> elem2 = grid2.Get(tmpPos);
// Calculate the actual distance from the x/y // Calculate the actual distance from the x/y
float dist1 = sqrt( (double)elem1.QuadDist() ); float dist1 = sqrt( (double)elem1.QuadDist() );
float dist2 = sqrt( (double)elem2.QuadDist() ); float dist2 = sqrt( (double)elem2.QuadDist() );

View File

@ -48,11 +48,11 @@
class Grid class Grid
{ {
public: public:
Vector2D<int32_t> m_size; etk::Vector2D<int32_t> m_size;
etk::Vector<int32_t > m_data; etk::Vector<int32_t > m_data;
int32_t m_outsideVal; int32_t m_outsideVal;
int32_t m_errorVal; int32_t m_errorVal;
Grid(Vector2D<int32_t> size) Grid(etk::Vector2D<int32_t> size)
{ {
m_size = size; m_size = size;
m_outsideVal = 20; m_outsideVal = 20;
@ -71,14 +71,14 @@ class Grid
{ {
m_errorVal = newVal; m_errorVal = newVal;
} }
void SetInide(Vector2D<int32_t> pos) void SetInide(etk::Vector2D<int32_t> pos)
{ {
if( pos.x>=0 && pos.x<m_size.x if( pos.x>=0 && pos.x<m_size.x
&& pos.y>=0 && pos.y<m_size.y) { && pos.y>=0 && pos.y<m_size.y) {
m_data[pos.x+pos.y*m_size.x]=0; m_data[pos.x+pos.y*m_size.x]=0;
} }
}; };
void SetOutside(Vector2D<int32_t> pos) void SetOutside(etk::Vector2D<int32_t> pos)
{ {
if( pos.x>=0 && pos.x<m_size.x if( pos.x>=0 && pos.x<m_size.x
&& pos.y>=0 && pos.y<m_size.y) { && pos.y>=0 && pos.y<m_size.y) {
@ -86,7 +86,7 @@ class Grid
} }
}; };
int32_t Get(Vector2D<int32_t> pos) int32_t Get(etk::Vector2D<int32_t> pos)
{ {
; ;
if( pos.x>0 && pos.x<m_size.x if( pos.x>0 && pos.x<m_size.x
@ -96,7 +96,7 @@ class Grid
return m_errorVal; return m_errorVal;
}; };
void Set(Vector2D<int32_t> pos, int32_t val) void Set(etk::Vector2D<int32_t> pos, int32_t val)
{ {
if( pos.x>0 && pos.x<m_size.x if( pos.x>0 && pos.x<m_size.x
&& pos.y>0 && pos.y<m_size.y) { && pos.y>0 && pos.y<m_size.y) {
@ -109,17 +109,17 @@ class Grid
class Grid class Grid
{ {
public: public:
Vector2D<int32_t> m_size; etk::Vector2D<int32_t> m_size;
etk::Vector<Vector2D<int32_t> > m_data; etk::Vector<etk::Vector2D<int32_t> > m_data;
int32_t m_outsideVal; int32_t m_outsideVal;
int32_t m_errorVal; int32_t m_errorVal;
Grid(Vector2D<int32_t> size) Grid(etk::Vector2D<int32_t> size)
{ {
m_size = size; m_size = size;
m_outsideVal = 20; m_outsideVal = 20;
m_errorVal = 0; m_errorVal = 0;
// basic element : // basic element :
Vector2D<int32_t> tmpPoint(0,0); etk::Vector2D<int32_t> tmpPoint(0,0);
// preallocate data with a basic bg elements : // preallocate data with a basic bg elements :
m_data.ReSize(m_size.x*m_size.y, tmpPoint); m_data.ReSize(m_size.x*m_size.y, tmpPoint);
}; };
@ -132,7 +132,7 @@ class Grid
{ {
m_errorVal = newVal; m_errorVal = newVal;
} }
void SetInide(Vector2D<int32_t> pos) void SetInide(etk::Vector2D<int32_t> pos)
{ {
//if( pos.x>=0 && pos.x<m_size.x //if( pos.x>=0 && pos.x<m_size.x
// && pos.y>=0 && pos.y<m_size.y) { // && pos.y>=0 && pos.y<m_size.y) {
@ -140,7 +140,7 @@ class Grid
m_data[pos.x+pos.y*m_size.x].y=0; m_data[pos.x+pos.y*m_size.x].y=0;
//} //}
}; };
void SetOutside(Vector2D<int32_t> pos) void SetOutside(etk::Vector2D<int32_t> pos)
{ {
//if( pos.x>=0 && pos.x<m_size.x //if( pos.x>=0 && pos.x<m_size.x
// && pos.y>=0 && pos.y<m_size.y) { // && pos.y>=0 && pos.y<m_size.y) {
@ -149,16 +149,16 @@ class Grid
//} //}
}; };
Vector2D<int32_t> Get(Vector2D<int32_t> pos) etk::Vector2D<int32_t> Get(etk::Vector2D<int32_t> pos)
{ {
//if( pos.x>0 && pos.x<m_size.x //if( pos.x>0 && pos.x<m_size.x
// && pos.y>0 && pos.y<m_size.y) { // && pos.y>0 && pos.y<m_size.y) {
return m_data[pos.x+pos.y*m_size.x]; return m_data[pos.x+pos.y*m_size.x];
//} //}
//return Vector2D<int32_t>(m_errorVal,m_errorVal); //return etk::Vector2D<int32_t>(m_errorVal,m_errorVal);
}; };
void Set(Vector2D<int32_t> pos, Vector2D<int32_t> val) void Set(etk::Vector2D<int32_t> pos, etk::Vector2D<int32_t> val)
{ {
//if( pos.x>0 && pos.x<m_size.x //if( pos.x>0 && pos.x<m_size.x
// && pos.y>0 && pos.y<m_size.y) { // && pos.y>0 && pos.y<m_size.y) {
@ -166,11 +166,11 @@ class Grid
//} //}
}; };
void Compare(Vector2D<int32_t> &p, Vector2D<int32_t> pos, int32_t offsetx, int32_t offsety ) void Compare(etk::Vector2D<int32_t> &p, etk::Vector2D<int32_t> pos, int32_t offsetx, int32_t offsety )
{ {
pos.x += offsetx; pos.x += offsetx;
pos.y += offsety; pos.y += offsety;
Vector2D<int32_t> other = Get(pos); etk::Vector2D<int32_t> other = Get(pos);
other.x += offsetx; other.x += offsetx;
other.y += offsety; other.y += offsety;
if (other.QuadDist() < p.QuadDist()) { if (other.QuadDist() < p.QuadDist()) {
@ -191,7 +191,7 @@ namespace draw
class Image { class Image {
private: private:
Vector2D<int32_t> m_size; etk::Vector2D<int32_t> m_size;
etk::Vector<draw::Color> m_data; etk::Vector<draw::Color> m_data;
agg::rendering_buffer * m_renderingBuffer; agg::rendering_buffer * m_renderingBuffer;
agg::pixfmt_rgba32 * m_pixFrame; agg::pixfmt_rgba32 * m_pixFrame;
@ -205,7 +205,7 @@ namespace draw
float m_strokeSize; float m_strokeSize;
public: public:
// constructor : // constructor :
Image(Vector2D<int32_t> size); Image(etk::Vector2D<int32_t> size);
Image(void); Image(void);
// destructor // destructor
~Image(void); ~Image(void);
@ -220,10 +220,10 @@ namespace draw
// -- basic tools : // -- basic tools :
// ----------------------------------------------- // -----------------------------------------------
public : public :
void Resize(Vector2D<int32_t> size); void Resize(etk::Vector2D<int32_t> size);
//void Resize(Vector2D<int32_t> startPos, Vector2D<int32_t> size); //void Resize(etk::Vector2D<int32_t> startPos, Vector2D<int32_t> size);
Vector2D<int32_t> GetSize(void) const etk::Vector2D<int32_t> GetSize(void) const
{ {
return m_size; return m_size;
}; };
@ -236,7 +236,7 @@ namespace draw
return m_size.y; return m_size.y;
}; };
//void Move(Vector2D<int32_t> pos); //void Move(etk::Vector2D<int32_t> pos);
//void Rotate(float angle); // radian //void Rotate(float angle); // radian
@ -254,7 +254,7 @@ namespace draw
//Image & operator= (const Image &image) //Image & operator= (const Image &image)
draw::Color Get(Vector2D<int32_t> pos) draw::Color Get(etk::Vector2D<int32_t> pos)
{ {
draw::Color outColor(0x00000000); draw::Color outColor(0x00000000);
if( pos.x>0 && pos.x<m_size.x if( pos.x>0 && pos.x<m_size.x
@ -264,7 +264,7 @@ namespace draw
return outColor; return outColor;
} }
void Set(Vector2D<int32_t> pos, draw::Color newColor) void Set(etk::Vector2D<int32_t> pos, draw::Color newColor)
{ {
if( pos.x>=0 && pos.x<m_size.x if( pos.x>=0 && pos.x<m_size.x
&& pos.y>=0 && pos.y<m_size.y) { && pos.y>=0 && pos.y<m_size.y) {
@ -272,9 +272,9 @@ namespace draw
} }
} }
//Image GetSubImage(Vector2D<int32_t> startPos, Vector2D<int32_t> size) const; //Image GetSubImage(etk::Vector2D<int32_t> startPos, Vector2D<int32_t> size) const;
//void SetData(uint8_t *data, Vector2D<int32_t> size); //void SetData(uint8_t *data, etk::Vector2D<int32_t> size);
// ----------------------------------------------- // -----------------------------------------------
// -- Drawing tools : // -- Drawing tools :
@ -291,21 +291,21 @@ namespace draw
void SetStrokeSize(float thickness) { void SetStrokeSize(float thickness) {
m_strokeSize = thickness; m_strokeSize = thickness;
} }
void MoveTo(Vector2D<float> pos); void MoveTo(etk::Vector2D<float> pos);
void MoveToAbs(Vector2D<float> pos); void MoveToAbs(etk::Vector2D<float> pos);
void LineTo(Vector2D<float> pos); void LineTo(etk::Vector2D<float> pos);
void LineToAbs(Vector2D<float> pos); void LineToAbs(etk::Vector2D<float> pos);
void Join(void); void Join(void);
void Draw(void); void Draw(void);
void Line(Vector2D<float> posStart, Vector2D<float> posEnd); void Line(etk::Vector2D<float> posStart, etk::Vector2D<float> posEnd);
void Dot(Vector2D<float> pos); void Dot(etk::Vector2D<float> pos);
void Rectangle(Vector2D<float> pos, Vector2D<float> size); void Rectangle(etk::Vector2D<float> pos, etk::Vector2D<float> size);
void Circle(Vector2D<float> pos, float radius, float angleStart=0, float angleStop=2*M_PI); void Circle(etk::Vector2D<float> pos, float radius, float angleStart=0, float angleStop=2*M_PI);
void Disc(Vector2D<float> pos, float radius, float angleStart=0, float angleStop=2*M_PI); void Disc(etk::Vector2D<float> pos, float radius, float angleStart=0, float angleStop=2*M_PI);
// generate the distant field from the alpha value of the Image // generate the distant field from the alpha value of the Image
void DistanceField(void); void DistanceField(void);
void DistanceField(Vector2D<int32_t> pos, Vector2D<int32_t> size, int32_t upscaler=1, int32_t startPos=0); void DistanceField(etk::Vector2D<int32_t> pos, etk::Vector2D<int32_t> size, int32_t upscaler=1, int32_t startPos=0);
void SaveFile(const char * file) {}; void SaveFile(const char * file) {};
private: private: