Skip to content
snap_to_pixel_center

snap_to_pixel_center

Mojo function 🡭

snap_to_pixel_center

fn def snap_to_pixel_center(value: Float64) -> Float64

value moved to the nearest pixel center, for the fixed coordinate of a hairline.

The counterpart of snap_to_pixel_edge. A one-pixel line is drawn about its centerline, so it covers exactly one row when that centerline is a whole number and spreads across two half-covered rows when it is not. A rectangle snaps to a boundary because it is bounded by its edges; a line snaps to a center because it is centered on its coordinate. Rounds as round_to_int does, halves away from zero, so a line and a marker at the same coordinate land on the same pixel.

Args:

  • value (Float64): A user-space coordinate.

Returns:

Float64: The nearest whole number, as a Float64.