chasing down coordinate problem
This commit is contained in:
@@ -195,12 +195,36 @@ function Level:insideBounds(x, y, segments)
|
|||||||
segments = self.segments
|
segments = self.segments
|
||||||
end
|
end
|
||||||
-- prepare shape
|
-- prepare shape
|
||||||
print_r(self.polygon)
|
local polygon = self:getPolygonFromSegments(segments)
|
||||||
|
|
||||||
return PointWithinShape(self.polygon, x, y)
|
return PointWithinShape(polygon, x, y)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Level:getPolygonFromSegments(segments)
|
||||||
|
local polygon = {}
|
||||||
|
local polygonPoints = {}
|
||||||
|
local pointlist = {}
|
||||||
|
local j = 1
|
||||||
|
for i, segment in ipairs(segments) do
|
||||||
|
polygon[i] = {}
|
||||||
|
polygon[i + 1] = {}
|
||||||
|
polygon[i].x, polygon[i].y, polygon[i + 1].x, polygon[i + 1].y = segment:segmentToPoints()
|
||||||
|
polygonPoints[j] = polygon[i].x
|
||||||
|
polygonPoints[j + 1] = polygon[i].y
|
||||||
|
polygonPoints[j + 2] = polygon[i + 1].x
|
||||||
|
polygonPoints[j + 3] = polygon[i + 1].y
|
||||||
|
|
||||||
|
j = j + 4
|
||||||
|
i = i + 1
|
||||||
|
end
|
||||||
|
return polygon
|
||||||
end
|
end
|
||||||
|
|
||||||
function Level:createPolygon()
|
function Level:createPolygon()
|
||||||
|
if #self.segments > 5 then
|
||||||
|
print("Level:createPolygon")
|
||||||
|
print_r(self.segments)
|
||||||
|
end
|
||||||
local polygon = {}
|
local polygon = {}
|
||||||
local polygonPoints = {}
|
local polygonPoints = {}
|
||||||
local pointlist = {}
|
local pointlist = {}
|
||||||
@@ -319,9 +343,9 @@ function Level:cutLevel()
|
|||||||
-- print("split the segment")
|
-- print("split the segment")
|
||||||
part1, temp, part2 = self.segments[k]:splitInThreeWithSegments(newSegs[1], newSegs[#newSegs])
|
part1, temp, part2 = self.segments[k]:splitInThreeWithSegments(newSegs[1], newSegs[#newSegs])
|
||||||
-- print("part1")
|
-- print("part1")
|
||||||
part1:debug()
|
-- part1:debug()
|
||||||
-- print("part2")
|
-- print("part2")
|
||||||
part2:debug()
|
-- part2:debug()
|
||||||
|
|
||||||
-- print("insert first part")
|
-- print("insert first part")
|
||||||
new[j] = part1
|
new[j] = part1
|
||||||
@@ -588,7 +612,7 @@ function Level:cutLevel()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self:createPolygon()
|
self.polygon = self:createPolygon()
|
||||||
self.mesh = poly2mesh(self.points)
|
self.mesh = poly2mesh(self.points)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -171,14 +171,14 @@ end
|
|||||||
|
|
||||||
function Segment:joinPerpendicular(s)
|
function Segment:joinPerpendicular(s)
|
||||||
-- changes the self, not the parameter
|
-- changes the self, not the parameter
|
||||||
if s.vertical then
|
if s.vertical and self.horizontal then
|
||||||
local sx = s.firstPointX
|
local sx = s.firstPointX
|
||||||
if math.abs(self.firstPointX - sx) < math.abs(self.secondPointX - sx) then
|
if math.abs(self.firstPointX - sx) < math.abs(self.secondPointX - sx) then
|
||||||
self.firstPointX = sx
|
self.firstPointX = sx
|
||||||
else
|
else
|
||||||
self.secondPointX = sx
|
self.secondPointX = sx
|
||||||
end
|
end
|
||||||
else
|
elseif s.horizontal and self.vertical then
|
||||||
local sy = s.firstPointY
|
local sy = s.firstPointY
|
||||||
if math.abs(self.firstPointY - sy) < math.abs(self.secondPointY - sy) then
|
if math.abs(self.firstPointY - sy) < math.abs(self.secondPointY - sy) then
|
||||||
self.firstPointY = sy
|
self.firstPointY = sy
|
||||||
|
|||||||
Reference in New Issue
Block a user