Skip to content

Commit 4907c16

Browse files
committed
Merge branch 'milmazz-more_cleanup'
2 parents d171ec5 + e393b42 commit 4907c16

File tree

8 files changed

+57
-68
lines changed

8 files changed

+57
-68
lines changed

lib/scenic/cache.ex

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,16 +302,14 @@ defmodule Scenic.Cache do
302302

303303
# --------------------------------------------------------
304304
defp do_keys(scope) do
305-
:ets.match(@scope_table, {scope, :"$2", :_})
305+
@scope_table
306+
|> :ets.match({scope, :"$2", :_})
306307
|> List.flatten()
307308
end
308309

309310
# --------------------------------------------------------
310311
defp key_in_scope?(scope, key) do
311-
case :ets.match(@scope_table, {scope, key, :_}) do
312-
[] -> false
313-
_ -> true
314-
end
312+
:ets.match(@scope_table, {scope, key, :_}) != []
315313
end
316314

317315
# ============================================================================

lib/scenic/cache/hash.ex

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@ defmodule Scenic.Cache.Hash do
1717
end
1818

1919
# --------------------------------------------------------
20+
@spec valid_hash_types() :: [:ripemd160 | :sha | :sha224 | :sha256 | :sha384 | :sha512, ...]
2021
def valid_hash_types(), do: @hash_types
2122
# --------------------------------------------------------
23+
@spec valid_hash_type?(any()) :: boolean()
2224
def valid_hash_type?(hash_type), do: Enum.member?(@hash_types, hash_type)
2325
# --------------------------------------------------------
26+
@spec valid_hash_type!(any()) :: any() | no_return
2427
def valid_hash_type!(hash_type) do
2528
case Enum.member?(@hash_types, hash_type) do
2629
true ->
@@ -33,9 +36,10 @@ defmodule Scenic.Cache.Hash do
3336
end
3437

3538
# --------------------------------------------------------
39+
@spec binary(any(), any()) :: {:error, :invalid_hash_type} | {:ok, binary()}
3640
def binary(data, hash_type) do
3741
case valid_hash_type?(hash_type) do
38-
true -> {:ok, :crypto.hash(hash_type, data) |> Base.url_encode64(padding: false)}
42+
true -> {:ok, hash_type |> :crypto.hash(data) |> Base.url_encode64(padding: false)}
3943
false -> {:error, :invalid_hash_type}
4044
end
4145
end
@@ -127,7 +131,7 @@ defmodule Scenic.Cache.Hash do
127131
end
128132
end
129133

130-
# --------------------------------------------------------
134+
# --------------------------------------------------------
131135
def verify_file!(path_data), do: path_params(path_data) |> do_verify_file!()
132136

133137
defp do_verify_file!({path, hash, hash_type}) do
@@ -139,7 +143,8 @@ defmodule Scenic.Cache.Hash do
139143

140144
# --------------------------------------------------------
141145
def from_path(path) do
142-
String.split(path, ".")
146+
path
147+
|> String.split(".")
143148
|> List.last()
144149
end
145150

lib/scenic/cache/supervisor.ex

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@ defmodule Scenic.Cache.Supervisor do
1717

1818
# import IEx
1919

20-
# @name :scenic_cache_supervisor
21-
2220
@cache_registry :scenic_cache_registry
2321

2422
# ============================================================================
2523
# setup the viewport supervisor
2624

2725
def start_link() do
28-
# Supervisor.start_link(__MODULE__, :ok, name: @name)
2926
Supervisor.start_link(__MODULE__, :ok)
3027
end
3128

lib/scenic/component/input/dropdown.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ defmodule Scenic.Component.Input.Dropdown do
1111
alias Scenic.Primitive.Style.Theme
1212
import Scenic.Primitives
1313

14-
import IEx
14+
# import IEx
1515

1616
@default_width 160
1717
@default_height 30

lib/scenic/graph.ex

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ defmodule Scenic.Graph do
1717

1818
@root_id :_root_
1919

20-
# defstruct primitives: %{}, ids: %{}, next_uid: 1, add_to: 0
20+
# defstruct primitives: %{}, ids: %{}, next_uid: 1, add_to: 0
2121
defstruct primitives: %{}, ids: %{}, next_uid: 1, add_to: 0
2222

