Integer Implementation
DEF COMPACT(X0%, Y0%, X1%, Y1%, MXW%, MXH%)
DIM C0% = Y0%*MXW% + X0%
DIM C1% = Y1%*MXW% + X1%
DIM C2% = C1%*MXW%*MXH% + C0%
RETURN C2%
END
DEF EXTRACT C2%, MXW%, MXH% OUT X0%, Y0%, X1%, Y1%
DIM C0% = C2% MOD MXW%*MXH%
DIM C1% = C2% DIV MXW%*MXH%
X0% = C0% MOD MXW%
Y0% = C0% DIV MXW%
X1% = C1% MOD MXW%
Y1% = C1% DIV MXW%
END
Floating-Point Implementation
DEF COMPACT(X0#, Y0#, X1#, Y1#, MXW#, MXH#)
DIM C0# = Y0#*MXW# + X0#
DIM C1# = Y1#*MXW# + X1#
DIM C2# = C1#*MXW#*MXH# + C0#
RETURN C2#
END
DEF EXTRACT C2#, MXW#, MXH# OUT X0#, Y0#, X1#, Y1#
DIM C0# = C2#-(MXW#*MXH#)*FLOOR(C2#/(MXW#*MXH#))
DIM C1# = FLOOR(C2#/(MXW#*MXH#))
X0# = C0#-MXW#*FLOOR(C0#/MXW#)
Y0# = FLOOR(C0#/MXW#)
X1# = C1#-MXW#*FLOOR(C1#/MXW#)
Y1# = FLOOR(C1#/MXW#)
END
What these functions essentially do is performing mathematical steps to re-represent the given data.
COMPACT receives two sets of x-y coordinates (x0, y0, x1, y1) and converts them into a single value which may be stored, and perhaps later passed through
EXTRACT, where it retrieves the original two sets of x-y coordinates given that it has the original
MXW (maximum width [highest allowed x-value]) and
MXH (maximum height [highest allowed y-value]). For the integer method of this, the highest values for
MXW and
MXH are
{320-1, 145} and
{320, 145-1}. For the floating-point method, these values are untested.