% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/R-trajectory.R
\name{bresenham_line}
\alias{bresenham_line}
\title{Rasterize a line between two points using Bresenham's algorithm}
\usage{
bresenham_line(p0, p1, snap = TRUE)
}
\arguments{
\item{p0}{A `data.frame` with at least columns `x` and `y`. If it contains
multiple rows, only the first row is used.}

\item{p1}{A `data.frame` with at least columns `x` and `y`. If it contains
multiple rows, only the first row is used.}

\item{snap}{Logical; if `TRUE` (default), `p0` and `p1` coordinates are
rounded
to the nearest integer before running the algorithm. If `FALSE`, coordinates
  are truncated via `as.integer()`.}
}
\value{
A `data.frame` with columns `x` and `y` giving the integer grid
points visited by the line, including both endpoints, in traversal order from `p0`
to `p1`.
}
\description{
Generates integer grid coordinates along the line segment connecting two
points
using Bresenham's line algorithm.
}
\details{
The function:
\itemize{
\item Validates inputs are data frames with `x`/`y` columns and at least one
row.
\item Converts endpoints to integer coordinates (optionally rounding first).
  \item Applies the classic Bresenham algorithm to enumerate grid points.
}

This is useful for tracing discrete paths on an integer lattice (e.g.,
pixels, tile grids, spatial transcriptomics spot grids).
}
\examples{
p0 <- data.frame(x = 1.2, y = 2.7)
p1 <- data.frame(x = 7.9, y = 5.1)

# Default (snap = TRUE): rounds endpoints first
bresenham_line(p0, p1)

# No rounding (snap = FALSE): integer coercion truncates toward zero
bresenham_line(p0, p1, snap = FALSE)

}
