TLinearDDA Class Reference

class TLinearDDA

Linear digital differential analyser.

This is used to calculate the pixels which most closely approximate a specified straight line, or when scaling a bitmap. Note that a line is infinitely thin, and can only be approximated by pixels with real width and height.

Functions are provided for: pixel line traversing; jumping to a rectangle or co-ordinate

Public Member Functions
TLinearDDA()
TLinearDDA(const TLinearDDA &)
IMPORT_C voidConstruct(const TPoint &, const TPoint &, TLineMode)
IMPORT_C voidJumpToRect(const TRect &)
IMPORT_C voidJumpToXCoord(const TInt, TInt &)
IMPORT_C voidJumpToXCoord2(TInt, TInt &)
IMPORT_C voidJumpToYCoord(TInt &, const TInt)
IMPORT_C voidJumpToYCoord2(TInt &, TInt)
IMPORT_C TBoolNextStep(TPoint &)
IMPORT_C TBoolSingleScanline(TPoint &, TPoint &)
IMPORT_C TBoolSingleStep(TPoint &)
Private Member Functions
voidUpdatePosition()
Public Member Enumerations
enumTLineMode { ECenter, ELeft }
Private Member Enumerations
enumTLineStatus { EInitialised, ECurrent, EComplete }
Private Attributes
TRect iBoundingRect
TBool iBoundingRectSet
TInt iCount
TSize iDifference
TPoint iFinish
TInt iGradient
TPoint iInc
TInt16 iInsideX
TInt16 iInsideY
TPoint iPos
TPoint iStart
TLineStatus iStatus

Constructor & Destructor Documentation

TLinearDDA()

IMPORT_CTLinearDDA()

Constructs the default linear DDA.

No start or end point is defined for the line.

TLinearDDA(const TLinearDDA &)

IMPORT_CTLinearDDA(const TLinearDDA &aLine)

Copy constructs a linear DDA from the specified linear DDA.

Parameters

const TLinearDDA & aLineThe linear DDA to be copied.

Member Functions Documentation

Construct(const TPoint &, const TPoint &, TLineMode)

IMPORT_C voidConstruct(const TPoint &aStart,
const TPoint &aFinish,
TLineModeaMode = ECenter
)

Constructs a linear DDA, setting the start and end points of the line.

Parameters

const TPoint & aStartThe start point of the line.
const TPoint & aFinishThe end point of the line.
TLineMode aMode = ECenterThe mode of the line; defaults to centred.

JumpToRect(const TRect &)

IMPORT_C voidJumpToRect(const TRect &aRect)

Jumps to start of a clipping rectangle.

This will accelerate the linear DDA to the vicinity of the specified rectangle. It is NOT guaranteed to reach the rectangle, but will reduce co-ordinates that are 1000's out to co-ordinates that are 10's out. Because of this, failure to intersect the rectangle may not be detected. If it is, or the line has not been constructed or has been run to completion, then a subsequent call to the stepping functions returns ETrue.

Parameters

const TRect & aRectThe rectangle to be jumped to.

JumpToXCoord(const TInt, TInt &)

IMPORT_C voidJumpToXCoord(const TIntaXCoord,
TInt &aYCoord
)

Jumps to x co-ordinate.

The other co-ordinate of the intersection is returned through a reference argument. After a jump call, the line is ready to continue through calls to the stepping functions.

This function accelerates the Linear DDA stepping functions (e.g. SingleStep()) making them return EFalse when they reach the specified co-ordinate. If the line does not cross the co-ordinate, has not been constructed, has been run to completion or the intersection is the end point of the line then the stepping functions will return ETrue.

Parameters

const TInt aXCoordx co-ordinate to jump to
TInt & aYCoordOn return, this parameter holds the y co-ordinate which corresponds to the specified x co-ordinate

JumpToXCoord2(TInt, TInt &)

IMPORT_C voidJumpToXCoord2(TIntaXCoord,
TInt &aYCoord
)

Jumps to x co-ordinate.

This works in the same way as TLinearDDA::JumpToXCoord except that it make sure that using the NextStep function does not return the same value twice.

TLinearDDA::JumpToXCoord(TInt, TInt&)

Parameters

TInt aXCoordx co-ordinate to jump to
TInt & aYCoordOn return, this parameter holds the y co-ordinate which corresponds to the specified x co-ordinate

JumpToYCoord(TInt &, const TInt)

IMPORT_C voidJumpToYCoord(TInt &aXCoord,
const TIntaYCoord
)

Jumps to a y co-ordinate.

The other co-ordinate of the intersection is returned through a reference argument. After a jump call, the line is ready to continue through calls to the stepping functions.

