# FUNCTION

# Public

# CELLS-SWEEP (STATE FUNCTION &OPTIONAL FUNCTION-SPAN)

Call FUNCTION for each pixel on the polygon described by
previous call to LINE or LINE-F. The pixels are scanned in
increasing Y, then on increasing X.
For optimization purpose, the optional FUNCTION-SPAN, if
provided, is called for a full span of identical alpha pixel. If
not provided, a call is made to FUNCTION for each pixel in the
span.

# CELLS-SWEEP/RECTANGLE (STATE X1 Y1 X2 Y2 FUNCTION &OPTIONAL FUNCTION-SPAN)

Call FUNCTION for each pixel on the polygon described by
previous call to LINE or LINE-F. The pixels are scanned in
increasing Y, then on increasing X. This is limited to the
rectangle region specified with (X1,Y1)-(X2,Y2) (where X2 must be
greater than X1 and Y2 must be greater than Y1, to describe a
non-empty region.)
For optimization purpose, the optional FUNCTION-SPAN, if
provided, is called for a full span of identical alpha pixel. If
not provided, a call is made to FUNCTION for each pixel in the
span.

# FREEZE-STATE (STATE)

Freeze the state and return a list of scanlines. A scanline is
an object which can be examined with SCANLINE-Y and processed
with SCANLINE-SWEEP.

# LINE (STATE X1 Y1 X2 Y2)

Draw a line from (X1,Y1) to (X2,Y2). All coordinates are
integers with subpixel accuracy (a pixel width is given by
+CELL-WIDTH+.) The line must be part of a closed polygon.

# LINE-F (STATE X1 Y1 X2 Y2)

Draw a line, whose coordinates are translated to fixed-point
as expected by function LINE. This is a convenient function to
not depend on +CELL-WIDTH+.

# SCANLINE-SWEEP

Call FUNCTION for each pixel on the polygon covered by
SCANLINE. The pixels are scanned in increasing X. The sweep can
be limited to a range by START (included) or/and END (excluded).

# SCANLINE-Y (SCANLINE)

Get the Y position of SCANLINE.

# STATE-RESET (STATE)

Reset the state, losing all accumulated cells. It can be
faster or less memory consuming to reset a state and reuse it,
rather than creating a new state.

# Undocumented

# MAKE-STATE (&KEY ((CURRENT-CELL DUM279) (MAKE-CELL)) ((CELLS DUM280) NIL) ((SCANLINES DUM281) NIL) ((END-OF-LINES DUM282) NIL) ((DROPPED-CELLS DUM283) NIL) ((RECYCLING-CELLS DUM284) (CONS NIL NIL)))

# Private

# CELL-AREA (INSTANCE)

@arg[extid]{A @class{extid}}
@return[sytemid]{puri:uri or nil}
Returns the System ID part of this External ID.

# CELL-COVER (INSTANCE)

@arg[extid]{A @class{extid}}
@return[sytemid]{puri:uri or nil}
Returns the System ID part of this External ID.

# CELL-EMPTY-P (CELL)

Test if the cell is empty. A cell is empty when COVER and AREA
are both zero.

# CELL-RESET (CELL)

Reset the cell such that CELL-EMPTY-P is true.

# CELL-X (INSTANCE)

@arg[extid]{A @class{extid}}
@return[sytemid]{puri:uri or nil}
Returns the System ID part of this External ID.

# CELL-Y (INSTANCE)

# COMPARE-CELLS (A B)

Compare coordinates between 2 cells. Used to sort cells by Y,
then by X.

# COMPUTE-ALPHA (COVER AREA)

Compute the alpha value given the accumulated cover and the
actual area of a cell.

# MAP-GRID-SPANS (FUNCTION X1 Y1 X2 Y2)

Call FUNCTION for each segments of the line from (X1,Y1)
to (X2,Y2) cut by a grid with spacing +CELL-WIDTH+.

# MAP-LINE-SPANS (FUNCTION A1 B1 A2 B2)

Call FUNCTION for each segment of a line with integer
coordinates (A1,B1)-(A2,B2) cut by a grid of spacing
+CELL-WIDTH+.

# SET-CURRENT-CELL (STATE X Y)

Ensure current cell is one at coordinate X and Y. If not,
the current cell is stored, then reset accordingly to new
coordinate.
Returns the current cell.

# STATE-CELLS (INSTANCE)

# STATE-CURRENT-CELL (INSTANCE)

# STATE-DROPPED-CELLS (INSTANCE)

# STATE-END-OF-LINES (INSTANCE)

# STATE-FINALIZE (STATE)

Finalize the state.

# STATE-PUSH-CELL (STATE CELL)

Store a copy of the current cell into the cells list. If the
state was reset, possibly reuse previous cells.

# STATE-RECYCLING-CELLS (INSTANCE)

# STATE-SCANLINES (INSTANCE)

# STATE-SORT-CELLS (STATE)

Sort the cells by Y, then by X.

# UPDATE-CELL (CELL FX1 FY1 FX2 FY2)

Update COVER and AREA given a segment inside the corresponding
cell. FX1, FY1, FX2 and FY2 must be subpixel coordinates between
0 and +CELL-WIDTH+ included.

# Undocumented

# SETFCELL-AREA (NEW-VALUE INSTANCE)

# SETFCELL-COVER (NEW-VALUE INSTANCE)

# CELL-P (OBJECT)

# SETFCELL-X (NEW-VALUE INSTANCE)

# SETFCELL-Y (NEW-VALUE INSTANCE)

# COPY-CELL (INSTANCE)

# COPY-STATE (INSTANCE)

# MAKE-CELL (&KEY ((X DUM178) 0) ((Y DUM179) 0) ((COVER DUM180) 0) ((AREA DUM181) 0))

# SETFSTATE-CELLS (NEW-VALUE INSTANCE)

# SETFSTATE-CURRENT-CELL (NEW-VALUE INSTANCE)

# SETFSTATE-DROPPED-CELLS (NEW-VALUE INSTANCE)

# SETFSTATE-END-OF-LINES (NEW-VALUE INSTANCE)

# STATE-P (OBJECT)

# SETFSTATE-RECYCLING-CELLS (NEW-VALUE INSTANCE)

# SETFSTATE-SCANLINES (NEW-VALUE INSTANCE)

# CLASS

# Private

# CELL

A cell used to represent the partial area covered by a line
passing by a corresponding pixel. The cell alone doesn't hold all
the information to calculate the area.

# STATE

AA state. Hold all the cells generated when drawing lines.

# CONSTANT

# Private

# +ALPHA-DIVISOR+

Constant used to translate value computed by AREA and COVER to
an alpha value.

# +ALPHA-RANGE+

For non overlapping polygons, the alpha value will be in the
range (-limit,limit) where limit is +alpha-range+. The value is
negative or positive accordingly to the polygon
orientation (clockwise or counter-clockwise.)

# +CELL-WIDTH+

A cell represent a pixel square, and the width is the
fractional part of the fixed-point coordinate. A large value
increase precision. 256 should be enough though. Note that
smaller value should NOT increase performance.