-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create functions for detecting each shape
- Loading branch information
David Minnerly
committed
Apr 30, 2021
1 parent
8ccc4c4
commit 122de2c
Showing
5 changed files
with
66 additions
and
48 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
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,17 @@ | ||
local getPerimeter = require(script.Parent.getPerimeter) | ||
|
||
local function fuzzyeq(a, b, epsilon) | ||
return math.abs(a - b) <= epsilon | ||
end | ||
|
||
local function isCircle(hull: { Vector2 }, hullArea: number) | ||
local perimeter = getPerimeter(hull) | ||
|
||
-- This ratio approaches 4pi for circles, so we will then compare that the | ||
-- ratio is roughly close to that value for circle detection. | ||
local thinnessRatio = perimeter^2 / hullArea | ||
|
||
return fuzzyeq(4 * math.pi, thinnessRatio, 1) | ||
end | ||
|
||
return isCircle |
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,14 @@ | ||
local getBoundingBox = require(script.Parent.getBoundingBox) | ||
local getSideLengths = require(script.Parent.getSideLengths) | ||
|
||
local RECTANGLE_PERCENT = 0.75 | ||
|
||
local function isRectangle(hull: { Vector2 }, hullArea: number) | ||
local rectangle = getBoundingBox(hull) | ||
local sides = getSideLengths(rectangle) | ||
local rectangleArea = sides.X * sides.Y | ||
|
||
return hullArea / rectangleArea >= RECTANGLE_PERCENT | ||
end | ||
|
||
return isRectangle |
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,14 @@ | ||
local getBoundingBox = require(script.Parent.getBoundingBox) | ||
local getSideLengths = require(script.Parent.getSideLengths) | ||
|
||
local SQUARE_PERCENT = 0.60 | ||
|
||
local function isSquare(hull: { Vector2 }, hullArea: number) | ||
local rectangle = getBoundingBox(hull) | ||
local sides = getSideLengths(rectangle) | ||
local maxSide = math.max(sides.X, sides.Y) | ||
|
||
return hullArea / maxSide^2 >= SQUARE_PERCENT | ||
end | ||
|
||
return isSquare |
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,13 @@ | ||
local getLargestTriangle = require(script.Parent.getLargestTriangle) | ||
local getTriangleArea = require(script.Parent.getTriangleArea) | ||
|
||
local TRIANGLE_PERCENT = 0.75 | ||
|
||
local function isTriangle(hull: { Vector2 }, hullArea: number) | ||
local triangle = getLargestTriangle(hull) | ||
local triangleArea = getTriangleArea(unpack(triangle)) | ||
|
||
return triangleArea / hullArea >= TRIANGLE_PERCENT | ||
end | ||
|
||
return isTriangle |