1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980(* Stores the number of tracks in a given dimension. Stores separately the
number of tracks in the implicit and explicit grids
Taffy uses two coordinate systems to refer to grid tracks (rows/columns):
Both of these systems represent the entire implicit grid, not just the
explicit grid.
"CellOccupancyMatrix track indices": - These are indexes into the
CellOccupancyMatrix - The CellOccupancyMatrix stores only tracks - 0 is the
leftmost track of the implicit grid, and indexes count up there
"GridTrackVec track indices": - The GridTrackVecs store both lines and
tracks, so: - even indices (0, 2, 4, etc) represent lines - odd indices (1,
3, 5, etc) represent tracks - There is always an odd number of elements -
Index 1 is the leftmost track of the implicit grid. Index 3 is the second
leftmost track, etc. - Index 0 is the leftmost grid line. Index 2 is the
second leftmost line, etc. *)openGeometryopenStyletypet=Grid.track_counts(* Create a track counts instance from raw track count numbers *)letmake~negative_implicit~explicit~positive_implicit=Grid.{negative_implicit;explicit;positive_implicit}(* Count the total number of tracks in the axis *)letlent=t.Grid.negative_implicit+t.Grid.explicit+t.Grid.positive_implicit(* Get the number of negative implicit tracks *)letnegative_implicitt=t.Grid.negative_implicit(* Get the number of explicit tracks *)letexplicitt=t.Grid.explicit(* Get the number of positive implicit tracks *)letpositive_implicitt=t.Grid.positive_implicit(* The OriginZeroLine representing the start of the implicit grid *)letimplicit_start_linet=-t.Grid.negative_implicit(* The OriginZeroLine representing the end of the implicit grid *)letimplicit_end_linet=t.Grid.explicit+t.Grid.positive_implicit(* Converts a grid line in OriginZero coordinates into the track immediately
following that grid line as an index into the CellOccupancyMatrix *)letoz_line_to_next_tracktindex=index+t.Grid.negative_implicit(* Converts start and end grid lines in OriginZero coordinates into a range of
tracks as indexes into the CellOccupancyMatrix *)letoz_line_range_to_track_rangetinput=letopenLineinletstart=oz_line_to_next_tracktinput.startinletend_=oz_line_to_next_tracktinput.end_in(* Don't subtract 1 as output range is exclusive *)(start,end_)(* Converts a track as an index into the CellOccupancyMatrix into the grid line
immediately preceding that track in OriginZero coordinates *)lettrack_to_prev_oz_linetindex=index-t.Grid.negative_implicit(* Converts a range of tracks as indexes into the CellOccupancyMatrix into start
and end grid lines in OriginZero coordinates *)lettrack_range_to_oz_line_ranget(start,end_)=letstart=track_to_prev_oz_linetstartinletend_=track_to_prev_oz_linetend_in(* Don't add 1 as input range is exclusive *)Line.makestartend_(* Converts an OriginZero grid line into a track index for the
CellOccupancyMatrix, or None if the line is outside the grid *)letoz_line_to_trackt(line:int):intoption=lettrack_index=line+t.Grid.negative_implicitiniftrack_index<0||track_index>=lentthenNoneelse(* Multiply by 2 to account for gutters - each line maps to an even index *)Some(2*track_index)