diff --git a/LuaLibs/FaceData.lua b/LuaLibs/FaceData.lua index 24b8016..e022bdf 100644 --- a/LuaLibs/FaceData.lua +++ b/LuaLibs/FaceData.lua @@ -225,55 +225,53 @@ local function GetBottomFaces( Proc) return nil end - for i = 1, #BottomFaces do - BottomFaces[i].Type = 'Bottom' - BottomFaces[i].MainEdges = {} - BottomFaces[i].MainEdges.LongEdges = {} - BottomFaces[i].MainEdges.SideEdges = {} - - local ClosedEdgesSortedByGreatestLength = {} - for j = 1, #BottomFaces[i].Edges do - if not BottomFaces[i].Edges[j].Open then - table.insert( ClosedEdgesSortedByGreatestLength, {}) - ClosedEdgesSortedByGreatestLength[#ClosedEdgesSortedByGreatestLength].nIndex = j - ClosedEdgesSortedByGreatestLength[#ClosedEdgesSortedByGreatestLength].dLength = BottomFaces[i].Edges[j].Len - end + BottomFaces[1].Type = 'Bottom' + BottomFaces[1].MainEdges = {} + BottomFaces[1].MainEdges.LongEdges = {} + BottomFaces[1].MainEdges.SideEdges = {} + + local ClosedEdgesSortedByGreatestLength = {} + for i = 1, #BottomFaces[1].Edges do + if not BottomFaces[1].Edges[i].Open then + table.insert( ClosedEdgesSortedByGreatestLength, {}) + ClosedEdgesSortedByGreatestLength[#ClosedEdgesSortedByGreatestLength].nIndex = i + ClosedEdgesSortedByGreatestLength[#ClosedEdgesSortedByGreatestLength].dLength = BottomFaces[1].Edges[i].Len end - table.sort( ClosedEdgesSortedByGreatestLength, function (a, b) return a.dLength > b.dLength end) - local nFirstLongEdgeIndex = ClosedEdgesSortedByGreatestLength[1].nIndex + end + table.sort( ClosedEdgesSortedByGreatestLength, function (a, b) return a.dLength > b.dLength end) + local nFirstLongEdgeIndex = ClosedEdgesSortedByGreatestLength[1].nIndex - for j = 1, #BottomFaces[i].Edges do - local nPreviousEdgeIndex = j - 1 - if j == 1 then - nPreviousEdgeIndex = #BottomFaces[i].Edges - end - local nNextEdgeIndex = j + 1 - if j == #BottomFaces[i].Edges then - nNextEdgeIndex = 1 - end + for i = 1, #BottomFaces[1].Edges do + local nPreviousEdgeIndex = i - 1 + if i == 1 then + nPreviousEdgeIndex = #BottomFaces[1].Edges + end + local nNextEdgeIndex = i + 1 + if i == #BottomFaces[1].Edges then + nNextEdgeIndex = 1 + end - local CurrentEdge = {} - CurrentEdge.idAdjacentFace = BottomFaces[i].Edges[j].Adj - CurrentEdge.vtToolDirection = Vector3d( BottomFaces[i].Edges[j].Norm) - CurrentEdge.dLength = BottomFaces[i].Edges[j].Len - CurrentEdge.dElevation = BottomFaces[i].Edges[j].Elev - CurrentEdge.bIsOpen = BottomFaces[i].Edges[j].Open - CurrentEdge.bIsStartOpen = BottomFaces[i].Edges[nPreviousEdgeIndex].Open - CurrentEdge.bIsEndOpen = BottomFaces[i].Edges[nNextEdgeIndex].Open + local CurrentEdge = {} + CurrentEdge.idAdjacentFace = BottomFaces[1].Edges[i].Adj + CurrentEdge.vtToolDirection = Vector3d( BottomFaces[1].Edges[i].Norm) + CurrentEdge.dLength = BottomFaces[1].Edges[i].Len + CurrentEdge.dElevation = BottomFaces[1].Edges[i].Elev + CurrentEdge.bIsOpen = BottomFaces[1].Edges[i].Open + CurrentEdge.bIsStartOpen = BottomFaces[1].Edges[nPreviousEdgeIndex].Open + CurrentEdge.bIsEndOpen = BottomFaces[1].Edges[nNextEdgeIndex].Open - if j == nFirstLongEdgeIndex then - BottomFaces[i].MainEdges.LongEdges[1] = CurrentEdge - BottomFaces[i].MainEdges.LongEdges[1].Type = 'Long' - elseif nNextEdgeIndex == nFirstLongEdgeIndex then - BottomFaces[i].MainEdges.SideEdges[1] = CurrentEdge - BottomFaces[i].MainEdges.SideEdges[1].Type = 'Side' - elseif nPreviousEdgeIndex == nFirstLongEdgeIndex then - BottomFaces[i].MainEdges.SideEdges[2] = CurrentEdge - BottomFaces[i].MainEdges.SideEdges[2].Type = 'Side' - else - BottomFaces[i].MainEdges.LongEdges[2] = CurrentEdge - BottomFaces[i].MainEdges.LongEdges[2].Type = 'Long' - end + if i == nFirstLongEdgeIndex then + BottomFaces[1].MainEdges.LongEdges[1] = CurrentEdge + BottomFaces[1].MainEdges.LongEdges[1].Type = 'Long' + elseif nNextEdgeIndex == nFirstLongEdgeIndex then + BottomFaces[1].MainEdges.SideEdges[1] = CurrentEdge + BottomFaces[1].MainEdges.SideEdges[1].Type = 'Side' + elseif nPreviousEdgeIndex == nFirstLongEdgeIndex then + BottomFaces[1].MainEdges.SideEdges[2] = CurrentEdge + BottomFaces[1].MainEdges.SideEdges[2].Type = 'Side' + else + BottomFaces[1].MainEdges.LongEdges[2] = CurrentEdge + BottomFaces[1].MainEdges.LongEdges[2].Type = 'Long' end end