def atest_bccw(self): fp = [ vec3(-282.1204528808594, 127.64604187011719, 0.0), vec3(-334.1018981933594, 179.6274871826172, 0.0), vec3(-130.43038940429688, 179.62747192382812, 0.0), vec3(-130.43038940429688, 336.434326171875, 0.0), vec3(-36.91655731201172, 366.8188171386719, 0.0), vec3(-36.916534423828125, 461.72088623046875, 0.0), vec3(191.35768127441406, 461.841796875, 0.0), vec3(275.3216552734375, 373.85748291015625, 0.0), vec3(152.47915649414062, 204.779296875, 0.0), vec3(332.7578430175781, -43.35302734375, 0.0), vec3(454.96630859375, -3.6450958251953125, 0.0), vec3(456.61492919921875, -166.4105224609375, 0.0), vec3(316.5687561035156, -120.90676879882812, 0.0), vec3(201.97442626953125, -278.63232421875, 0.0), vec3(277.8673400878906, -383.0899963378906, 0.0), vec3(195.58241271972656, -472.19598388671875, 0.0), vec3(-10.369781494140625, -468.9277038574219, 0.0), vec3(-10.369804382324219, -395.02154541015625, 0.0), vec3(-78.82841491699219, -326.56292724609375, 0.0), vec3(-175.64352416992188, -326.56292724609375, 0.0), vec3(-244.10214233398438, -395.0215759277344, 0.0), vec3(-244.10214233398438, -414.89117431640625, 0.0), vec3(-465.6239929199219, -192.85736083984375, 0.0), vec3(-466.0299072265625, -122.715087890625, 0.0), vec3(-385.8233947753906, -122.71507263183594, 0.0), vec3(-282.1204528808594, -19.01211929321289, 0.0), ] o = pym.bccw(fp) self.assertTrue(o == False) fp.reverse() o = pym.bccw(fp) self.assertTrue(o == True)
def splitr(self, sup, line, connect=True): sv = self.vs[sup] bd = sv[2]['bound'] bprjx = vec3(1, 0, 0).prjps(bd) bprjy = vec3(0, 1, 0).prjps(bd) bprjz = vec3(0, 0, 1).prjps(bd) lp = vec3(bprjx[0] + line[0].x * (bprjx[1] - bprjx[0]), bprjy[0] + line[0].y * (bprjy[1] - bprjy[0]), bprjz[0] + line[0].z * (bprjz[1] - bprjz[0])) sp1 = lp.cp().trn(line[1].cp().uscl(1000)) sp2 = lp.cp().trn(line[1].cp().uscl(-1000)) l, r = pym.bsegsxy(bd, sp1, sp2) sv[2]['bound'] = tuple(l if pym.bccw(l) else l[::-1]) newes = sv[1][:] + ([sup] if connect else []) new = self.defroom(r, newes, exits=sv[2]['exits'][:], level=sv[2]['level'], skirt=sv[2]['skirt'], crown=sv[2]['crown']) # add edge for existing room for vx in sv[1]: self.vs[vx][1].append(new) if connect: sv[1].append(new) return new
def plotxy(self, fp=None, ax=None): if ax is None: ax = dtl.plot_axes_xy(50) for rmv in self.vs: if rmv is None: continue if rmv[2]['level'] > 0: continue bcol = 'b' if rmv[2]['shaft'] else None rconbs = 0.5 if pym.bccw(rmv[2]['bound']) else -0.5 rconb = pym.contract(rmv[2]['bound'], rconbs) ax = dtl.plot_polygon_xy(rconb, ax, lw=4, col=bcol) rc = vec3(0, 0, 0).com(rmv[2]['bound']) rs = str(rmv[0]) + ',' + str(rmv[1]) ax = dtl.plot_point_xy(rc, dtl.plot_point_xy_annotate(rc, ax, rs)) if rmv[1]: for re in rmv[1]: if self.vs[re] is None: continue rt = (rc, vec3(0, 0, 0).com(self.vs[re][2]['bound'])) ax = dtl.plot_edges_xy(rt, ax, col='g') for exit in rmv[2]['exits']: if exit is True: exitp = rc ax = dtl.plot_point_xy( exitp, dtl.plot_point_xy_annotate(exitp, ax, 'exit')) else: ax = dtl.plot_point_xy( exit, dtl.plot_point_xy_annotate(exit, ax, 'exit')) if not fp is None: ax = dtl.plot_polygon_xy(fp, ax, lw=2, col='r') return ax
def vstitch(self, vb, v, a, l=10): #vb = [b.cp() for b in v[1]['b'][0]] if not pym.bccw(vb): vb.reverse() fnd = True while fnd: fnd = False for o, depth in a.enum(): if o.ix == v.ix: continue #if ox == v.ix:continue ob = o.loop adjs = pym.badjbxy(vb, ob, 0.1) for adj in adjs: vbx, obx = adj vb1, vb2, ob1, ob2 = vb[vbx - 1], vb[vbx], ob[obx - 1], ob[obx] ips = pym.sintsxyp(vb1, vb2, ob1, ob2, ieb=0, skew=0, ie=0) if ips is None: continue ip1, ip2 = ips if not ip1 in vb or not ip2 in vb: if ip1.onsxy(vb1, vb2, 0): vb.insert(vbx, ip1) fnd = True if ip2.onsxy(vb1, vb2, 0): vb.insert(vbx, ip2) fnd = True if fnd: break vbx = 0 while vbx < len(vb): vb1, vb2 = vb[vbx - 1], vb[vbx] if vb1.d(vb2) < l: vbx += 1 else: vb.insert(vbx, vb1.mid(vb2)) return vb
def plotxy(self,fp = None,ax = None): if ax is None:ax = dtl.plot_axes_xy(50) for rmv in self.vs: if rmv is None:continue if rmv[2]['level'] > 0:continue bcol = 'b' if rmv[2]['shaft'] else None rconbs = 0.5 if pym.bccw(rmv[2]['bound']) else -0.5 rconb = pym.contract(rmv[2]['bound'],rconbs) ax = dtl.plot_polygon_xy(rconb,ax,lw = 4,col = bcol) rc = vec3(0,0,0).com(rmv[2]['bound']) rs = str(rmv[0])+','+str(rmv[1]) ax = dtl.plot_point_xy(rc,dtl.plot_point_xy_annotate(rc,ax,rs)) if rmv[1]: for re in rmv[1]: if self.vs[re] is None:continue rt = (rc,vec3(0,0,0).com(self.vs[re][2]['bound'])) ax = dtl.plot_edges_xy(rt,ax,col = 'g') for exit in rmv[2]['exits']: if exit is True: exitp = rc ax = dtl.plot_point_xy(exitp, dtl.plot_point_xy_annotate(exitp,ax,'exit')) else: ax = dtl.plot_point_xy(exit, dtl.plot_point_xy_annotate(exit,ax,'exit')) if not fp is None: ax = dtl.plot_polygon_xy(fp,ax,lw = 2,col = 'r') return ax
def plotxy(self,ax = None,scale = 250): if ax is None:ax = dtl.plot_axes_xy(scale) ax = pgr.planargraph.plotxy(self,ax) ekeys = [] for vx in range(self.vcnt): v = self.vs[vx] if v is None:continue vb = v[1]['b'] vrtls = '-' if 't' in v[1]:vrtls = '--' if 'developed' in v[1]['t'] else '-' conr = 1 if pym.bccw(vb[0]) else -1 ax = dtl.plot_polygon_xy(pym.contract(vb[0],conr), ax,lw = 2,ls = vrtls,col = 'b') for ib in vb[1]: conr = 1 if pym.bccw(ib) else -1 ax = dtl.plot_polygon_xy(pym.contract(ib,conr),ax,lw = 2,col = 'r') vbc = vec3(0,0,0).com(vb[0]) rs = str(vx)+','+str(self.orings[vx])#+',\n'+str(v[1]['type']) ax = dtl.plot_point_xy_annotate(vbc,ax,rs) for ve in self.orings[vx]: ov = self.vs[ve] if ov is None:continue if not (vx,ve) in ekeys and not (ve,vx) in ekeys: ekeys.append((vx,ve)) aws = pym.badjbxy(vb[0],ov[1]['b'][0],0) for awx in range(len(aws)): vwx,owx = aws[awx] ex,ekws = self.es[self.elook[ekeys[-1]]] door = vb[0][vwx-1].lerp(vb[0][vwx],ekws['p']) ax = dtl.plot_point_xy(door,ax,col = 'r') ovbc = vec3(0,0,0).com(self.vs[ve][1]['b'][0]) ax = dtl.plot_edges_xy((vbc,ovbc),ax,lw = 3,col = 'c') #for ep in v[1]['exits']: # ax = dtl.plot_point_xy(ep,ax,mk = 's',col = 'r') return ax
def raise_earth(topo, tips, e, mingrad=1.0, mindelz=-5.0, depth=0): if depth == 0: for j, tip in enumerate(tips): tips[j].loop = pym.bisectb(tips[j].loop) #if depth == 10:return print('... raising earth ... (depth: %d)' % depth) newtips = [] for tip in tips: if tip is None: continue newloop = [p.cp().ztrn(mindelz) for p in tip.loop] newloop = pym.aggregate( pym.contract(newloop, abs(mindelz / mingrad)), 5) #uloops = [pym.smoothxyi(newloop,0.8,e,10,1)] #uloops = [pym.pinchb(u,10) for u in uloops if u] #uloops = [pym.pinchb(newloop,10)] uloops = pym.pinchb(newloop, 10) uloops = [u for u in uloops if u] for u in uloops: if not pym.bccw(u): u.reverse() ''' if len(uloops) == 1: print('... 1 loop to raise ...') theloop = uloops[0] newtiparea = pym.bareaxy(theloop,True) elif uloops: print('... 2+ loops to raise ...') bareas = [pym.bareaxy(u,True) for u in uloops] theloop = uloops[bareas.index(max(bareas))] newtiparea = max(bareas) else: print('... no loops to raise ...') theloop = [] ''' for theloop in uloops: newtiparea = pym.bareaxy(theloop, True) newtip = None if theloop and newtiparea > 10: #2*(e)**2: newtip = topo.avert(tip, loop=theloop) else: print('... abortive tip! ...') if newtip is None: continue else: newtips.append(newtip) if newtips: terrain.raise_earth(topo, newtips, e, mingrad, mindelz, depth + 1) else: print('... exhausted tip! ...')
def pepper(t, tip, e=2): print('pepper') c = vec3(0, 0, 0).com(tip.loop) d = vec3(1, 0, 0).uscl(1000) s1, s2 = c.cp().trn(d.flp()), c.cp().trn(d.flp()) ch = lambda b: pyg.chunk( b, e, random.random() + 0.2, edge=random.randint(0, 1)) bs = [ch(tip.loop) for x in range(10)] bs = pym.bsuxy(bs, e) #ax = dtl.plot_axes_xy(200) #for b in bs: # dtl.plot_polygon_xy(b,ax,lw = 2) #plt.show() newtips = [] for sb in bs: if not pym.bccw(sb): sb.reverse() sb = pyg.ajagged(sb, 2) sb = pyg.ajagged(sb, 2) sb = pyg.ajagged(sb, 2) #sb = pyg.ajagged(sb,2) #for x in range(3):b = pyg.ajagged(b,e) sb = pym.bisectb(sb) #sb = pym.smoothxy(sb,0.5,e) sb = pym.smoothxy(sb, 0.5, e) sb = pym.aggregate(sb, 4) #sb = pym.blimithmin(sb,2,50) for p in sb: p.ztrn(2) newtips.append(t.al(sb, tip)) ax = dtl.plot_axes(200) ax = dtl.plot_polygon(t.root.loop, ax, ls='--', lw=2, col='k') ax = dtl.plot_polygon(tip.loop, ax, lw=3, col='r') for b in bs: ax = dtl.plot_polygon(b, ax, lw=3, col='g') plt.show() return newtips
def raise_earth(topo,tips,e,mingrad = 1.0,mindelz = -5.0,depth = 0): if depth == 0: for j,tip in enumerate(tips): tips[j].loop = pym.bisectb(tips[j].loop) #if depth == 10:return print('... raising earth ... (depth: %d)' % depth) newtips = [] for tip in tips: if tip is None:continue newloop = [p.cp().ztrn(mindelz) for p in tip.loop] newloop = pym.aggregate(pym.contract(newloop,abs(mindelz/mingrad)),5) #uloops = [pym.smoothxyi(newloop,0.8,e,10,1)] #uloops = [pym.pinchb(u,10) for u in uloops if u] #uloops = [pym.pinchb(newloop,10)] uloops = pym.pinchb(newloop,10) uloops = [u for u in uloops if u] for u in uloops: if not pym.bccw(u): u.reverse() ''' if len(uloops) == 1: print('... 1 loop to raise ...') theloop = uloops[0] newtiparea = pym.bareaxy(theloop,True) elif uloops: print('... 2+ loops to raise ...') bareas = [pym.bareaxy(u,True) for u in uloops] theloop = uloops[bareas.index(max(bareas))] newtiparea = max(bareas) else: print('... no loops to raise ...') theloop = [] ''' for theloop in uloops: newtiparea = pym.bareaxy(theloop,True) newtip = None if theloop and newtiparea > 10:#2*(e)**2: newtip = topo.avert(tip,loop = theloop) else:print('... abortive tip! ...') if newtip is None:continue else:newtips.append(newtip) if newtips: terrain.raise_earth(topo,newtips,e,mingrad,mindelz,depth+1) else:print('... exhausted tip! ...')
def pepper(t,tip,e = 2): print('pepper') c = vec3(0,0,0).com(tip.loop) d = vec3(1,0,0).uscl(1000) s1,s2 = c.cp().trn(d.flp()),c.cp().trn(d.flp()) ch = lambda b : pyg.chunk(b,e,random.random()+0.2,edge = random.randint(0,1)) bs = [ch(tip.loop) for x in range(10)] bs = pym.bsuxy(bs,e) #ax = dtl.plot_axes_xy(200) #for b in bs: # dtl.plot_polygon_xy(b,ax,lw = 2) #plt.show() newtips = [] for sb in bs: if not pym.bccw(sb):sb.reverse() sb = pyg.ajagged(sb,2) sb = pyg.ajagged(sb,2) sb = pyg.ajagged(sb,2) #sb = pyg.ajagged(sb,2) #for x in range(3):b = pyg.ajagged(b,e) sb = pym.bisectb(sb) #sb = pym.smoothxy(sb,0.5,e) sb = pym.smoothxy(sb,0.5,e) sb = pym.aggregate(sb,4) #sb = pym.blimithmin(sb,2,50) for p in sb:p.ztrn(2) newtips.append(t.al(sb,tip)) ax = dtl.plot_axes(200) ax = dtl.plot_polygon(t.root.loop,ax,ls = '--',lw = 2,col = 'k') ax = dtl.plot_polygon(tip.loop,ax,lw = 3,col = 'r') for b in bs: ax = dtl.plot_polygon(b,ax,lw = 3,col = 'g') plt.show() return newtips
def split(self,v,s,z,rad,epsilon): sp = vec3(0,0,0).com(v.loop) sd = vec3(0,1,0) if random.random() > 0.5 else vec3(1,0,0) s1 = sp.cp().trn(sd.cp().uscl( 10000)) s2 = sp.cp().trn(sd.cp().uscl(-10000)) loops = pym.bsegsxy(v.loop,s1,s2,0.1) lvs = [] for el in loops: if not pym.bccw(el):el.reverse() el = pym.blimithmin(el,2,50) el = pym.aggregate(el,2) #el = pym.smoothxy(el,0.5,epsilon) nv = self.grow(v,z,rad,epsilon,el) lvs.append(nv) ax = self.plot() for el in loops: ax = dtl.plot_polygon(el,ax,lw = 2,col = 'r') plt.show() return lvs
def splitr(self,sup,line,connect = True): sv = self.vs[sup] bd = sv[2]['bound'] bprjx = vec3(1,0,0).prjps(bd) bprjy = vec3(0,1,0).prjps(bd) bprjz = vec3(0,0,1).prjps(bd) lp = vec3( bprjx[0]+line[0].x*(bprjx[1]-bprjx[0]), bprjy[0]+line[0].y*(bprjy[1]-bprjy[0]), bprjz[0]+line[0].z*(bprjz[1]-bprjz[0])) sp1 = lp.cp().trn(line[1].cp().uscl( 1000)) sp2 = lp.cp().trn(line[1].cp().uscl(-1000)) l,r = pym.bsegsxy(bd,sp1,sp2) sv[2]['bound'] = tuple(l if pym.bccw(l) else l[::-1]) newes = sv[1][:]+([sup] if connect else []) new = self.defroom(r,newes, exits = sv[2]['exits'][:],level = sv[2]['level'], skirt = sv[2]['skirt'],crown = sv[2]['crown']) # add edge for existing room for vx in sv[1]:self.vs[vx][1].append(new) if connect:sv[1].append(new) return new