📄 polygon.h
字号:
#ifndef __GFX_POLYGON
#define __GFX_POLYGON
#include <e32std.h>
class MPolygon
{
// Pure Interface
public:
virtual TInt PolyCount() const =0;
virtual TPoint PolyPoint(TInt aPointNumber) const = 0;
virtual void SetPolyPoint(TInt aPointNumber, TPoint aPoint) =0;
// Utilities that make use of the interface
public:
inline TInt PolyLineCount() const;
TBool PointInterSects(const TPoint& aPoint) const;
TBool RectInterSects(const TRect& aRect) const;
TBool InsidePolygon(const TPoint p) const;
TBool Intersects(const MPolygon& aOther) const;
TBool Intersects(TPoint aPoint1, TPoint aPoint2) const;
void GetPolyLine(TInt aLineNumber, TPoint& aStartLine, TPoint& aEndLine) const;
void Scale(TReal iDx, TReal iDy);
void Rotate(TInt aAngle, MPolygon &aDestination) const;
void GetBoundingRect(TRect& aRect) const;
void RotateAndOffset(TInt aAngle,TPoint aOffset, MPolygon& aDestination) const;
void RotateOffsetAndScale(TInt aAngle,TPoint aOffset, TReal iXScale, TReal iYScale, MPolygon& aDestination) const;
void Offset(TPoint aOffset, MPolygon& aDestination) const;
};
/*
* RPolygon a polygon implemented as a dynamic array
*/
class RPolygon : public MPolygon
{
public:
void AppendPoint(TPoint aPoint);
void RemovePoint(TInt aIndex);
inline const TPoint& operator[](TInt aNum) const;
inline TPoint& operator[](TInt aNum);
void Close();
public: // from MPolygon
virtual TInt PolyCount() const;
virtual TPoint PolyPoint(TInt aPointNumber) const;
virtual void SetPolyPoint(TInt aPointNumber, TPoint aPoint);
private:
RArray<TPoint> iPointArray;
};
/*
* TFixedPolygon a fixed size polygon who's size is known at compile time
*/
template<TInt S>
class TFixedPolygon : public MPolygon
{
public:
TFixedPolygon();
virtual TInt PolyCount() const;
void SetPolyCount(TInt aCount);
TPoint PolyPoint(TInt aPointNumber) const;
void SetPolyPoint(TInt aPointNumber, TPoint aPoint);
TPoint& operator[](TInt aNum) const;
TPoint& operator[](TInt aNum);
private:
TPoint iPointArray[S];
TInt iCount;
TRect iBoundingRect;
};
/*
* INLINES
*/
inline TInt MPolygon::PolyLineCount() const
{
return PolyCount();
}
inline void RPolygon::AppendPoint(TPoint aPoint)
{
iPointArray.Append(aPoint);
}
template<TInt S>
TFixedPolygon<S>::TFixedPolygon():
iCount(S)
{
}
template<TInt S>
TInt TFixedPolygon<S>::PolyCount() const
{
return iCount;
}
template<TInt S>
void TFixedPolygon<S>::SetPolyCount(TInt aCount)
{
iCount = aCount;
}
template<TInt S>
TPoint TFixedPolygon<S>::PolyPoint(TInt aPointNumber) const
{
return iPointArray[aPointNumber];
}
template<TInt S>
void TFixedPolygon<S>::SetPolyPoint(TInt aPointNumber, TPoint aPoint)
{
iPointArray[aPointNumber] = aPoint;
}
template<TInt S>
TPoint& TFixedPolygon<S>::operator[](TInt aNum) const
{
return iPointArray[aNum];
}
template<TInt S>
TPoint& TFixedPolygon<S>::operator[](TInt aNum)
{
return iPointArray[aNum];
}
#endif // __GFX_POLYGON
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -