-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42f11b5
commit ab738f8
Showing
6 changed files
with
91 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
defmodule Mudbrick.ContentStream.L do | ||
@enforce_keys :coords | ||
defstruct [:coords] | ||
|
||
defimpl Mudbrick.Object do | ||
def from(%Mudbrick.ContentStream.L{coords: {x, y}}) do | ||
Enum.map_intersperse([x, y, "l"], " ", &to_string/1) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
defmodule Mudbrick.ContentStream.M do | ||
@enforce_keys :coords | ||
defstruct [:coords] | ||
|
||
defimpl Mudbrick.Object do | ||
def from(%Mudbrick.ContentStream.M{coords: {x, y}}) do | ||
Enum.map_intersperse([x, y, "m"], " ", &to_string/1) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
defmodule Mudbrick.ContentStream.S do | ||
defstruct [] | ||
|
||
defimpl Mudbrick.Object do | ||
def from(_op) do | ||
["S"] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
defmodule Mudbrick.Drawing do | ||
defstruct lines: [] | ||
|
||
def new() do | ||
struct!(__MODULE__, []) | ||
end | ||
defstruct paths: [] | ||
|
||
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) | ||
def new(opts) do | ||
struct!(__MODULE__, opts) | ||
end | ||
end | ||
|
||
def new() do | ||
struct!(__MODULE__, []) | ||
end | ||
|
||
def path(drawing, opts) do | ||
%{drawing | paths: [Path.new(opts) | drawing.paths]} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,23 @@ | ||
defmodule Mudbrick.Drawing.Output do | ||
defstruct operations: [] | ||
|
||
def from(_) do | ||
%__MODULE__{} | ||
alias Mudbrick.ContentStream.{ | ||
L, | ||
M, | ||
S | ||
} | ||
|
||
def from(%Mudbrick.Drawing{} = drawing) do | ||
for path <- Enum.reverse(drawing.paths), reduce: %__MODULE__{} do | ||
acc -> | ||
acc | ||
|> add(%M{coords: path.from}) | ||
|> add(%L{coords: path.to}) | ||
|> add(%S{}) | ||
end | ||
end | ||
|
||
def add(%__MODULE__{} = output, op) do | ||
%{output | operations: [op | output.operations]} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters