Permalink
Browse files

Trim with multiple intersections

  • Loading branch information...
feragon committed Jul 8, 2016
1 parent 13ac87c commit d8134e3919e0db83b3d71286b953d6a3e9bd9c37
Showing with 34 additions and 14 deletions.
  1. +34 −14 lcUILua/actions/trimoperation.lua
@@ -77,28 +77,48 @@ function TrimOperation:getIntersectionPoints()
end
function TrimOperation:trim()
local newEntity
local b = Builder(active_widget():document())
b:append(self.toTrim)
b:push()
b:remove()
b:processStack()
if(self.toTrim.entityType == "line") then
local point = self.toTrim:nearestPointOnEntity(self.toRemovePoint)
local start = self.toTrim:start()
local finish = self.toTrim:finish()
local startToPoint = point:distanceTo(start)
local previousIntersect = start
local previousIntersectDistance = 0
local nextIntersect = finish
local nextIntersectDistance = start:distanceTo(finish)
local startToPoint = point:distanceTo(self.toTrim:start())
local startToIntersect = point:distanceTo(self.intersectionPoints[1])
for k, v in pairs(self.intersectionPoints) do
local startToIntersect = start:distanceTo(v)
if(startToPoint >= startToIntersect) then
newEntity = Line(self.toTrim:start(), self.intersectionPoints[1], self.toTrim:layer())
if(startToIntersect < startToPoint and startToIntersect > previousIntersectDistance) then
previousIntersect = v
previousIntersectDistance = startToIntersect
elseif(startToIntersect > startToPoint and startToIntersect < nextIntersectDistance) then
nextIntersect = v
nextIntersectDistance = startToIntersect
end
end
if(previousIntersect == start) then
b:append(Line(nextIntersect, finish, self.toTrim:layer()))
elseif(nextIntersect == finish) then
b:append(Line(start, previousIntersect, self.toTrim:layer()))
else
newEntity = Line(self.intersectionPoints[1], self.toTrim:finish(), self.toTrim:layer())
b:append(Line(start, previousIntersect, self.toTrim:layer()))
b:append(Line(nextIntersect, finish, self.toTrim:layer()))
end
end
local b = Builder(active_widget():document())
b:append(self.toTrim)
b:push()
b:remove()
b:processStack()
b:append(newEntity)
b:execute()
self:close()

0 comments on commit d8134e3

Please sign in to comment.