2323
@type t :: %Graph{
@@ -74,9 +74,10 @@ defmodule Scenic.Graph do
7474
graph
7575

7676
max ->
77-
cond do
78-
is_integer(max) && max > 0 -> Map.put(graph, :max_depth, max)
79-
true -> raise Error, message: @err_msg_depth_option
77+
if is_integer(max) && max > 0 do
78+
Map.put(graph, :max_depth, max)
79+
else
80+
raise Error, message: @err_msg_depth_option
8081
end
8182
end
8283
end
@@ -369,8 +370,8 @@ defmodule Scenic.Graph do
369370
# In case I want to reintroduce templates.
370371
# #--------------------------------------------------------
371372
# # insert a template, which is a graph that has relative uids
372-
# # can't just merge the various maps. map the incoming graph into an id space that
373-
# # starts with next_uid, then bump up next_uid to account for everything in the updated graph
373+
# # can't just merge the various maps. map the incoming graph into an id space that
374+
# # starts with next_uid, then bump up next_uid to account for everything in the updated graph
374375
# defp insert_at({%Graph{primitives: p_map, ids: ids, next_uid: next_uid} = graph, parent_uid},
375376
# index,
376377
# %Graph{primitives: t_p_map, ids: t_ids, next_uid: t_next_uid} = t_graph,

lib/scenic/primitive/triangle.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ defmodule Scenic.Primitive.Triangle do
6767
dot12 = Math.Vector2.dot(v1, v2)
6868

6969
# Compute barycentric coordinates
70-
invDenom = 1.0 / (dot00 * dot11 - dot01 * dot01)
71-
u = (dot11 * dot02 - dot01 * dot12) * invDenom
72-
v = (dot00 * dot12 - dot01 * dot02) * invDenom
70+
inv_denom = 1.0 / (dot00 * dot11 - dot01 * dot01)
71+
u = (dot11 * dot02 - dot01 * dot12) * inv_denom
72+
v = (dot00 * dot12 - dot01 * dot02) * inv_denom
7373

7474
# Check if point is in triangle
7575
u >= 0 && v >= 0 && u + v < 1

lib/scenic/view_port/input.ex

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
defmodule Scenic.ViewPort.Input do
1212
@moduledoc false
1313
alias Scenic.Scene
14-
# alias Scenic.Utilities
15-
# alias Scenic.Graph
1614
alias Scenic.ViewPort.Context
1715
alias Scenic.ViewPort
1816
alias Scenic.Primitive
@@ -32,17 +30,14 @@ defmodule Scenic.ViewPort.Input do
3230
| {:cursor_scroll, {offset :: Math.point(), position :: Math.point()}}
3331
| {:cursor_pos, position :: Math.point()}
3432
| {:viewport_enter, position :: Math.point()}
35-
# |
3633
| {:viewport_exit, position :: Math.point()}
37-
# {:viewport_reshape, size :: Math.point}
3834

3935
@type class ::
4036
:codepoint
4137
| :key
4238
| :cursor_button
4339
| :cursor_scroll
4440
| :cursor_pos
45-
# | :viewport_reshape
4641
| :viewport_enter
4742
| :viewport_exit
4843

@@ -86,7 +81,7 @@ defmodule Scenic.ViewPort.Input do
8681

8782
# #--------------------------------------------------------
8883
# # do nothing if the size isn't actually changing
89-
# def handle_cast( {:input, {:viewport_reshape, new_size}}, %{size: old_size} = state )
84+
# def handle_cast( {:input, {:viewport_reshape, new_size}}, %{size: old_size} = state )
9085
# when new_size == old_size do
9186
# {:noreply, state}
9287
# end
@@ -583,18 +578,17 @@ defmodule Scenic.ViewPort.Input do
583578
point = Matrix.project_vector(context.inverse_tx, point)
584579

585580
with {:ok, graph} <- ViewPort.Tables.get_graph(context.graph_key) do
586-
do_find_by_captured_point(
587-
point,
588-
0,
589-
graph,
590-
Matrix.identity(),
591-
Matrix.identity(),
592-
max_depth
593-
)
594-
|> case do
595-
nil -> {nil, nil, point}
596-
out -> out
597-
end
581+
point =
582+
do_find_by_captured_point(
583+
point,
584+
0,
585+
graph,
586+
Matrix.identity(),
587+
Matrix.identity(),
588+
max_depth
589+
)
590+
591+
if point, do: point, else: {nil, nil, point}
598592
else
599593
_ -> {nil, nil, point}
600594
end
@@ -637,12 +631,8 @@ defmodule Scenic.ViewPort.Input do
637631
local_point = Matrix.project_vector(inv_tx, point)
638632

639633
# test if the point is in the primitive
640-
case mod.contains_point?(data, local_point) do
641-
true ->
642-
{uid, p[:id], point}
643-
644-
false ->
645-
nil
634+
if mod.contains_point?(data, local_point) do
635+
{uid, p[:id], point}
646636
end
647637
end
648638
end
@@ -651,7 +641,7 @@ defmodule Scenic.ViewPort.Input do
651641
# find the indicated primitive in the graph given a point in screen coordinates.
652642
# to do this, we need to project the point into primitive local coordinates by
653643
# projecting it with the primitive's inverse final matrix.
654-
#
644+
#
655645
# Since the last primitive drawn is always on top, we should walk the tree
656646
# backwards and return the first hit we find. We could just reduct the whole
657647
# thing and return the last one found (that was my first try), but this is
@@ -729,16 +719,12 @@ defmodule Scenic.ViewPort.Input do
729719
local_point = Matrix.project_vector(inv_tx, {x, y})
730720

731721
# test if the point is in the primitive
732-
case mod.contains_point?(data, local_point) do
733-
true ->
734-
id = p[:id]
735-
# Return the point in graph coordinates. Local was good for the hit test
736-
# but graph coords makes more sense for the graph_key logic
737-
graph_point = Matrix.project_vector(graph_inv_tx, {x, y})
738-
{graph_point, {uid, id, graph_key}, {graph_tx, graph_inv_tx}}
739-
740-
false ->
741-
nil
722+
if mod.contains_point?(data, local_point) do
723+
id = p[:id]
724+
# Return the point in graph coordinates. Local was good for the hit test
725+
# but graph coords makes more sense for the graph_key logic
726+
graph_point = Matrix.project_vector(graph_inv_tx, {x, y})
727+
{graph_point, {uid, id, graph_key}, {graph_tx, graph_inv_tx}}
742728
end
743729
end
744730
end

test/scenic/primitive/group_test.exs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,40 +33,42 @@ defmodule Scenic.Primitive.GroupTest do
3333
assert Primitive.get(g) == [1234]
3434

3535
g =
36-
Group.insert_at(group, -1, 1234)
37-
|> Group.insert_at(-1, 12345)
36+
group
37+
|> Group.insert_at(-1, 1234)
38+
|> Group.insert_at(-1, 12_345)
3839

39-
assert Primitive.get(g) == [1234, 12345]
40+
assert Primitive.get(g) == [1234, 12_345]
4041

4142
g =
42-
Group.insert_at(group, -1, 1234)
43-
|> Group.insert_at(0, 12345)
43+
group
44+
|> Group.insert_at(-1, 1234)
45+
|> Group.insert_at(0, 12_345)
4446

45-
assert Primitive.get(g) == [12345, 1234]
47+
assert Primitive.get(g) == [12_345, 1234]
4648
end
4749

4850
test "delete works" do
4951
g =
5052
Group.build()
5153
|> Group.insert_at(-1, 1234)
52-
|> Group.insert_at(-1, 12345)
54+
|> Group.insert_at(-1, 12_345)
5355

54-
assert Primitive.get(g) == [1234, 12345]
56+
assert Primitive.get(g) == [1234, 12_345]
5557

5658
g = Group.delete(g, 1234)
57-
assert Primitive.get(g) == [12345]
59+
assert Primitive.get(g) == [12_345]
5860
end
5961

6062
test "increment_data adds a constant to the child ids" do
6163
g =
6264
Group.build()
6365
|> Group.insert_at(-1, 1234)
64-
|> Group.insert_at(-1, 12345)
66+
|> Group.insert_at(-1, 12_345)
6567

66-
assert Primitive.get(g) == [1234, 12345]
68+
assert Primitive.get(g) == [1234, 12_345]
6769

6870
g = Group.increment(g, 10)
69-
assert Primitive.get(g) == [1244, 12355]
71+
assert Primitive.get(g) == [1244, 12_355]
7072
end
7173

7274
# ============================================================================

0 commit comments

Comments
 (0)