Permalink
Browse files

Trim circles

  • Loading branch information...
feragon committed Jul 8, 2016
1 parent d8134e3 commit 8ae61ed8d37f13bd9e3156e457afbc0c3be04d56
Showing with 49 additions and 0 deletions.
  1. +42 −0 lcUILua/actions/trimoperation.lua
  2. +7 −0 lcadluascript/cad/lualibrecadbridge.cpp
@@ -117,6 +117,48 @@ function TrimOperation:trim()
b:append(Line(start, previousIntersect, self.toTrim:layer()))
b:append(Line(nextIntersect, finish, self.toTrim:layer()))
end
elseif(self.toTrim.entityType == "circle") then
if(#self.intersectionPoints < 2) then
message("Circle need at least two intersection points")
self:close()
return
end
local center = self.toTrim:center()
local selectedPoint = self.toTrim:nearestPointOnEntity(self.toRemovePoint)
local selectedAngle = center:angleTo(selectedPoint)
local intersectAngles = {}
local previousAngle
local nextAngle
for k, v in pairs(self.intersectionPoints) do
table.insert(intersectAngles, center:angleTo(v))
end
table.sort(intersectAngles)
for i, v in ipairs(intersectAngles) do
if(selectedAngle < v) then
if(i > 1) then
previousAngle = intersectAngles[i - 1]
nextAngle = v
break
else
previousAngle = v
nextAngle = intersectAngles[#intersectAngles]
break
end
elseif(i == #intersectAngles) then
previousAngle = v
nextAngle = intersectAngles[1]
break
end
end
b:append(Arc(center, self.toTrim:radius(), previousAngle, nextAngle, false, self.toTrim:layer()))
else
message("Unsupported entity")
end
b:execute()
@@ -202,6 +202,13 @@ void lua_openlckernel(lua_State* L) {
const geo::Coordinate & center,
double radius,
const Layer_CSPtr))
.addProperty("entityType", [](entity::Circle*) {
return "circle";
})
.addFunction("nearestPointOnEntity", &geo::Circle::nearestPointOnEntity)
.addFunction("nearestPointOnPath", &geo::Circle::nearestPointOnPath)
.addFunction("center", &entity::Circle::center)
.addFunction("radius", &entity::Circle::radius)
.endClass()
.beginExtendClass<entity::Arc, entity::CADEntity>("Arc")
.addConstructor(LUA_SP(entity::Arc_SPtr), LUA_ARGS(

0 comments on commit 8ae61ed

Please sign in to comment.