Skip to content

Commit d74fb0e

Browse files
committed
cleanup typspec warnings and errors from dialyzer
1 parent a3c3e30 commit d74fb0e

File tree

3 files changed

+32
-22
lines changed

3 files changed

+32
-22
lines changed

lib/scenic/math.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ defmodule Scenic.Math do
2424
@type triangle :: {p0 :: point, p1 :: point, p2 :: point}
2525
@type quad :: {p0 :: point, p1 :: point, p2 :: point, p3 :: point}
2626

27-
@type matrix :: <<_::64>>
27+
@type matrix :: binary()
2828

2929
@type matrix_list :: list(number)
3030
end

lib/scenic/math/matrix.ex

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,10 @@ defmodule Scenic.Math.Matrix do
199199
"""
200200
@spec build_translation(vector_2 :: Math.vector_2()) :: Math.matrix()
201201
def build_translation(vector_2)
202-
def build_translation({x, y}), do: build_translation({x, y, 0.0})
202+
def build_translation({x, y}), do: do_build_translation({x, y, 0.0})
203203
# def build_translation({x, y, z}), do: build_translation(x, y, z)
204204
# def build_translation(x, y), do: build_translation(x, y, 0.0)
205-
def build_translation({x, y, z}) do
205+
defp do_build_translation({x, y, z}) do
206206
<<
207207
1.0::float-size(32)-native,
208208
0.0::float-size(32)-native,
@@ -235,11 +235,11 @@ defmodule Scenic.Math.Matrix do
235235
"""
236236
@spec build_scale(scale :: number | Math.vector_2()) :: Math.matrix()
237237
def build_scale(scale)
238-
def build_scale(s) when is_number(s), do: build_scale({s, s, s})
239-
def build_scale({x, y}), do: build_scale({x, y, 1.0})
238+
def build_scale(s) when is_number(s), do: do_build_scale({s, s, s})
239+
def build_scale({x, y}), do: do_build_scale({x, y, 1.0})
240240
# def build_scale({x, y, z}), do: build_scale(x, y, z)
241241
# def build_scale(x, y), do: build_scale(x, y, 1.0)
242-
def build_scale({x, y, z}) do
242+
defp do_build_scale({x, y, z}) do
243243
<<
244244
x * 1.0::float-size(32)-native,
245245
0.0::float-size(32)-native,
@@ -394,13 +394,15 @@ defmodule Scenic.Math.Matrix do
394394
Returns:
395395
A binary matrix
396396
"""
397-
@spec rotate(matrix :: number, pin :: Math.point() | nil) :: Math.matrix()
397+
@spec rotate(matrix :: Math.matrix(), angle :: number | nil) :: Math.matrix()
398398
def rotate(matrix, angle)
399399
def rotate(matrix, nil), do: matrix
400400

401-
def rotate(matrix, amount) do
402-
build_rotation(amount)
403-
|> (&Matrix.mul(matrix, &1)).()
401+
def rotate(matrix, angle) do
402+
Matrix.mul(
403+
matrix,
404+
build_rotation(angle)
405+
)
404406
end
405407

406408
# def rotate( matrix, radians, axis ) when is_atom(axis) do
@@ -419,13 +421,15 @@ defmodule Scenic.Math.Matrix do
419421
Returns:
420422
A binary matrix
421423
"""
422-
@spec translate(matrix :: number, vector_2 :: Math.vector_2() | nil) :: Math.matrix()
424+
@spec translate(matrix :: Math.matrix(), vector_2 :: Math.vector_2() | nil) :: Math.matrix()
423425
def translate(matrix, vector_2)
424426
def translate(matrix, nil), do: matrix
425427

426428
def translate(matrix, {x, y}) do
427-
build_translation({x, y})
428-
|> (&Matrix.mul(matrix, &1)).()
429+
Matrix.mul(
430+
matrix,
431+
build_translation({x, y})
432+
)
429433
end
430434

