Permalink
Browse files

Trim arcs

  • Loading branch information...
feragon committed Jul 11, 2016
1 parent 8ae61ed commit 45fc13a0210f381628d6cc075f2f0fa0948c6851
Showing with 65 additions and 0 deletions.
  1. +51 −0 lcUILua/actions/trimoperation.lua
  2. +14 −0 lcadluascript/cad/lualibrecadbridge.cpp
@@ -157,6 +157,57 @@ function TrimOperation:trim()
end
b:append(Arc(center, self.toTrim:radius(), previousAngle, nextAngle, false, self.toTrim:layer()))
elseif(self.toTrim.entityType == "arc") then
local center = self.toTrim:center()
local startAngle
local endAngle
if(self.toTrim:CCW()) then
startAngle = self.toTrim:startAngle()
endAngle = self.toTrim:endAngle()
else
startAngle = self.toTrim:endAngle()
endAngle = self.toTrim:startAngle()
end
local selectedAngle = center:angleTo(self.toRemovePoint)
local intersectAngles = {startAngle, endAngle}
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
message("first")
previousAngle = intersectAngles[i - 1]
nextAngle = v
break
else
message("second")
previousAngle = v
nextAngle = intersectAngles[#intersectAngles]
break
end
elseif(i == #intersectAngles) then
message("third")
previousAngle = v
nextAngle = intersectAngles[1]
break
end
end
if(nextIntersectAngle ~= endAngle) then
b:append(Arc(center, self.toTrim:radius(), nextAngle, endAngle, true, self.toTrim:layer()))
end
if(previousIntersectAngle ~= startAngle) then
b:append(Arc(center, self.toTrim:radius(), startAngle, previousAngle, true, self.toTrim:layer()))
end
else
message("Unsupported entity")
end
@@ -218,6 +218,20 @@ void lua_openlckernel(lua_State* L) {
const double endAngle,
bool CCW,
const Layer_CSPtr layer))
.addFunction("nearestPointOnEntity", &geo::Arc::nearestPointOnEntity)
.addFunction("nearestPointOnPath", &geo::Arc::nearestPointOnPath)
.addFunction("angle", &geo::Arc::angle)
.addFunction("startAngle", &geo::Arc::startAngle)
.addFunction("endAngle", &geo::Arc::endAngle)
.addFunction("center", &entity::Arc::center)
.addFunction("radius", &entity::Arc::radius)
.addFunction("CCW", &geo::Arc::CCW)
.addProperty("entityType", [](entity::CADEntity*) {
return "arc";
})
.endClass()
.beginExtendClass<entity::Ellipse, entity::CADEntity>("Ellipse")
.addConstructor(LUA_SP(entity::Ellipse_SPtr), LUA_ARGS(

0 comments on commit 45fc13a

Please sign in to comment.