##############################
###     DM2_w23  hu_02     ###
###  FloBer  /  2023 10 18 ###
##############################
import rhinoscriptsyntax as rs
import random, time, sys   ###                                              
sys.path.append("P:/")     ###                                                  
import DM_lib as dm        ### reload(dm)    
##############################   


rs.UnitSystem(3)                       
rs.ShowGrid(view=None, show=0)
rs.ShowGridAxes(view=None, show=0)
rs.ViewDisplayMode(view=None, mode="Wireframe")
rs.EnableRedraw(0)
rs.DeleteObjects(rs.AllObjects())
dm.newEmptyLayer( "Default" )
for lay in rs.LayerNames(): rs.PurgeLayer(lay)



size = 100

dm.allCoords = dm.setUp_hu_02(size)          ### calling def from DM_lib to get *new* set of coords
allCoords = dm.allCoords
coordsCir=allCoords[0]
coordsCub=allCoords[1]

### here we go:

coordsTop = []                                      # creates coords by "adding" the circle and the square
for i in range(len(coordsCir)):
    top = rs.PointAdd(coordsCir[i],coordsCub[i])
    coordsTop.append(top)

coordsBtm = []                                      # creates coords by "subtracting" the square from the circle
for i in range(len(coordsCir)):
    btm = rs.PointSubtract(coordsCir[i], coordsCub[i])
    coordsBtm.append(btm)

coordsSrf = []                                      # creats coords by making a curve connecting the square, top, circle and bottom coords and dividing that curve into segments
for i in range(len(coordsCir)):
    crv = rs.AddCurve([coordsCub[i], coordsTop[i], coordsCir[i], coordsBtm[i]])
    crv_div = rs.DivideCurve(crv, 50,0,1)
    coordsSrf.extend(crv_div)
    rs.DeleteObject(crv)

if 1:                       # set 1 to make a fake surface of the "squared circle", a shape defined by the top, bottom, circle and square coords
    # creates cap for top and bottom of shape
    for i in range(100):
        rs.AddCurve([random.choice(coordsCub), random.choice(coordsCub)])
        rs.AddCurve([random.choice(coordsBtm), random.choice(coordsBtm)])
    # creates surface of shape by making random curves not longer than 4
    for i in range (10000):
        pt1 = random.choice(coordsSrf)
        pt2 = random.choice(coordsSrf)
        dist = rs.Distance(pt1, pt2)
        if dist < 4:
            rs.AddCurve([pt1, pt2])
    # creats 4 curves to mark the "corners" of the shape
    for i in range(len(coordsCir)):
        if not i % (size/4):
            rs.AddCurve([coordsCub[i],coordsTop[i],coordsCir[i],coordsBtm[i]])


if 0:                       # set 1 to make cloud of points inside the shape
    coordsOut = []
    for i in range(10000):
        pt = dm.pntInbetween(random.choice(coordsTop), random.choice(coordsBtm), random.uniform(0,1))
        coordsOut.append(pt)
    ptsOut = rs.AddPoints(coordsOut)

if 0:                       # set 1 to flip pointcloud, needs previous set to 1, combine with line_shape to create mirrored shape
    rs.RotateObjects(ptsOut, coordsBtm[0], 180, [1,0,0])
    rs.MirrorObjects(ptsOut, coordsBtm[0], [1,0,0])

if 0:                       # set 1 to show respective coords
    rs.AddPoints(coordsTop)
    rs.AddPoints(coordsBtm)
    rs.AddPoints(coordsCir)
    rs.AddPoints(coordsCub)


################
dm.PointRadius(displayModeX=0, rad=3, styl=3)
rs.ZoomExtents()




