Skip to content

Commit

Permalink
Merge pull request #313 from seb3s/patch-5
Browse files Browse the repository at this point in the history
clean centroid & default_pin code
  • Loading branch information
crertel authored May 5, 2024
2 parents 4da2346 + 0acf473 commit 0b6b4b2
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 44 deletions.
12 changes: 2 additions & 10 deletions lib/scenic/primitive/line.ex
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ defmodule Scenic.Primitive.Line do

# --------------------------------------------------------
def default_pin(data), do: centroid(data)
def default_pin(data, _styles), do: centroid(data)

# --------------------------------------------------------
@doc """
Returns a the midpoint of the line. This is used as the default pin when applying
Returns the midpoint of the line. This is used as the default pin when applying
rotate or scale transforms.
"""
def centroid(data)
Expand All @@ -116,13 +117,4 @@ defmodule Scenic.Primitive.Line do
|> Scenic.Math.Vector2.project(mx)
|> Scenic.Math.Vector2.bounds()
end

# --------------------------------------------------------
@doc false
def default_pin({{x0, y0}, {x1, y1}}, _styles) do
{
(x0 + x1) / 2,
(y0 + y1) / 2
}
end
end
21 changes: 10 additions & 11 deletions lib/scenic/primitive/quad.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,17 @@ defmodule Scenic.Primitive.Quad do
end

# --------------------------------------------------------
def default_pin(data)
def default_pin(data), do: centroid(data)
def default_pin(data, _styles), do: centroid(data)

def default_pin({{x0, y0}, {x1, y1}, {x2, y2}, {x3, y3}}) do
# --------------------------------------------------------
@doc """
Returns the centroid of the quad. This is used as the default pin when applying
rotate or scale transforms.
"""
def centroid(data)

def centroid({{x0, y0}, {x1, y1}, {x2, y2}, {x3, y3}}) do
{
(x0 + x1 + x2 + x3) / 4,
(y0 + y1 + y2 + y3) / 4
Expand Down Expand Up @@ -149,13 +157,4 @@ defmodule Scenic.Primitive.Quad do
# assumes convex, which is verified above
Triangle.contains_point?({p0, p1, p2}, px) || Triangle.contains_point?({p1, p2, p3}, px)
end

# --------------------------------------------------------
@doc false
def default_pin({{x0, y0}, {x1, y1}, {x2, y2}, {x3, y3}}, _styles) do
{
(x0 + x1 + x2 + x3) / 4,
(y0 + y1 + y2 + y3) / 4
}
end
end
7 changes: 1 addition & 6 deletions lib/scenic/primitive/rectangle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ defmodule Scenic.Primitive.Rectangle do

# --------------------------------------------------------
def default_pin(data), do: centroid(data)
def default_pin(data, _styles), do: centroid(data)

# --------------------------------------------------------
@doc """
Expand All @@ -110,10 +111,4 @@ defmodule Scenic.Primitive.Rectangle do
# yp must be less than the height
xp * w >= 0 && yp * h >= 0 && abs(xp) <= abs(w) && abs(yp) <= abs(h)
end

# --------------------------------------------------------
@doc false
def default_pin({width, height}, _styles) do
{width / 2, height / 2}
end
end
11 changes: 3 additions & 8 deletions lib/scenic/primitive/rounded_rectangle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,16 @@ defmodule Scenic.Primitive.RoundedRectangle do

# --------------------------------------------------------
def default_pin(data), do: centroid(data)
def default_pin(data, _styles), do: centroid(data)

# --------------------------------------------------------
@doc """
Returns a the centroid of the rectangle. This is used as the default pin when applying
Returns the centroid of the rectangle. This is used as the default pin when applying
rotate or scale transforms.
"""
def centroid(data)

def centroid({width, height, _}) do
def centroid({width, height, _radius}) do
{width / 2, height / 2}
end

Expand Down Expand Up @@ -152,10 +153,4 @@ defmodule Scenic.Primitive.RoundedRectangle do
false
end
end

# --------------------------------------------------------
@doc false
def default_pin({width, height, _radius}, _styles) do
{width / 2, height / 2}
end
end
10 changes: 1 addition & 9 deletions lib/scenic/primitive/triangle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ defmodule Scenic.Primitive.Triangle do

# --------------------------------------------------------
def default_pin(data), do: centroid(data)
def default_pin(data, _styles), do: centroid(data)

# --------------------------------------------------------
@doc """
Expand Down Expand Up @@ -144,13 +145,4 @@ defmodule Scenic.Primitive.Triangle do
u >= 0 && v >= 0 && u + v < 1
end
end

# --------------------------------------------------------
@doc false
def default_pin({{x0, y0}, {x1, y1}, {x2, y2}}, _styles) do
{
(x0 + x1 + x2) / 3,
(y0 + y1 + y2) / 3
}
end
end

0 comments on commit 0b6b4b2

Please sign in to comment.