*Input*: End points of [[Line Segment]] $l$, $p_0$, $p_1$, where $l \in \Rn2$, where $l \in \Rn2$.
>[!note] These end points are not required to be [[Pixel]] aligned.
$\let (i_\op{min}, j_\op{min})$ be the pixel coordinate of $(x_0,y_{0})$
$\let (i_\op{max}, j_\op{max})$ be the pixel coordinate of $(x_1,y_{1})$
$\huge
\begin{align}
i_{\op{min}} &= \op{round}(x_{0})\\
i_{\op{max}} &= \op{round}(x_{1})\\
\end{align}
$
To [[Rasterization|Rasterize]] the image you can iterate through all the [[Pixel]] $x$-values $\in\ba{i_{\op{min}}, i_{\op{max}}}$, and then compute the height of the [[Line]] for every $x$ value to get the pixel $(x, \op{round}(y(x))$.
$\huge \begin{align}
y(i) &= y_{0} + m(i - x_{0})
\end{align}$
The slope of the input [[Line Segment]]:
$\huge m = \frac{y_{1} - y_{0}}{x_{1}-x_{0}}$
>[!tip]
> If the given slope $m > 1$, that means the line is steep enough so that different values of $y(i)$ may jump discontinuously.
>
> To prevent this happening, you can repeat this same process except scanning along the $y$ axis.
$\huge \begin{align}
\let {l} &\in \Rn{2} \text{ be a Line} \\
l_{0} &= (x_{0}, y_{0})\\
l_{1} &= (x_{1}, y_{1})\\
m &= \frac{y_{1}-y_{0}}{x_{1}-x_{0}} \\
i_{\op{min}} &= \begin{cases}
x_{0} & |m| \le 1 \\
y_{0} & |m| \ge 1 \\
\end{cases}\\
i_{\op{max}} &= \begin{cases}
x_{1} & |m| \le 1 \\
y_{1} & |m| \ge 1 \\
\end{cases}\\
\end{align}
$
```rust
fn rasterize(raster: Raster, line: LineSegment) {
let p0 = line.start;
let p1 = line.end;
let mut slope = (p1.y - p0.y) / (p1.x - p0.x);
let (i_min, i_max, j_min) = if slope.abs() > 1 {
slope = 1. / slope;
(p0.y, p1.y, p0.x)
} else {
(p0.x, p1.x, p1.y)
};
let slope = slope;
for i in i_min..i_max {
let j =
}
}
```