mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-05-21 06:45:39 -06:00
Painter fixed to work in Linux, MoveableWithSwap removed (GCC problems, possibly undefined behaviour of code)
git-svn-id: svn://ultimatepp.org/upp/trunk@867 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
f2f2348907
commit
dd88989c82
13 changed files with 2005 additions and 2045 deletions
|
|
@ -207,67 +207,25 @@ inline void AssertMoveable(T *t = 0) { if(t) AssertMoveable0(t); }
|
|||
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
inline void Swap_(T& a, T& b) { T tmp = a; a = b; b = tmp; }
|
||||
|
||||
template <class T>
|
||||
inline void MoveableSwap(T& x, T& y)
|
||||
{
|
||||
if(sizeof(T) == 1)
|
||||
Swap_(*(byte *)&x, *(byte *)&y);
|
||||
else
|
||||
if(sizeof(T) == 2)
|
||||
Swap_(*(uint16 *)&x, *(uint16 *)&y);
|
||||
else
|
||||
if(sizeof(T) == 4)
|
||||
Swap_(*(uint32 *)&x, *(uint32 *)&y);
|
||||
else
|
||||
if(sizeof(T) == 8)
|
||||
Swap_(*(uint64 *)&x, *(uint64 *)&y);
|
||||
else
|
||||
if(sizeof(T) == 12) {
|
||||
Swap_(*(uint64 *)&x, *(uint64 *)&y);
|
||||
Swap_(*((uint32 *)&x + 2), *((uint32 *)&y + 2));
|
||||
}
|
||||
else
|
||||
if(sizeof(T) == 16) {
|
||||
Swap_(*(uint64 *)&x, *(uint64 *)&y);
|
||||
Swap_(*((uint64 *)&x + 1), *((uint64 *)&y + 1));
|
||||
}
|
||||
else
|
||||
Swap_(x, y);
|
||||
}
|
||||
|
||||
template <class T, class B = EmptyClass>
|
||||
class MoveableWithSwap : public Moveable<T, B> {
|
||||
friend void Swap(T& a, T& b) { MoveableSwap(a, b); }
|
||||
friend void IterSwap(T *a, T *b) { Swap(*a, *b); }
|
||||
};
|
||||
|
||||
#define NTL_MOVEABLE_WITH_SWAP(T) \
|
||||
inline void Swap(T& a, T& b) { MoveableSwap(a, b); } \
|
||||
inline void IterSwap(T *a, T *b) { MoveableSwap(*a, *b); } \
|
||||
NTL_MOVEABLE(T)
|
||||
|
||||
NTL_MOVEABLE_WITH_SWAP(bool);
|
||||
NTL_MOVEABLE_WITH_SWAP(char);
|
||||
NTL_MOVEABLE_WITH_SWAP(signed char);
|
||||
NTL_MOVEABLE_WITH_SWAP(unsigned char);
|
||||
NTL_MOVEABLE_WITH_SWAP(short);
|
||||
NTL_MOVEABLE_WITH_SWAP(unsigned short);
|
||||
NTL_MOVEABLE_WITH_SWAP(int);
|
||||
NTL_MOVEABLE_WITH_SWAP(unsigned int);
|
||||
NTL_MOVEABLE_WITH_SWAP(long);
|
||||
NTL_MOVEABLE_WITH_SWAP(unsigned long);
|
||||
NTL_MOVEABLE_WITH_SWAP(int64);
|
||||
NTL_MOVEABLE_WITH_SWAP(uint64);
|
||||
NTL_MOVEABLE_WITH_SWAP(float);
|
||||
NTL_MOVEABLE_WITH_SWAP(double);
|
||||
NTL_MOVEABLE_WITH_SWAP(void *);
|
||||
NTL_MOVEABLE_WITH_SWAP(const void *);
|
||||
NTL_MOVEABLE(bool);
|
||||
NTL_MOVEABLE(char);
|
||||
NTL_MOVEABLE(signed char);
|
||||
NTL_MOVEABLE(unsigned char);
|
||||
NTL_MOVEABLE(short);
|
||||
NTL_MOVEABLE(unsigned short);
|
||||
NTL_MOVEABLE(int);
|
||||
NTL_MOVEABLE(unsigned int);
|
||||
NTL_MOVEABLE(long);
|
||||
NTL_MOVEABLE(unsigned long);
|
||||
NTL_MOVEABLE(int64);
|
||||
NTL_MOVEABLE(uint64);
|
||||
NTL_MOVEABLE(float);
|
||||
NTL_MOVEABLE(double);
|
||||
NTL_MOVEABLE(void *);
|
||||
NTL_MOVEABLE(const void *);
|
||||
|
||||
#if defined(_NATIVE_WCHAR_T_DEFINED) || defined(COMPILER_GCC)
|
||||
NTL_MOVEABLE_WITH_SWAP(wchar_t);
|
||||
NTL_MOVEABLE(wchar_t);
|
||||
#endif
|
||||
|
||||
template <class T, class B = EmptyClass>
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ void ApproximateArc(LinearPathConsumer& t, const Pointf& c, const Pointf& r,
|
|||
while(angle + sweep < 0)
|
||||
angle += 2000 * M_PI;
|
||||
double fid = acos(1 - tolerance / max(r.x, r.y));
|
||||
if(abs(sweep / fid) > 1000)
|
||||
if(fabs(sweep / fid) > 1000)
|
||||
fid = sweep / 1000;
|
||||
double a = angle;
|
||||
double e = angle + sweep;
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ public:
|
|||
virtual void Line(const Pointf& p);
|
||||
|
||||
private:
|
||||
struct Cell : MoveableWithSwap<Cell> {
|
||||
struct Cell : Moveable<Cell> {
|
||||
int16 x;
|
||||
int16 cover;
|
||||
int area;
|
||||
|
|
|
|||
|
|
@ -213,7 +213,6 @@ struct PainterImageSpan : SpanSource {
|
|||
|
||||
void BufferPainter::RenderImage(double width, const Image& image, const Xform2D& transsrc, dword flags)
|
||||
{
|
||||
Close();
|
||||
if(image.GetWidth() == 0 || image.GetHeight() == 0)
|
||||
return;
|
||||
PainterImageSpan ss;
|
||||
|
|
@ -227,6 +226,7 @@ void BufferPainter::RenderImage(double width, const Image& image, const Xform2D&
|
|||
|
||||
void BufferPainter::FillOp(const Image& image, const Xform2D& transsrc, dword flags)
|
||||
{
|
||||
Close();
|
||||
RenderImage(-1, image, transsrc, flags);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ double SquareDist(const Pointf& p1, const Pointf& p2)
|
|||
|
||||
Pointf Mid(const Pointf& a, const Pointf& b)
|
||||
{
|
||||
return (a + b) / 2;
|
||||
return 0.5 * (a + b);
|
||||
}
|
||||
|
||||
Pointf Orthogonal(const Pointf& p)
|
||||
|
|
|
|||
|
|
@ -45,7 +45,8 @@ void *BufferPainter::PathAddRaw(int type, int size)
|
|||
|
||||
void BufferPainter::MoveOp(const Pointf& p, bool rel)
|
||||
{
|
||||
PathAdd<LinearData>(MOVE).p = move = ccontrol = qcontrol = EndPoint(p, rel);
|
||||
move = ccontrol = qcontrol = EndPoint(p, rel);
|
||||
PathAdd<LinearData>(MOVE).p = move;
|
||||
}
|
||||
|
||||
void BufferPainter::DoMove0()
|
||||
|
|
@ -70,7 +71,7 @@ void BufferPainter::QuadraticOp(const Pointf& p1, const Pointf& p, bool rel)
|
|||
|
||||
void BufferPainter::QuadraticOp(const Pointf& p, bool rel)
|
||||
{
|
||||
QuadraticOp(2 * current - qcontrol, p, rel);
|
||||
QuadraticOp(2.0 * current - qcontrol, p, rel);
|
||||
}
|
||||
|
||||
void BufferPainter::CubicOp(const Pointf& p1, const Pointf& p2, const Pointf& p, bool rel)
|
||||
|
|
@ -84,7 +85,7 @@ void BufferPainter::CubicOp(const Pointf& p1, const Pointf& p2, const Pointf& p,
|
|||
|
||||
void BufferPainter::CubicOp(const Pointf& p2, const Pointf& p, bool rel)
|
||||
{
|
||||
CubicOp(2 * current - ccontrol, p2, p, rel);
|
||||
CubicOp(2.0 * current - ccontrol, p2, p, rel);
|
||||
}
|
||||
|
||||
Pointf BufferPainter::ArcData::EndPoint() const
|
||||
|
|
@ -115,7 +116,7 @@ void BufferPainter::SvgArcOp(const Pointf& r, double xangle, bool large, bool sw
|
|||
|
||||
void BufferPainter::CloseOp()
|
||||
{
|
||||
if(!IsNull(move) && current != move) {
|
||||
if(!IsNull(move) && !IsNull(current) && current != move) {
|
||||
Line(move);
|
||||
move = Null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ NAMESPACE_UPP
|
|||
|
||||
void Rasterizer::CvLine(double x1, double y1, double x2, double y2)
|
||||
{
|
||||
LLOG("CvLine " << x1 << ", " << y1 << " - " << x2 << ", " << y2);
|
||||
LineRaw(Q8(x1), Q8(y1), Q8(x2), Q8(y2));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ void Painter::DoSvgArc(const Pointf& rr, double xangle, int large, int sweep,
|
|||
{
|
||||
Pointf r(fabs(rr.x), fabs(rr.y));
|
||||
Xform2D m = Xform2D::Rotation(-xangle);
|
||||
Pointf d1 = m.Transform((p0 - p1) / 2);
|
||||
Pointf d1 = m.Transform(Mid(p0, p1));
|
||||
Pointf pr = r * r;
|
||||
Pointf p = d1 * d1;
|
||||
double check = p.x / pr.x + p.y / pr.y;
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ double Xform2D::GetScale() const
|
|||
bool Xform2D::IsRegular() const
|
||||
{
|
||||
Pointf d = GetScaleXY();
|
||||
return abs(d.x - d.y) < 1e-10 * abs(max(d.x, d.y));
|
||||
return fabs(d.x - d.y) < 1e-10 * fabs(max(d.x, d.y));
|
||||
}
|
||||
|
||||
Xform2D::Xform2D()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue