WIP
This commit is contained in:
parent
40ffbe9c7c
commit
5038d26bf9
2 changed files with 77 additions and 2 deletions
|
@ -11,6 +11,76 @@ defmodule Vivid.SLPFA do
|
|||
@moduledoc false
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
||||
iex> use Vivid
|
||||
...> frame = Frame.init(16, 16, RGBA.black)
|
||||
...> polygon = Polygon.init([Point.init(1, 1), Point.init(4, 1), Point.init(4, 7), Point.init(11, 7), Point.init(11, 1), Point.init(14, 1), Point.init(14, 14), Point.init(1, 14)])
|
||||
...> Frame.push(frame, polygon, RGBA.white)
|
||||
...> |> to_string
|
||||
" \n" <>
|
||||
" @@@@@@@@@@@@@@ \n" <>
|
||||
" @ @ \n" <>
|
||||
" @ @ \n" <>
|
||||
" @ @ \n" <>
|
||||
" @ @ \n" <>
|
||||
" @ @ \n" <>
|
||||
" @ @ \n" <>
|
||||
" @ @@@@@@@@ @ \n" <>
|
||||
" @ @ @ @ \n" <>
|
||||
" @ @ @ @ \n" <>
|
||||
" @ @ @ @ \n" <>
|
||||
" @ @ @ @ \n" <>
|
||||
" @ @ @ @ \n" <>
|
||||
" @@@@ @@@@ \n" <>
|
||||
" \n"
|
||||
|
||||
iex> use Vivid
|
||||
...> frame = Frame.init(16, 16, RGBA.black)
|
||||
...> polygon = Polygon.init([Point.init(1, 1), Point.init(4, 1), Point.init(4, 7), Point.init(11, 7), Point.init(11, 1), Point.init(14, 1), Point.init(14, 14), Point.init(1, 14)]) |> Vivid.SLPFA.fill |> Group.init
|
||||
...> Frame.push(frame, polygon, RGBA.white)
|
||||
...> |> to_string
|
||||
" \n" <>
|
||||
" \n" <>
|
||||
" @@@@@@@@@@@@ \n" <>
|
||||
" @@@@@@@@@@@@ \n" <>
|
||||
" @@@@@@@@@@@@ \n" <>
|
||||
" @@@@@@@@@@@@ \n" <>
|
||||
" @@@@@@@@@@@@ \n" <>
|
||||
" @@@@@@@@@@@@ \n" <>
|
||||
" @@@@@@@@@@@@ \n" <>
|
||||
" @@ @@ \n" <>
|
||||
" @@ @@ \n" <>
|
||||
" @@ @@ \n" <>
|
||||
" @@ @@ \n" <>
|
||||
" @@ @@ \n" <>
|
||||
" @@ @@ \n" <>
|
||||
" \n"
|
||||
|
||||
iex> use Vivid
|
||||
...> frame = Frame.init(16, 16, RGBA.black)
|
||||
...> polygon = Polygon.init([Point.init(1, 1), Point.init(4, 1), Point.init(4, 7), Point.init(11, 7), Point.init(11, 1), Point.init(14, 1), Point.init(14, 14), Point.init(1, 14)])
|
||||
...> inside = polygon |> Vivid.SLPFA.fill |> Group.init
|
||||
...> Frame.push(frame, polygon, RGBA.white)
|
||||
...> |> Frame.push(inside, RGBA.white)
|
||||
...> |> to_string
|
||||
" \n" <>
|
||||
" @@@@@@@@@@@@@@ \n" <>
|
||||
" @@@@@@@@@@@@@@ \n" <>
|
||||
" @@@@@@@@@@@@@@ \n" <>
|
||||
" @@@@@@@@@@@@@@ \n" <>
|
||||
" @@@@@@@@@@@@@@ \n" <>
|
||||
" @@@@@@@@@@@@@@ \n" <>
|
||||
" @@@@@@@@@@@@@@ \n" <>
|
||||
" @@@@@@@@@@@@@@ \n" <>
|
||||
" @@@@ @@@@ \n" <>
|
||||
" @@@@ @@@@ \n" <>
|
||||
" @@@@ @@@@ \n" <>
|
||||
" @@@@ @@@@ \n" <>
|
||||
" @@@@ @@@@ \n" <>
|
||||
" @@@@ @@@@ \n" <>
|
||||
" \n"
|
||||
"""
|
||||
def fill(%Polygon{vertices: vertices}=polygon) do
|
||||
vertices
|
||||
|> create_edge_table
|
||||
|
@ -57,7 +127,7 @@ defmodule Vivid.SLPFA do
|
|||
active
|
||||
|> Stream.chunk(2)
|
||||
|> Enum.reduce(points, fn [a0, a1], points ->
|
||||
Enum.reduce(a0.x..a1.x, points, fn x, points ->
|
||||
Enum.reduce(a0.x+1..a1.x-1, points, fn x, points ->
|
||||
MapSet.put(points, Point.init(x, y))
|
||||
end)
|
||||
end)
|
||||
|
@ -132,4 +202,4 @@ defmodule Vivid.SLPFA do
|
|||
defp horizontal_line?(_edge_bucket), do: false
|
||||
|
||||
defp sort_by_min_y(%EdgeBucket{y_min: y_min0}, %EdgeBucket{y_min: y_min1}), do: y_min1 > y_min0
|
||||
end
|
||||
end
|
||||
|
|
5
test/vivid/slpfa_test.exs
Normal file
5
test/vivid/slpfa_test.exs
Normal file
|
@ -0,0 +1,5 @@
|
|||
defmodule Vivid.SLPFATest do
|
||||
use ExUnit.Case
|
||||
doctest Vivid.SLPFA
|
||||
end
|
||||
|
Loading…
Reference in a new issue