1 Star 0 Fork 2

chenyp401/CAM

forked from zzthfut/CAM 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
LinkSegs_dlook.py 1.72 KB
一键复制 编辑 原始数据 按行查看 历史
zzthfut 提交于 2023-08-03 10:54 . 6-8
from LinkPoint import LinkPoint
from Polyline import Polyline
class LinkSegs_dlook:
def __init__(self, segs):
self.segs = segs
self.contours = []
self.polys = []
self.dic = {}
self.link()
def createLpDic(self):
dic = {}
for seg in self.segs:
lp1, lp2 = LinkPoint(seg.A), LinkPoint(seg.B)
lp1.other, lp2.other = lp2, lp1
l1 = (lp1.x, lp1.y)
l2 = (lp2.x, lp2.y)
if l1 not in dic.keys():
dic[l1] = []
dic[l1].append(lp1)
if l2 not in dic.keys():
dic[l2] = []
dic[l2].append(lp2)
self.dic = dic
return dic
def findUnusedPnt(self, dic=None):
if dic is None:
dic = self.dic
for pnts in dic.values():
for pnt in pnts:
if not pnt.used:
return pnt
return None
def findNextPnt(self, p, dic=None):
if dic is None:
dic = self.dic
other = p.other
pnts = dic[(other.x, other.y)]
for pnt in pnts:
if pnt is not other:
return pnt
return None
def link(self):
self.createLpDic()
while True:
p = self.findUnusedPnt()
if p is None:
break
poly = Polyline()
while True:
poly.addPoint(p.toPoint3D())
p.used, p.other.used = True, True
p = self.findNextPnt(p)
if poly.isClosed():
self.contours.append(poly)
break
if p is None:
self.polys.append(poly)
break
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/chenyp401/cam.git
git@gitee.com:chenyp401/cam.git
chenyp401
cam
CAM
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385