This function accelerates the Linear DDA stepping functions (e.g. SingleStep()) making them return EFalse when they reach the specified co-ordinate. If the line does not cross the co-ordinate, has not been constructed, has been run to completion or the intersection is the end point of the line then they will return ETrue.

Parameters

TInt & aXCoordOn return, this parameter holds the x co-ordinate which corresponds to the specified y co-ordinate.
const TInt aYCoordy co-ordinate to jump to

JumpToYCoord2(TInt &, TInt)

IMPORT_C voidJumpToYCoord2(TInt &aXCoord,
TIntaYCoord
)

Jumps to a y co-ordinate.

This works in the same way as TLinearDDA::JumpToYCoord except that it make sure that using the NextStep function does not return the same value twice.

TLinearDDA::JumpToYCoord(TInt&, TInt)

Parameters

TInt & aXCoordOn return, this parameter holds the x co-ordinate which corresponds to the specified y co-ordinate.
TInt aYCoordy co-ordinate to jump to

NextStep(TPoint &)

IMPORT_C TBoolNextStep(TPoint &aPosition)

Gets the pixel co-ordinates of the start of the next scan line.

The best line that joins the start and end points is formed from all the scan lines returned by this function.

The function is called repeatedly until the start position of all scanlines has been returned.

The start and end points passed to the constructor of this object define the boundaries of the line. Successive scan lines move from the start point to the end point.

Parameters

TPoint & aPositionOn entry to the first call, this can be a reference to any point. On return from the first call, this is the position of the pixel that defines the leftmost position of the first scan line. On return from subsequent calls, this is the position of the pixel that defines the leftmost position of the next scan line. On return from the final call, this is the position of the last pixel in the line, as specified during construction.

SingleScanline(TPoint &, TPoint &)

IMPORT_C TBoolSingleScanline(TPoint &aStartPosition,
TPoint &aEndPosition
)

Gets the start and end pixel co-ordinates that define the next scan line.

The best line that joins the start and end points is formed from all the scan lines returned by this function.

The function is called repeatedly until the position of all scanlines has been returned.

The start and end points passed to the constructor of this object define the boundaries of the line. Successive scan lines move from the start point to the end point.

Parameters

TPoint & aStartPositionOn entry to the first call, this can be a reference to any point. On return from the first call, this is the position of the pixel that defines the leftmost position of the first scan line. On return from subsequent calls, this is the position of the pixel that defines the leftmost position of the next scan line. On return from the final call, either this or aEndPosition is set to the end point, as specified during construction.
TPoint & aEndPositionOn entry to the first call, this can be a reference to any point. On return from the first call, this is the position of the pixel that defines the rightmost position of the first scan line. On return from subsequent calls, this is the position of the pixel that defines the rightmost position of the next scan line. On return from the final call, either this or aStartPosition is set to the end point, as specified during construction.

SingleStep(TPoint &)

IMPORT_C TBoolSingleStep(TPoint &aPosition)

Gets the pixel co-ordinates of the next pixel on the pixel line.

The function is called repeatedly until the whole line has been traversed or, if JumpToRect() has been called, until the part of the line inside the rectangle has been traversed. Note that, for performance reasons, JumpToRect() may fail to detect the intersection of the line with the rectangle accurately and SingleStep() may return more points than strictly necessary.

Parameters

TPoint & aPositionOn entry to the first call, this can be a reference to any point. On return from the first call, this is the position of the first pixel in the line, as specified during construction of this object. On return from subsequent calls, this is the position of subsequent pixels in the line, as calculated by the function. On return from the final call, this is the position of the last pixel in the line, as specified during construction of this object.

UpdatePosition()

voidUpdatePosition()[private]

Member Enumerations Documentation

Enum TLineMode

LDDA Line mode.

Enumerators

ECenter

Centres scan-lines in the pixel line

ELeft

Starts at the beginning of a complete scan line. Used for bitmap scaling.

Enum TLineStatus

Enumerators

EInitialised
ECurrent
EComplete

Member Data Documentation

TRect iBoundingRect

TRect iBoundingRect[private]

TBool iBoundingRectSet

TBool iBoundingRectSet[private]

TInt iCount

TInt iCount[private]

TSize iDifference

TSize iDifference[private]

TPoint iFinish

TPoint iFinish[private]

TInt iGradient

TInt iGradient[private]

TPoint iInc

TPoint iInc[private]

TInt16 iInsideX

TInt16 iInsideX[private]

TInt16 iInsideY

TInt16 iInsideY[private]

TPoint iPos

TPoint iPos[private]

TPoint iStart

TPoint iStart[private]

TLineStatus iStatus

TLineStatus iStatus[private]