drawLine
Sets the pixels of a line one pixel wide from column x1 and row y1 to column x2 and row y2 to color, alpha included, as Image.set does. Nothing is blended, so a transparent color clears the pixels the line covers.
Coordinates are in pixels from the image's top-left corner. Both ends are set, and between them the line takes one pixel in each column, or in each row when it is taller than it is wide, picked with Bresenham's algorithm, so its edges are hard. A line drawn from either end sets the same pixels, and a line whose ends are the same pixel sets that pixel. The parts of the line outside the image are left out without changing the pixels inside, and ends far outside cost no more than ends on the edge. Pass the coordinates and color by name.
Samples
val image = Image(8, 8)
image.drawLine(x1 = 0, y1 = 0, x2 = 7, y2 = 3, color = Color.WHITE)
// Both ends are set, with one pixel in each column between them.
assertPrints(image[0, 0], "Color(#ffffffff)")
assertPrints(image[7, 3], "Color(#ffffffff)")
assertPrints(image[7, 0], "Color(#00000000)")
// The part of a line outside the image is left out.
image.drawLine(x1 = -4, y1 = 6, x2 = 20, y2 = 6, color = Color.RED)
assertPrints(image[0, 6], "Color(#ff0000ff)")
assertPrints(image[7, 6], "Color(#ff0000ff)")