Skip to content
Snippets Groups Projects
Blocks.py 67.4 KiB
Newer Older
  • Learn to ignore specific revisions
  • # GPL # "authors": dudecon, jambay
    
    
    # Module notes:
    #
    # Grout needs to be implemented.
    # consider removing wedge crit for small "c" and "cl" values
    # wrap around for openings on radial stonework?
    # auto-clip wall edge to SMALL for radial and domes.
    # unregister doesn't release all references.
    # repeat for opening doesn't distribute evenly when radialized - see wrap around
    
    # if opening width == indent*2 the edge blocks fail (row of blocks cross opening).
    # if openings overlap fills inverse with blocks - see h/v slots.
    
    # Negative grout width creates a pair of phantom blocks, separated by grout
    
    # width, inside the edges.
    # if block width variance is 0, and edging is on, right edge blocks create a "vertical seam"
    
    from math import (
            fmod, sqrt,
            sin, cos, atan,
            pi as PI,
            )
    
    # Set to True to enable debug_prints
    DEBUG = False
    
    # A few constants
    
    # for values that must be != 0; see UI options/variables - sort of a bug to be fixed
    NOTZERO = 0.01
    
    # General masonry Settings
    
    # ------------------------
    settings = {
        'w': 1.2, 'wv': 0.3, 'h': .6, 'hv': 0.3, 'd': 0.3, 'dv': 0.1,
        'g': 0.1, 'gv': 0.07, 'gd': 0.01, 'gdv': 0.0, 'b': 0, 'bv': 0,
        'f': 0.0, 'fv': 0.0, 't': 0.0, 'sdv': 0.1, 'hwt': 0.5, 'aln': 0,
        'wm': 0.8, 'hm': 0.3, 'dm': 0.1,
        'woff': 0.0, 'woffv': 0.0, 'eoff': 0.3, 'eoffv': 0.0, 'rwhl': 1,
        'hb': 0, 'ht': 0, 'ge': 0, 'physics': 0
        }
    """
        settings DOCUMENTATION:
        'w':width 'wv':widthVariation
        'h':height 'hv':heightVariation
        'd':depth 'dv':depthVariation
        'g':grout 'gv':groutVariation 'gd':groutDepth 'gdv':groutDepthVariation
        'b':bevel 'bv':bevelVariation
        'f':flawSize 'fv':flawSizeVariation 'ff':flawFraction
        't':taper
        'sdv':subdivision(distance or angle)
        'hwt':row height effect on block widths in the row (0=no effect,
              1=1:1 relationship, negative values allowed, 0.5 works well)
        'aln':alignment(0=none, 1=rows w/features, 2=features w/rows)
             (currently unused)
        'wm':width minimum 'hm':height minimum 'dm':depth minimum
        'woff':row start offset(fraction of width)
        'woffv':width offset variation(fraction of width)
        'eoff':edge offset 'eoffv':edge offset variation
        'rwhl':row height lock(1 is all blocks in row have same height)
        'hb':bottom row height 'ht': top row height 'ge': grout the edges
        'physics': set up for physics
    """
    
    # ------------------------
    dims = {
        's': 0, 'e': PI * 3 / 2, 'b': 0.1, 't': 12.3
        }  # radial
    """
        dims DOCUMENTATION:
        's':start x or theta 'e':end x or theta 'b':bottom z or r 't':top z or r
        'w' = e-s and h = t-b; calculated to optimize for various operations/usages
        dims = {'s':-12, 'e':15, 'w':27, 'b':-15., 't':15., 'h':30}
        dims = {'s':-bayDim/2, 'e':bayDim/2, 'b':-5., 't':10.} # bay settings?
    """
    
    # ------------------------
    
    radialized = 0  # Radiating from one point - round/disc; instead of square
    
    slope = 0       # Warp/slope; curved over like a vaulted tunnel
    
    
    # 'bigblock': merge adjacent blocks into single large blocks
    
    bigBlock = 0    # Merge blocks
    
    
    # Gaps in blocks for various apertures
    # ------------------------
    
    # openingSpecs = []
    
    openingSpecs = [
        {'w': 0.5, 'h': 0.5, 'x': 0.8, 'z': 2.7, 'rp': 1, 'b': 0.0,
         'v': 0, 'vl': 0, 't': 0, 'tl': 0}
        ]
    """
        openingSpecs DOCUMENTATION:
        'w': opening width, 'h': opening height,
        'x': horizontal position, 'z': vertical position,
        'rp': make multiple openings, with a spacing of x,
        'b': bevel the opening, inside only, like an arrow slit.
        'v': height of the top arch, 'vl':height of the bottom arch,
        't': thickness of the top arch, 'tl': thickness of the bottom arch
    """
    
    # Add blocks to make platforms
    # ------------------------
    
    shelfSpecs = {
        'w': 0.5, 'h': 0.5, 'd': 0.3, 'x': 0.8, 'z': 2.7
        }
    """
        shelfSpecs DOCUMENTATION:
        'w': block width, 'h': block height, 'd': block depth (shelf size; offset from wall)
        'x': horizontal start position, 'z': vertical start position
    """
    
    # Add blocks to make steps
    # ------------------------
    
    
    stepSpecs = {
        'x': 0.0, 'z': -10, 'w': 10.0, 'h': 10.0,
        'v': 0.7, 't': 1.0, 'd': 1.0
        }
    """
        stepSpecs DOCUMENTATION:
        'x': horizontal start position, 'z': vertical start position,
        'w': step area width, 'h': step area height,
        'v': riser height, 't': tread width, 'd': block depth (step size; offset from wall)
    """
    stepLeft = 0
    shelfBack = 0
    stepOnly = 0
    stepBack = 0
    
    
    # switchable prints
    def debug_prints(func="", text="Message", var=None):
        global DEBUG
        if DEBUG:
            print("\n[{}]\nmessage: {}".format(func, text))
            if var:
                print("Error: ", var)
    
    
    # pass variables just like for the regular prints
    def debug_print_vars(*args, **kwargs):
        global DEBUG
        if DEBUG:
            print(*args, **kwargs)
    
    # easier way to get to the random function
    def rnd():
        return random()
    
    
    # random number from -0.5 to 0.5
    def rndc():
        return (random() - 0.5)
    
    # random number from -1.0 to 1.0
    def rndd():
        return (random() - 0.5) * 2.0
    
    # Opening Test suite
    # opening test function
    
    def test(TestN=13):
        dims = {'s': -29., 'e': 29., 'b': -6., 't': TestN * 7.5}
    
        openingSpecs = []
        for i in range(TestN):
            x = (random() - 0.5) * 6
    
            z = i * 7.5
            v = .2 + i * (3. / TestN)
            vl = 3.2 - i * (3. / TestN)
    
            t = 0.3 + random()
            tl = 0.3 + random()
    
            rn = random() * 2
            openingSpecs += [{'w': 3.1 + rn, 'h': 0.3 + rn, 'x': float(x),
                              'z': float(z), 'rp': 0, 'b': 0.,
                              'v': float(v), 'vl': float(vl),
                              't': float(t), 'tl': float(tl)}]
    
    # dims, openingSpecs = test(15)
    
    # For filling a linear space with divisions
    def fill(left, right, avedst, mindst=0.0, dev=0.0, pad=(0.0, 0.0), num=0,
    
             center=0):
        __doc__ = """\
        Fills a linear range with points and returns an ordered list of those points
        including the end points.
    
        left: the lower boundary
        right: the upper boundary
        avedst: the average distance between points
        mindst: the minimum distance between points
        dev: the maximum random deviation from avedst
        pad: tends to move the points near the bounds right (positive) or
            left (negative).
            element 0 pads the lower bounds, element 1 pads the upper bounds
        num: substitutes a numerical limit for the right limit.  fill will then make
            a num+1 element list
        center: flag to center the elements in the range, 0 == disabled
    
        curpos = left + pad[0]
    
    
        # Set offset by average spacing, then add blocks (fall through);
        # if not at right edge.
        if center:
    
            curpos += ((right - left - mindst * 2) % avedst) / 2 + mindst
            if curpos - poslist[-1] < mindst:
                curpos = poslist[-1] + mindst + rnd() * dev / 2
    
            if (right - curpos < mindst) or (right - curpos < mindst - pad[1]):
    
            else:
                poslist.append(curpos)
    
        # unused... for now.
    
            while idx < num + 1:
                curpos += avedst + rndd() * dev
                if curpos - poslist[-1] < mindst:
                    curpos = poslist[-1] + mindst + rnd() * dev / 2
    
                poslist.append(curpos)
                idx += 1
    
            return poslist
    
        # make block edges
        else:
    
            while True:  # loop for blocks
                curpos += avedst + rndd() * dev
                if curpos - poslist[-1] < mindst:
                    curpos = poslist[-1] + mindst + rnd() * dev / 2
    
                if (right - curpos < mindst) or (right - curpos < mindst - pad[1]):
    
                else:
                    poslist.append(curpos)
    
    # For generating block geometry
    
    def MakeABlock(bounds, segsize, vll=0, Offsets=None, FaceExclude=[],
                   bevel=0, xBevScl=1):
        __doc__ = """\
        MakeABlock returns lists of points and faces to be made into a square
                cornered block, subdivided along the length, with optional bevels.
        bounds: a list of boundary positions:
            0:left, 1:right, 2:bottom, 3:top, 4:back, 5:front
        segsize: the maximum size before lengthwise subdivision occurs
        vll: the number of vertexes already in the mesh. len(mesh.verts) should
                give this number.
        Offsets: list of coordinate delta values.
            Offsets are lists, [x,y,z] in
                [
                0:left_bottom_back,
                1:left_bottom_front,
                2:left_top_back,
                3:left_top_front,
                4:right_bottom_back,
                5:right_bottom_front,
                6:right_top_back,
                7:right_top_front,
                ]
        FaceExclude: list of faces to exclude from the faces list.  see bounds above for indices
    
        xBevScl: how much to divide the end (+- x axis) bevel dimensions.  Set to current average
        radius to compensate for angular distortion on curved blocks
    
        """
    
        slices = fill(bounds[0], bounds[1], segsize, segsize, center=1)
        points = []
        faces = []
    
    
        if Offsets is None:
            points.append([slices[0], bounds[4], bounds[2]])
            points.append([slices[0], bounds[5], bounds[2]])
            points.append([slices[0], bounds[5], bounds[3]])
            points.append([slices[0], bounds[4], bounds[3]])
    
                points.append([x, bounds[4], bounds[2]])
                points.append([x, bounds[5], bounds[2]])
                points.append([x, bounds[5], bounds[3]])
                points.append([x, bounds[4], bounds[3]])
    
            points.append([slices[-1], bounds[4], bounds[2]])
            points.append([slices[-1], bounds[5], bounds[2]])
            points.append([slices[-1], bounds[5], bounds[3]])
            points.append([slices[-1], bounds[4], bounds[3]])
    
            points.append([slices[0] + Offsets[0][0], bounds[4] + Offsets[0][1], bounds[2] + Offsets[0][2]])
            points.append([slices[0] + Offsets[1][0], bounds[5] + Offsets[1][1], bounds[2] + Offsets[1][2]])
            points.append([slices[0] + Offsets[3][0], bounds[5] + Offsets[3][1], bounds[3] + Offsets[3][2]])
            points.append([slices[0] + Offsets[2][0], bounds[4] + Offsets[2][1], bounds[3] + Offsets[2][2]])
    
            for x in slices[1: -1]:
                xwt = (x - bounds[0]) / (bounds[1] - bounds[0])
                points.append([x + Offsets[0][0] * (1 - xwt) + Offsets[4][0] * xwt,
                              bounds[4] + Offsets[0][1] * (1 - xwt) + Offsets[4][1] * xwt,
                              bounds[2] + Offsets[0][2] * (1 - xwt) + Offsets[4][2] * xwt])
                points.append([x + Offsets[1][0] * (1 - xwt) + Offsets[5][0] * xwt,
                              bounds[5] + Offsets[1][1] * (1 - xwt) + Offsets[5][1] * xwt,
                              bounds[2] + Offsets[1][2] * (1 - xwt) + Offsets[5][2] * xwt])
                points.append([x + Offsets[3][0] * (1 - xwt) + Offsets[7][0] * xwt,
                              bounds[5] + Offsets[3][1] * (1 - xwt) + Offsets[7][1] * xwt,
                              bounds[3] + Offsets[3][2] * (1 - xwt) + Offsets[7][2] * xwt])
                points.append([x + Offsets[2][0] * (1 - xwt) + Offsets[6][0] * xwt,
                              bounds[4] + Offsets[2][1] * (1 - xwt) + Offsets[6][1] * xwt,
                              bounds[3] + Offsets[2][2] * (1 - xwt) + Offsets[6][2] * xwt])
    
            points.append([slices[-1] + Offsets[4][0], bounds[4] + Offsets[4][1], bounds[2] + Offsets[4][2]])
            points.append([slices[-1] + Offsets[5][0], bounds[5] + Offsets[5][1], bounds[2] + Offsets[5][2]])
            points.append([slices[-1] + Offsets[7][0], bounds[5] + Offsets[7][1], bounds[3] + Offsets[7][2]])
            points.append([slices[-1] + Offsets[6][0], bounds[4] + Offsets[6][1], bounds[3] + Offsets[6][2]])
    
        faces.append([vll, vll + 3, vll + 2, vll + 1])
    
        for x in range(len(slices) - 1):
            faces.append([vll, vll + 1, vll + 5, vll + 4])
            vll += 1
            faces.append([vll, vll + 1, vll + 5, vll + 4])
            vll += 1
            faces.append([vll, vll + 1, vll + 5, vll + 4])
            vll += 1
            faces.append([vll, vll - 3, vll + 1, vll + 4])
            vll += 1
    
        faces.append([vll, vll + 1, vll + 2, vll + 3])
    
    
    # For generating Keystone Geometry
    
    
    def MakeAKeystone(xpos, width, zpos, ztop, zbtm, thick, bevel, vll=0, FaceExclude=[], xBevScl=1):
        __doc__ = """\
    
        MakeAKeystone returns lists of points and faces to be made into a
        square cornered keystone, with optional bevels.
    
        xpos: x position of the centerline
        width: x width of the keystone at the widest point (discounting bevels)
        zpos: z position of the widest point
        ztop: distance from zpos to the top
        zbtm: distance from zpos to the bottom
        thick: thickness
        bevel: the amount to raise the back vertex to account for arch beveling
        vll: the number of vertexes already in the mesh. len(mesh.verts) should give this number
    
        faceExclude: list of faces to exclude from the faces list.
                     0:left, 1:right, 2:bottom, 3:top, 4:back, 5:front
    
        xBevScl: how much to divide the end (+- x axis) bevel dimensions.
        Set to current average radius to compensate for angular distortion on curved blocks
    
        """
    
        points = []
        faces = []
        faceinclude = [1 for x in range(6)]
    
        for x in FaceExclude:
            faceinclude[x] = 0
    
        Wid = width / 2.0
        Thk = thick / 2.0
    
    
        # The front top point
        points.append([xpos, Thk, Top])
        # The front left point
    
        points.append([xpos - Wid, Thk, zpos])
    
        # The front bottom point
        points.append([xpos, Thk, Btm])
        # The front right point
    
        points.append([xpos + Wid, Thk, zpos])
    
            MirrorPoints.append([i[0], -i[1], i[2]])
    
        points += MirrorPoints
        points[6][2] += bevel
    
    
        faces.append([3, 2, 1, 0])
        faces.append([4, 5, 6, 7])
        faces.append([4, 7, 3, 0])
        faces.append([5, 4, 0, 1])
        faces.append([6, 5, 1, 2])
        faces.append([7, 6, 2, 3])
    
        # Offset the vertex numbers by the number of vertices already in the list
    
            for j in range(len(faces[i])):
                faces[i][j] += vll
    
    # for finding line/circle intercepts
    
    def circ(offs=0., r=1.):
    
        __doc__ = """\
        offs is the distance perpendicular to the line to the center of the circle
        r is the radius of the circle
    
        circ returns the distance parallel to the line to the center of the circle at the intercept.
    
        if offs > r:
            return None
        elif offs == r:
            return 0.
        else:
            return sqrt(r ** 2 - offs ** 2)
    
    
    # class openings in the wall
    
    
    class opening:
        __doc__ = """\
        This is the class for holding the data for the openings in the wall.
        It has methods for returning the edges of the opening for any given position value,
        as well as bevel settings and top and bottom positions.
        It stores the 'style' of the opening, and all other pertinent information.
        """
        # x = 0. # x position of the opening
        # z = 0. # x position of the opening
        # w = 0. # width of the opening
        # h = 0. # height of the opening
    
        r = 0    # top radius of the arch (derived from 'v')
        rl = 0   # lower radius of the arch (derived from 'vl')
        rt = 0   # top arch thickness
        rtl = 0  # lower arch thickness
        ts = 0   # Opening side thickness, if greater than average width, replaces it.
        c = 0    # top arch corner position (for low arches), distance from the top of the straight sides
        cl = 0   # lower arch corner position (for low arches), distance from the top of the straight sides
        # form = 0  # arch type (unused for now)
        # b = 0.    # back face bevel distance, like an arrow slit
        v = 0.   # top arch height
        vl = 0.  # lower arch height
    
        # variable "s" is used for "side" in the "edge" function.
        # it is a signed int, multiplied by the width to get + or - of the center
    
        def btm(self):
    
            if self.vl <= self.w / 2:
                return self.z - self.h / 2 - self.vl - self.rtl
            else:
                return self.z - sqrt((self.rl + self.rtl) ** 2 - (self.rl - self.w / 2) ** 2) - self.h / 2
    
            if self.v <= self.w / 2:
                return self.z + self.h / 2 + self.v + self.rt
            else:
                return sqrt((self.r + self.rt) ** 2 - (self.r - self.w / 2) ** 2) + self.z + self.h / 2
    
        # crits returns the critical split points, or discontinuities, used for making rows
    
            if self.vl > 0:  # for lower arch
    
                # add the top point if it is pointed
    
                # if self.vl >= self.w/2.: critlist.append(self.btm())
                if self.vl < self.w / 2.:  # else: for low arches, with wedge blocks under them
                    # critlist.append(self.btm())
                    critlist.append(self.z - self.h / 2 - self.cl)
    
            if self.h > 0:  # if it has a height, append points at the top and bottom of the main square section
                critlist += [self.z - self.h / 2, self.z + self.h / 2]
    
            else:  # otherwise, append just one in the center
                critlist.append(self.z)
    
    
            if self.v > 0:  # for the upper arch
                if self.v < self.w / 2:  # add the splits for the upper wedge blocks, if needed
                    critlist.append(self.z + self.h / 2 + self.c)
                    # critlist.append(self.top())
                # otherwise just add the top point, if it is pointed
                # else: critlist.append(self.top())
    
    
            return critlist
    
        # get the side position of the opening.
        # ht is the z position; s is the side: 1 for right, -1 for left
        # if the height passed is above or below the opening, return None
        def edgeS(self, ht, s):
    
            # set the row radius: 1 for standard wall (flat)
            if radialized:
    
                if slope:
                    r1 = abs(dims['t'] * sin(ht * PI / (dims['t'] * 2)))
                else:
                    r1 = abs(ht)
            else:
                r1 = 1
    
            # Go through all the options, and return the correct value
            if ht < self.btm():  # too low
    
            elif ht > self.top():  # too high
    
                return None
    
            # Check for circ returning None - prevent TypeError (script failure) with float.
            # in this range, pass the lower arch info
    
            elif ht <= self.z - self.h / 2 - self.cl:
                if self.vl > self.w / 2:
                    circVal = circ(ht - self.z + self.h / 2, self.rl + self.rtl)
                    if circVal is None:
    
                    else:
                        return self.x + s * (self.w / 2. - self.rl + circVal) / r1
    
                    circVal = circ(ht - self.z + self.h / 2 + self.vl - self.rl, self.rl + self.rtl)
                    if circVal is None:
    
                    else:
                        return self.x + s * circVal / r1
    
            # in this range, pass the top arch info
            elif ht >= self.z + self.h / 2 + self.c:
                if self.v > self.w / 2:
                    circVal = circ(ht - self.z - self.h / 2, self.r + self.rt)
                    if circVal is None:
    
                    else:
                        return self.x + s * (self.w / 2. - self.r + circVal) / r1
    
                    circVal = circ(ht - (self.z + self.h / 2 + self.v - self.r), self.r + self.rt)
                    if circVal is None:
    
                    else:
                        return self.x + s * circVal / r1
    
            # in this range pass the lower corner edge info
            elif ht <= self.z - self.h / 2:
                d = sqrt(self.rtl ** 2 - self.cl ** 2)
                if self.cl > self.rtl / sqrt(2.):
                    return self.x + s * (self.w / 2 + (self.z - self.h / 2 - ht) * d / self.cl) / r1
                else:
                    return self.x + s * (self.w / 2 + d) / r1
    
            # in this range pass the upper corner edge info
            elif ht >= self.z + self.h / 2:
                d = sqrt(self.rt ** 2 - self.c ** 2)
                if self.c > self.rt / sqrt(2.):
                    return self.x + s * (self.w / 2 + (ht - self.z - self.h / 2) * d / self.c) / r1
                else:
                    return self.x + s * (self.w / 2 + d) / r1
    
            # in this range, pass the middle info (straight sides)
            else:
                return self.x + s * self.w / 2 / r1
    
    
        # get the top or bottom of the opening
        # ht is the x position; s is the side: 1 for top, -1 for bottom
        def edgeV(self, ht, s):
    
            dist = abs(self.x - ht)
    
    
                # take the distance and adjust for radial geometry, return dist
    
                        dist = dist * abs(dims['t'] * sin(sideVal * PI / (dims['t'] * 2)))
    
            if s > 0:  # and (dist <= self.edgeS(self.z + self.h / 2 + self.c, 1) - self.x):  # check top down
                # hack for radialized masonry, import approx Z instead of self.top()
    
                # no arch on top, flat
                if not self.r:
                    return self.z + self.h / 2
    
                # pointed arch on top
                elif self.v > self.w / 2:
                    circVal = circ(dist - self.w / 2 + self.r, self.r + self.rt)
                    if circVal is None:
    
                    else:
                        return self.z + self.h / 2 + circVal
    
                # domed arch on top
    
                    circVal = circ(dist, self.r + self.rt)
                    if circVal is None:
    
                    else:
                        return self.z + self.h / 2 + self.v - self.r + circVal
    
            else:  # and (dist <= self.edgeS(self.z - self.h / 2 - self.cl, 1) - self.x):  # check bottom up
                # hack for radialized masonry, import approx Z instead of self.top()
    
                # no arch on bottom
                if not self.rl:
                    return self.z - self.h / 2
    
                # pointed arch on bottom
                elif self.vl > self.w / 2:
                    circVal = circ(dist - self.w / 2 + self.rl, self.rl + self.rtl)
                    if circVal is None:
    
                    else:
                        return self.z - self.h / 2 - circVal
    
                # old conditional? if (dist-self.w / 2 + self.rl) <= (self.rl + self.rtl):
                # domed arch on bottom
    
                    circVal = circ(dist, self.rl + self.rtl)   # dist-self.w / 2 + self.rl
                    if circVal is None:
    
                    else:
                        return self.z - self.h / 2 - self.vl + self.rl - circVal
    
            # and this never happens - but, leave it as failsafe :)
            debug_prints(func="opening.EdgeV",
                         text="Got all the way out of the edgeV!  Not good!")
            debug_print_vars("opening x = ", self.x, ", opening z = ", self.z)
    
    
            if ht > (self.z + self.h / 2):
                return 0.0
            if ht < (self.z - self.h / 2):
                return 0.0
    
                if slope:
                    r1 = abs(dims['t'] * sin(ht * PI / (dims['t'] * 2)))
                else:
                    r1 = abs(ht)
            else:
                r1 = 1
    
            bevel = self.b / r1
            return bevel
    
        def __init__(self, xpos, zpos, width, height, archHeight=0, archThk=0,
                     archHeightLower=0, archThkLower=0, bevel=0, edgeThk=0):
            self.x = float(xpos)
            self.z = float(zpos)
            self.w = float(width)
            self.h = float(height)
            self.rt = archThk
            self.rtl = archThkLower
            self.v = archHeight
            self.vl = archHeightLower
    
            if self.w <= 0:
                self.w = SMALL
    
            # find the upper arch radius
            if archHeight >= width / 2:
    
                self.r = (self.v ** 2) / self.w + self.w / 4
    
            elif archHeight <= 0:
                # No arches
                self.r = 0
                self.v = 0
            else:
                # Two arches
    
                self.r = (self.w ** 2) / (8 * self.v) + self.v / 2.
                self.c = self.rt * cos(atan(self.w / (2 * (self.r - self.v))))
    
            # find the lower arch radius
            if archHeightLower >= width / 2:
                self.rl = (self.vl ** 2) / self.w + self.w / 4
    
            elif archHeightLower <= 0:
                self.rl = 0
                self.vl = 0
            else:
    
                self.rl = (self.w ** 2) / (8 * self.vl) + self.vl / 2.
                self.cl = self.rtl * cos(atan(self.w / (2 * (self.rl - self.vl))))
    
            # self.form = something?
    
    
    # class for the whole wall boundaries; a sub-class of "opening"
    
    class openingInvert(opening):
    
        # this is supposed to switch the sides of the opening
        # so the wall will properly enclose the whole wall.
    
    
        def edgeS(self, ht, s):
            return opening.edgeS(self, ht, -s)
    
        def edgeV(self, ht, s):
            return opening.edgeV(self, ht, -s)
    
    
    class rowOb:
        __doc__ = """\
        This is the class for holding the data for individual rows of blocks.
        each row is required to have some edge blocks, and can also have
        intermediate sections of "normal" blocks.
        """
        radius = 1
        EdgeOffset = 0.
    
        def FillBlocks(self):
            # Set the radius variable, in the case of radial geometry
            if radialized:
    
                if slope:
                    self.radius = dims['t'] * (sin(self.z * PI / (dims['t'] * 2)))
                else:
                    self.radius = self.z
    
            # initialize internal variables from global settings
    
    
            SetH = settings['h']
            SetHwt = settings['hwt']
            SetWid = settings['w']
            SetWidMin = settings['wm']
            SetWidVar = settings['wv']
            SetGrt = settings['g']
            SetGrtVar = settings['gv']
            SetRowHeightLink = settings['rwhl']
            SetDepth = settings['d']
            SetDepthVar = settings['dv']
    
    
            # height weight, used for making shorter rows have narrower blocks, and vice-versa
            hwt = ((self.h / SetH - 1) * SetHwt + 1)
    
    
            # set variables for persistent values: loop optimization, readability, single ref for changes.
    
    
            avgDist = hwt * SetWid / self.radius
            minDist = SetWidMin / self.radius
            deviation = hwt * SetWidVar / self.radius
            grtOffset = SetGrt / (2 * self.radius)
    
            grt = (SetGrt + rndc() * SetGrtVar) / (self.radius)
            ThisBlockHeight = self.h + rndc() * (1 - SetRowHeightLink) * SetGrtVar
            ThisBlockDepth = rndd() * SetDepthVar + SetDepth
    
                divs = fill(segment[0] + grtOffset, segment[1] - grtOffset, avgDist, minDist, deviation)
    
                # loop through the divisions, adding blocks for each one
                for i in range(len(divs) - 1):
                    ThisBlockx = (divs[i] + divs[i + 1]) / 2
                    ThisBlockw = divs[i + 1] - divs[i] - grt
    
    
                    self.BlocksNorm.append([ThisBlockx, self.z, ThisBlockw, ThisBlockHeight, ThisBlockDepth, None])
    
    
                    if SetDepthVar:  # vary depth
                        ThisBlockDepth = rndd() * SetDepthVar + SetDepth
    
                    if SetGrtVar:  # vary grout
                        grt = (SetGrt + rndc() * SetGrtVar) / (self.radius)
                        ThisBlockHeight = self.h + rndc() * (1 - SetRowHeightLink) * SetGrtVar
    
        def __init__(self, centerheight, rowheight, edgeoffset=0.):
    
            self.z = float(centerheight)
            self.h = float(rowheight)
            self.EdgeOffset = float(edgeoffset)
    
    
        # THIS INITIALIZATION IS IMPORTANT!  OTHERWISE ALL OBJECTS WILL HAVE THE SAME LISTS!
    
            self.BlocksEdge = []
            self.RowSegments = []
            self.BlocksNorm = []
    
    
    
    def arch(ra, rt, x, z, archStart, archEnd, bevel, bevAngle, vll):
    
        __doc__ = """\
        Makes a list of faces and vertexes for arches.
        ra: the radius of the arch, to the center of the bricks
        rt: the thickness of the arch
        x: x center location of the circular arc, as if the arch opening were centered on x = 0
        z: z center location of the arch
        anglebeg: start angle of the arch, in radians, from vertical?
        angleend: end angle of the arch, in radians, from vertical?
        bevel: how much to bevel the inside of the arch.
        vll: how long is the vertex list already?
        """
        avlist = []
        aflist = []
    
    
        # initialize internal variables for global settings
    
        SetGrt = settings['g']
        SetGrtVar = settings['gv']
        SetDepth = settings['d']
        SetDepthVar = settings['dv']
    
        # Init loop variables
    
        def bevelEdgeOffset(offsets, bevel, side):
            """
            Take the block offsets and modify it for the correct bevel.
    
            offsets = the offset list. See MakeABlock
            bevel = how much to offset the edge
            side = -1 for left (right side), 1 for right (left side)
            """
    
            left = (0, 2, 3)
            right = (4, 6, 7)
            if side == 1:
                pointsToAffect = right
            else:
                pointsToAffect = left
    
            for num in pointsToAffect:
                offsets[num] = offsets[num][:]
                offsets[num][0] += -bevel * side
    
    
        ArchInner = ra - rt / 2
        ArchOuter = ra + rt / 2 - SetGrt + rndc() * SetGrtVar
    
        DepthBack = - SetDepth / 2 - rndc() * SetDepthVar
        DepthFront = SetDepth / 2 + rndc() * SetDepthVar
    
        if radialized:
            subdivision = settings['sdv']
        else:
            subdivision = 0.12
    
        grt = (SetGrt + rndc() * SetGrtVar) / (2 * ra)  # init grout offset for loop
    
        # set up the offsets, it will be the same for every block
    
        offsets = ([[0] * 2 + [bevel]] + [[0] * 3] * 3) * 2
    
        # make the divisions in the "length" of the arch
        divs = fill(archStart, archEnd, settings['w'] / ra, settings['wm'] / ra, settings['wv'] / ra)
    
        for i in range(len(divs) - 1):
    
                bevelEdgeOffset(ThisOffset, bevAngle, - 1)
            elif i == len(divs) - 2:
    
                ThisOffset = offsets[:]
                bevelEdgeOffset(ThisOffset, bevAngle, 1)
            else:
                ThisOffset = offsets
    
    
            geom = MakeABlock(
                        [divs[i] + grt, divs[i + 1] - grt, ArchInner, ArchOuter, DepthBack, DepthFront],
                        subdivision, len(avlist) + vll, ThisOffset, [], None, ra
                        )
    
            if SetDepthVar:  # vary depth
                DepthBack = -SetDepth / 2 - rndc() * SetDepthVar
                DepthFront = SetDepth / 2 + rndc() * SetDepthVar
    
            if SetGrtVar:  # vary grout
                grt = (settings['g'] + rndc() * SetGrtVar) / (2 * ra)
                ArchOuter = ra + rt / 2 - SetGrt + rndc() * SetGrtVar
    
        for i, vert in enumerate(avlist):
            v0 = vert[2] * sin(vert[0]) + x
    
            v2 = vert[2] * cos(vert[0]) + z
    
            if radialized == 1:
                if slope == 1:
                    r1 = dims['t'] * (sin(v2 * PI / (dims['t'] * 2)))
                else:
                    r1 = v2
                v0 = v0 / r1
    
            avlist[i] = [v0, v1, v2]
    
        return (avlist, aflist)
    
        The 'sketch' function creates a list of openings from the general specifications passed to it.
        It takes curved and domed walls into account, placing the openings at the appropriate angular locations
        """
        boundlist = []
        for x in openingSpecs:
            if x['rp']:
    
                if radialized:
                    r1 = x['z']
                else:
                    r1 = 1
    
                if x['x'] > (x['w'] + settings['wm']):
                    spacing = x['x'] / r1
                else:
                    spacing = (x['w'] + settings['wm']) / r1
    
                minspacing = (x['w'] + settings['wm']) / r1
    
                divs = fill(dims['s'], dims['e'], spacing, minspacing, center=1)
    
                for posidx in range(len(divs) - 2):
                    boundlist.append(opening(divs[posidx + 1], x['z'], x['w'], x['h'],
                                            x['v'], x['t'], x['vl'], x['tl'], x['b']))
            else:
                boundlist.append(opening(x['x'], x['z'], x['w'], x['h'], x['v'], x['t'], x['vl'], x['tl'], x['b']))
    
    
        return boundlist
    
    
    def wedgeBlocks(row, opening, leftPos, rightPos, edgeBinary, r1):
        __doc__ = """\
        Makes wedge blocks for the left and right sides, depending
        example:
        wedgeBlocks(row, LeftWedgeEdge, LNerEdge, LEB, r1)
        wedgeBlocks(row, RNerEdge, RightWedgeEdge, REB, r1)
        """
    
        wedgeEdges = fill(leftPos, rightPos, settings['w'] / r1, settings['wm'] / r1,
                          settings['wv'] / r1)
    
        for i in range(len(wedgeEdges) - 1):
            x = (wedgeEdges[i + 1] + wedgeEdges[i]) / 2
            grt = (settings['g'] + rndd() * settings['gv']) / r1
            w = wedgeEdges[i + 1] - wedgeEdges[i] - grt
    
            ThisBlockDepth = rndd() * settings['dv'] + settings['d']
    
            # edgeV may return "None" - causing TypeError for math op.
            # use 0 until wedgeBlocks operation worked out
            edgeVal = opening.edgeV(x - w / 2, edgeBinary)
            if edgeVal is None:
                edgeVal = 0.0
    
            LeftVertOffset = -(row.z - (row.h / 2) * edgeBinary - edgeVal)
    
            # edgeV may return "None" - causing TypeError for math op.
            # use 0 until wedgeBlocks operation worked out
            edgeVal = opening.edgeV(x + w / 2, edgeBinary)
            if edgeVal is None:
                edgeVal = 0.0
    
            RightVertOffset = -(row.z - (row.h / 2) * edgeBinary - edgeVal)
    
            # Wedges are on top = off,  blank,  off,  blank
            # Wedges are on btm = blank,  off,  blank,  off
            ThisBlockOffsets = [[0, 0, LeftVertOffset]] * 2 + [[0] * 3] * 2 + [[0, 0, RightVertOffset]] * 2
    
            # Insert or append "blank" for top or bottom wedges.
    
            if edgeBinary == 1:
                ThisBlockOffsets = ThisBlockOffsets + [[0] * 3] * 2
            else:
                ThisBlockOffsets = [[0] * 3] * 2 + ThisBlockOffsets
    
            row.BlocksEdge.append([x, row.z, w, row.h, ThisBlockDepth, ThisBlockOffsets])
    
    def bevelBlockOffsets(offsets, bevel, side):
        """
        Take the block offsets and modify it for the correct bevel.
    
        offsets = the offset list. See MakeABlock
        bevel = how much to offset the edge
        side = -1 for left (right side), 1 for right (left side)
        """
    
        if side == 1:
            pointsToAffect = (0, 2)  # right
        else:
            pointsToAffect = (4, 6)  # left
    
        for num in pointsToAffect:
            offsets[num] = offsets[num][:]
            offsets[num][0] += bevel * side
    
    
    def rowProcessing(row, Thesketch, WallBoundaries):
        __doc__ = """\
        Take row and opening data and process a single row, adding edge and fill blocks to the row data.
        """
    
        # set end blocks
        # check for openings, record top and bottom of row for right and left of each
        # if both top and bottom intersect create blocks on each edge, appropriate to the size of the overlap
        # if only one side intersects, run fill to get edge positions, but this should never happen
    
        if radialized:  # this checks for radial stonework, and sets the row radius if required
            if slope:
                r1 = abs(dims['t'] * sin(row.z * PI / (dims['t'] * 2)))
            else:
                r1 = abs(row.z)
        else:
            r1 = 1
    
    
        # set the edge grout thickness, especially with radial stonework in mind
    
        edgrt = settings['ge'] * (settings['g'] / 2 + rndc() * settings['gv']) / (2 * r1)
    
    
        # Sets up a list of  intersections of top of row with openings,
    
        # from left to right [left edge of opening,  right edge of opening,  etc...]
        # initially just the left and right edge of the wall
        edgetop = [[dims['s'] + row.EdgeOffset / r1 + edgrt, WallBoundaries],