431435
# def translate(matrix, {x, y, z}), do: translate(matrix, x, y, z)
@@ -444,12 +448,17 @@ defmodule Scenic.Math.Matrix do
444448
Returns:
445449
A binary matrix
446450
"""
447-
@spec scale(matrix :: number, scale :: number | Math.vector_2() | nil) :: Math.matrix()
451+
@spec scale(matrix :: Math.matrix(), scale :: number | Math.vector_2() | nil) :: Math.matrix()
448452
def scale(matrix, scale)
449453
def scale(matrix, nil), do: matrix
450454
# def scale(matrix, {x, y}), do: scale(matrix, {x, y})
451455
# def scale(matrix, {x, y, z}), do: scale(matrix,{ x, y, z})
452-
def scale(matrix, s), do: build_scale(s) |> (&Matrix.mul(matrix, &1)).()
456+
def scale(matrix, s) do
457+
Matrix.mul(
458+
matrix,
459+
build_scale(s)
460+
)
461+
end
453462
# def scale(matrix, x, y), do: build_scale(x, y) |> (&Matrix.mul(matrix, &1)).()
454463
# def scale(matrix, x, y, z), do: build_scale(x, y, z) |> (&Matrix.mul(matrix, &1)).()
455464

@@ -468,7 +477,7 @@ defmodule Scenic.Math.Matrix do
468477
Returns:
469478
A number
470479
"""
471-
@spec get(matrix :: number, x :: number, y :: number) :: number
480+
@spec get(matrix :: Math.matrix(), x :: number, y :: number) :: number
472481
def get(matrix, x, y)
473482

474483
def get(matrix, x, y)
@@ -497,7 +506,7 @@ defmodule Scenic.Math.Matrix do
497506
Returns:
498507
A number
499508
"""
500-
@spec put(matrix :: number, x :: number, y :: number, v :: number) :: Math.matrix()
509+
@spec put(matrix :: Math.matrix, x :: number, y :: number, v :: number) :: Math.matrix()
501510
def put(matrix, x, y, v)
502511
def put(matrix, x, y, v) when is_integer(v), do: put(matrix, x, y, v * 1.0)
503512

@@ -529,7 +538,7 @@ defmodule Scenic.Math.Matrix do
529538
Returns:
530539
A vector_2
531540
"""
532-
@spec get_xy(matrix :: number) :: Math.vector_2()
541+
@spec get_xy(matrix :: Math.matrix) :: Math.vector_2()
533542
def get_xy(matrix)
534543

535544
def get_xy(<<
@@ -660,7 +669,7 @@ defmodule Scenic.Math.Matrix do
660669
Returns:
661670
The resulting matrix
662671
"""
663-
@spec mul(matrix :: Math.matrix(), multiplier :: number | Math.matrix()) :: Math.matrix()
672+
@spec mul(matrix :: Math.matrix(), multiplier :: (number | Math.matrix())) :: Math.matrix()
664673

665674
def mul(matrix, multiplier)
666675
def mul(a, s) when is_integer(s), do: mul(a, s * 1.0)
@@ -693,7 +702,7 @@ defmodule Scenic.Math.Matrix do
693702
Returns:
694703
The resulting matrix
695704
"""
696-
@spec mul(matrix :: Math.matrix(), divisor :: number) :: Math.matrix()
705+
@spec div(matrix :: Math.matrix(), divisor :: number) :: Math.matrix()
697706
def div(matrix, scalar)
698707
def div(a, s) when is_integer(s), do: Matrix.div(a, s * 1.0)
699708

lib/scenic/math/vector_2.ex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ defmodule Scenic.Math.Vector2 do
1212
{3.5, 4.7}
1313
"""
1414

15+
alias Scenic.Math
1516
alias Scenic.Math.Vector2
1617
alias Scenic.Math.Matrix
1718

@@ -353,7 +354,7 @@ defmodule Scenic.Math.Vector2 do
353354
Returns:
354355
true or false
355356
"""
356-
@spec in_bounds?(vector :: Math.vector_2(), bounds :: Math.vector_2()) :: Math.vector_2()
357+
@spec in_bounds?(vector :: Math.vector_2(), bounds :: Math.vector_2()) :: boolean
357358
def in_bounds?(vector, bounds)
358359

359360
def in_bounds?({vx, vy}, {boundsx, boundsy}),
@@ -373,7 +374,7 @@ defmodule Scenic.Math.Vector2 do
373374
A vector derived from the the space between two other vectors
374375
"""
375376
@spec in_bounds?(vector :: Math.vector_2(), min :: Math.vector_2(), max :: Math.vector_2()) ::
376-
Math.vector_2()
377+
boolean
377378
def in_bounds?(vector, min, max)
378379

379380
def in_bounds?({vx, vy}, {minx, miny}, {maxx, maxy}),

0 commit comments

Comments
 (0)