123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172(* Taffy uses two coordinate systems to refer to grid lines (the gaps/gutters
between rows/columns) *)openGeometryopenStyletypegrid_line=int(* Represents a grid line position in "CSS Grid Line" coordinates *)(* Create a grid line from an integer value *)letgrid_linei=ifi=0thenfailwith"Grid line of zero is invalid"elsei(* Returns the underlying integer *)letgrid_line_to_intgl=gltypeorigin_zero_line=int(* Represents a grid line position in "OriginZero" coordinates *)(* Convert into OriginZero coordinates using the specified explicit track
count *)letgrid_line_to_origin_zero_lineglexplicit_track_count=letexplicit_line_count=explicit_track_count+1inifgl>0thengl-1elseifgl<0thengl+explicit_line_countelsefailwith"Grid line of zero is invalid"(* Converts a grid line in OriginZero coordinates into the index of that same
grid line in the GridTrackVec. This fallible version is used for the
placement of absolutely positioned grid items *)lettry_origin_zero_line_to_track_vec_indexozltrack_counts=(* OriginZero grid line cannot be less than the number of negative grid
lines *)ifozl<-track_counts.Grid.negative_implicitthenNone(* OriginZero grid line cannot be more than the number of positive grid
lines *)elseifozl>track_counts.Grid.explicit+track_counts.Grid.positive_implicitthenNoneelseSome(2*(ozl+track_counts.Grid.negative_implicit))(* Converts a grid line in OriginZero coordinates into the index of that same
grid line in the GridTrackVec *)letorigin_zero_line_to_track_vec_indexozltrack_counts=matchtry_origin_zero_line_to_track_vec_indexozltrack_countswith|Someidx->idx|None->ifozl>0thenfailwith"OriginZero grid line cannot be more than the number of positive \
grid lines"elsefailwith"OriginZero grid line cannot be less than the number of negative \
grid lines"(* The minimum number of negative implicit tracks there must be if a grid item
starts at this line *)letorigin_zero_line_implied_negative_implicit_tracksozl=ifozl<0thenabsozlelse0(* The minimum number of positive implicit tracks there must be if a grid item
ends at this line *)letorigin_zero_line_implied_positive_implicit_tracksozlexplicit_track_count=ifozl>explicit_track_countthenozl-explicit_track_countelse0(* The number of tracks between the start and end lines *)letline_spanline=max(line.Line.end_-line.start)0(* Comparison function for origin zero lines *)letcompare_origin_zero_line=Int.compare(* Equality function for origin zero lines *)letequal_origin_zero_line=Int.equal