Crate clipline

source ·
Expand description

Efficient scan conversion (rasterization) of line segments with clipping to a rectangular window.

The key advantage of clipline over vanilla Bresenham is that it eliminates the need for bounds checking on every pixel, which speeds up line drawing. Furthermore, the clipping uses integer arithmetic, producing pixel-perfect endpoints. This sets it apart from floating-point clipping algorithms like Cohen-Sutherland, which may distort the line due to rounding errors.

Usage

This crate provides two ways of performing scan conversion: the clipline function, and the Clipline iterator. The former is slightly more optimized, the latter allows external iteration. Both methods can be toggled with the func and iter features (both enabled by default).

Structs

Enums

  • Enum representing the different variants of clipped line segment iterators.

Traits

  • The absolute difference operation.
  • Provides constants for 0, 1 and 2.

Functions

  • Performs scan conversion of a line segment using Bresenham’s algorithm, while clipping it to a specified rectangle.