When drawing a rectangle, it creates the shape as expected when the first point is in the upper-left hand corner and the last point is south & east of the first point, creating what would be the lower-right hand corner of the polygon. This is not the case when these points are inverted, as shown. The expected behavior would be to re-orient the shape, just how drawTriangle does already.
Canvas:DrawRectangle(StartPoint, EndPoint, CurrentColor, false)
-- As expected:
-- Start Point: 38, 40
-- End Point: 105, 116
Canvas:DrawRectangle(StartPoint, EndPoint, CurrentColor, false)
-- Unexpected shape/behaviour:
-- Start Point: 208, 119
-- End Point: 144, 38
A thickness for polygons would be amazing too! This is currently how I manage shape thickness.
local function CreateShape(shape, PointA, PointB, Colour, Fill, thickness)
local offsets = {
Vector2.new(1, 0),
Vector2.new(-1, 0),
Vector2.new(0, 1),
Vector2.new(0, -1)
}
if shape == "Rectangle" then
if Fill then
Canvas:DrawRectangle(PointA, PointB, Colour, true)
else
Canvas:DrawRectangle(PointA, PointB, Colour, false)
for i = 1, thickness do
for _, offset in ipairs(offsets) do
local newPointA = PointA + offset * I
local newPointB = PointB + offset * I
Canvas:DrawRectangle(newPointA, newPointB, Colour, false)
end
end
end
elseif shape == "Triangle" then
if Fill then
Canvas:DrawTriangle(PointA, PointB, Vector2.new(PointA.X, PointB.Y), Colour, true)
else
Canvas:DrawTriangle(PointA, PointB, Vector2.new(PointA.X, PointB.Y), Colour, false)
for i = 1, thickness do
for _, offset in ipairs(offsets) do
local newPointA = PointA + offset * I
local newPointB = PointB + offset * I
local newPointC = Vector2.new(PointA.X, PointB.Y) + offset * I
Canvas:DrawTriangle(newPointA, newPointB, newPointC, Colour, false)
end
end
end
elseif shape == "Circle" then
local radius = (PointB - PointA).Magnitude
if Fill then
Canvas:DrawCircle(PointA, radius, Colour, true)
else
Canvas:DrawCircle(PointA, radius, Colour, false)
for i = 1, thickness do
Canvas:DrawCircle(PointA, radius + i, Colour, false)
Canvas:DrawCircle(PointA, radius - i, Colour, false)
end
end
end
end