Skip to content

Commit

Permalink
Vector drawing bootstrapping
Browse files Browse the repository at this point in the history
  • Loading branch information
camelpunch committed Oct 31, 2024
1 parent 0e59ed5 commit 42f11b5
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 4 deletions.
18 changes: 18 additions & 0 deletions lib/mudbrick/drawing.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
defmodule Mudbrick.Drawing do
defstruct lines: []

def new() do
struct!(__MODULE__, [])
end

defmodule Path do
@enforce_keys [:from, :to]
defstruct [:from, :to]

def new(drawing, opts) do
Map.update!(drawing, :lines, fn lines ->
[struct!(__MODULE__, opts) | lines]
end)
end
end
end
7 changes: 7 additions & 0 deletions lib/mudbrick/drawing/output.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
defmodule Mudbrick.Drawing.Output do
defstruct operations: []

def from(_) do
%__MODULE__{}
end
end
21 changes: 21 additions & 0 deletions test/mudbrick/drawing_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
defmodule Mudbrick.DrawingTest do
use ExUnit.Case, async: true

import Mudbrick.TestHelper, only: [output: 2]

alias Mudbrick.Drawing

test "can make an empty line drawing" do
assert [] =
output(fn ->
Drawing.new()
end)
|> operations()
end

defp output(f), do: output(fn _ -> f.() end, Mudbrick.Drawing.Output)

defp operations(ops) do
Enum.map(ops, &Mudbrick.TestHelper.show/1)
end
end
4 changes: 3 additions & 1 deletion test/mudbrick/text_block_test.exs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Mudbrick.TextBlockTest do
use ExUnit.Case, async: true

import Mudbrick.TestHelper, only: [output: 1]
import Mudbrick.TestHelper, only: [output: 2]

alias Mudbrick.TextBlock
alias Mudbrick.TextBlock.Line
Expand Down Expand Up @@ -283,6 +283,8 @@ defmodule Mudbrick.TextBlockTest do
end
end

defp output(f), do: output(f, Mudbrick.TextBlock.Output)

defp operations(ops) do
Enum.map(ops, &Mudbrick.TestHelper.show/1)
end
Expand Down
5 changes: 2 additions & 3 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ defmodule Mudbrick.TestHelper do
@example_png Path.join(__DIR__, "fixtures/Example.png") |> File.read!()

alias Mudbrick.Page
alias Mudbrick.TextBlock.Output

def show(o) do
Mudbrick.Object.from(o) |> to_string()
Expand Down Expand Up @@ -38,7 +37,7 @@ defmodule Mudbrick.TestHelper do
@example_png
end

def output(f) when is_function(f) do
def output(f, output_mod) when is_function(f) do
import Mudbrick

{doc, _contents_obj} =
Expand All @@ -65,7 +64,7 @@ defmodule Mudbrick.TestHelper do
}
})

ops = Output.from(block).operations
ops = output_mod.from(block).operations

context
|> Mudbrick.ContentStream.put(operations: ops)
Expand Down

0 comments on commit 42f11b5

Please sign in to comment.