Skip to content

Commit 0b6b4b2

Browse files
authored
Merge pull request #313 from seb3s/patch-5
clean centroid & default_pin code
2 parents 4da2346 + 0acf473 commit 0b6b4b2

File tree

5 files changed

+17
-44
lines changed

5 files changed

+17
-44
lines changed

lib/scenic/primitive/line.ex

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,11 @@ defmodule Scenic.Primitive.Line do
9393

9494
# --------------------------------------------------------
9595
def default_pin(data), do: centroid(data)
96+
def default_pin(data, _styles), do: centroid(data)
9697

9798
# --------------------------------------------------------
9899
@doc """
99-
Returns a the midpoint of the line. This is used as the default pin when applying
100+
Returns the midpoint of the line. This is used as the default pin when applying
100101
rotate or scale transforms.
101102
"""
102103
def centroid(data)
@@ -116,13 +117,4 @@ defmodule Scenic.Primitive.Line do
116117
|> Scenic.Math.Vector2.project(mx)
117118
|> Scenic.Math.Vector2.bounds()
118119
end
119-
120-
# --------------------------------------------------------
121-
@doc false
122-
def default_pin({{x0, y0}, {x1, y1}}, _styles) do
123-
{
124-
(x0 + x1) / 2,
125-
(y0 + y1) / 2
126-
}
127-
end
128120
end

lib/scenic/primitive/quad.ex

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,17 @@ defmodule Scenic.Primitive.Quad do
103103
end
104104

105105
# --------------------------------------------------------
106-
def default_pin(data)
106+
def default_pin(data), do: centroid(data)
107+
def default_pin(data, _styles), do: centroid(data)
107108

108-
def default_pin({{x0, y0}, {x1, y1}, {x2, y2}, {x3, y3}}) do
109+
# --------------------------------------------------------
110+
@doc """
111+
Returns the centroid of the quad. This is used as the default pin when applying
112+
rotate or scale transforms.
113+
"""
114+
def centroid(data)
115+
116+
def centroid({{x0, y0}, {x1, y1}, {x2, y2}, {x3, y3}}) do
109117
{
110118
(x0 + x1 + x2 + x3) / 4,
111119
(y0 + y1 + y2 + y3) / 4
@@ -149,13 +157,4 @@ defmodule Scenic.Primitive.Quad do
149157
# assumes convex, which is verified above
150158
Triangle.contains_point?({p0, p1, p2}, px) || Triangle.contains_point?({p1, p2, p3}, px)
151159
end
152-
153-
# --------------------------------------------------------
154-
@doc false
155-
def default_pin({{x0, y0}, {x1, y1}, {x2, y2}, {x3, y3}}, _styles) do
156-
{
157-
(x0 + x1 + x2 + x3) / 4,
158-
(y0 + y1 + y2 + y3) / 4
159-
}
160-
end
161160
end

lib/scenic/primitive/rectangle.ex

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ defmodule Scenic.Primitive.Rectangle do
9090

9191
# --------------------------------------------------------
9292
def default_pin(data), do: centroid(data)
93+
def default_pin(data, _styles), do: centroid(data)
9394

9495
# --------------------------------------------------------
9596
@doc """
@@ -110,10 +111,4 @@ defmodule Scenic.Primitive.Rectangle do
110111
# yp must be less than the height
111112
xp * w >= 0 && yp * h >= 0 && abs(xp) <= abs(w) && abs(yp) <= abs(h)
112113
end
113-
114-
# --------------------------------------------------------
115-
@doc false
116-
def default_pin({width, height}, _styles) do
117-
{width / 2, height / 2}
118-
end
119114
end

lib/scenic/primitive/rounded_rectangle.ex

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,16 @@ defmodule Scenic.Primitive.RoundedRectangle do
106106

107107
# --------------------------------------------------------
108108
def default_pin(data), do: centroid(data)
109+
def default_pin(data, _styles), do: centroid(data)
109110

110111
# --------------------------------------------------------
111112
@doc """
112-
Returns a the centroid of the rectangle. This is used as the default pin when applying
113+
Returns the centroid of the rectangle. This is used as the default pin when applying
113114
rotate or scale transforms.
114115
"""
115116
def centroid(data)
116117

117-
def centroid({width, height, _}) do
118+
def centroid({width, height, _radius}) do
118119
{width / 2, height / 2}
119120
end
120121

@@ -152,10 +153,4 @@ defmodule Scenic.Primitive.RoundedRectangle do
152153
false
153154
end
154155
end
155-
156-
# --------------------------------------------------------
157-
@doc false
158-
def default_pin({width, height, _radius}, _styles) do
159-
{width / 2, height / 2}
160-
end
161156
end

lib/scenic/primitive/triangle.ex

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ defmodule Scenic.Primitive.Triangle do
9898

9999
# --------------------------------------------------------
100100
def default_pin(data), do: centroid(data)
101+
def default_pin(data, _styles), do: centroid(data)
101102

102103
# --------------------------------------------------------
103104
@doc """
@@ -144,13 +145,4 @@ defmodule Scenic.Primitive.Triangle do
144145
u >= 0 && v >= 0 && u + v < 1
145146
end
146147
end
147-
148-
# --------------------------------------------------------
149-
@doc false
150-
def default_pin({{x0, y0}, {x1, y1}, {x2, y2}}, _styles) do
151-
{
152-
(x0 + x1 + x2) / 3,
153-
(y0 + y1 + y2) / 3
154-
}
155-
end
156148
end

0 commit comments

Comments
 (0)