const bendRad = 0.05
const thickness = 0.1046
const railHeight = 45 // u
const originStart = [4, 1, 5.114]
const depth = 48
const serverDepth = 31
const width = 21.53

// simple caster model at each corner
fn caster = (originStart) => {
  const plane001c = {
    plane: {
      origin: [
        -(3.543 - 2.756) / 2 + originStart[0],
        -(3.543 - 2.756) / 2 + originStart[1],
        4.114
      ],
      x_axis: [1.0, 0.0, 0.0],
      y_axis: [0.0, 1.0, 0.0],
      z_axis: [0.0, 0.0, 1.0]
    }
  }

  const sketch001c = startSketchOn(plane001c)
    |> startProfileAt([0, 0], %)
    |> xLine(3.543, %)
    |> yLine(3.543, %)
    |> xLine(-3.543, %)
    |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
    |> close()
    |> hole(circle({ center: [
         (3.543 - 2.756) / 2,
         (3.543 - 2.756) / 2
       ], radius: 8.8 / 2 / 25.4 }, %), %)
    |> hole(circle({ center: [
         (3.543 - 2.756) / 2 + 2.756,
         (3.543 - 2.756) / 2
       ], radius: 8.8 / 2 / 25.4 }, %), %)
    |> hole(circle({ center: [
         (3.543 - 2.756) / 2,
         (3.543 - 2.756) / 2 + 2.756
       ], radius: 8.8 / 2 / 25.4 }, %), %)
    |> hole(circle({ center: [
         (3.543 - 2.756) / 2 + 2.756,
         (3.543 - 2.756) / 2 + 2.756
       ], radius: 8.8 / 2 / 25.4 }, %), %)
    |> extrude(length = -.25)

  const sketch002c = startSketchOn(sketch001c, 'START')
    |> startProfileAt([-originStart[0], 2.2 + originStart[1]], %)
    |> arc({
         angle_start: 30,
         angle_end: 330,
         radius: 3.2 / 2
       }, %)
    |> close()
    |> extrude(length = 3.1)

  const plane002c = {
    plane: {
      origin: [
        0 + originStart[0],
        0.8 + originStart[1],
        0
      ],
      x_axis: [1, 0, 0],
      y_axis: [0, 0, 1],
      z_axis: [1, 0, 0]
    }
  }
  const sketch003c = startSketchOn(plane002c)
    |> circle({ center: [0, 1.2], radisu: 2.48 / 2 }, %)
  const examplec = extrude(sketch003c, length = -1 - (3 / 16))
  return examplec
}

// generate 4 casters
caster([
  (3.543 - 2.756) / 2,
  (3.543 - 2.756) / 2 + 2.75
])
caster([
  -(3.543 - 2.756) / 2 + width - 2.756,
  (3.543 - 2.756) / 2 + .4
])
caster([
  (3.543 - 2.756) / 2,
  serverDepth + 5 - ((3.543 - 2.756) / 2) - 2.2
])
caster([
  -(3.543 - 2.756) / 2 + width - 2.756,
  depth - ((3.543 - 2.756) / 2) - 2.756 - 1.7
])

// left wall
const plane001 = {
  plane: {
    origin: [
      originStart[0] - 4,
      originStart[1] + 2,
      4.114
    ],
    x_axis: [0, 1, 0],
    y_axis: [0, 0, 1],
    z_axis: [1, 0, 0]
  }
}

const sketch001l = startSketchOn(plane001)
  |> startProfileAt([0, 0], %)
  |> xLine(serverDepth + .8, %)
  |> angledLineToY({ angle: -45, to: 1 }, %)
  |> xLine(-serverDepth + 2 - .8, %, $seg01)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude001l = extrude(sketch001l, length = 1)

const sketch002l = startSketchOn(plane001)
  |> startProfileAt([serverDepth + .8, 0], %)
  |> yLine(railHeight * 1.75 + 2, %)
  |> angledLineToX({
       angle: -135,
       to: serverDepth - 1 + .8
     }, %)
  |> yLine(-railHeight * 1.75, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude002l = extrude(sketch002l, length = 1)

const sketch003l = startSketchOn(plane001)
  |> startProfileAt([
       serverDepth + .8,
       railHeight * 1.75 + 2
     ], %)
  |> xLine(-serverDepth - .8, %, $seg02)
  |> angledLineToY({
       angle: -45,
       to: railHeight * 1.75 - 1 + 2
     }, %)
  |> xLine(serverDepth - 2 + .8, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude003l = extrude(sketch003l, length = 1)

const sketch004l = startSketchOn(plane001)
  |> startProfileAt([0, 0], %)
  |> yLine(railHeight * 1.75 + 2, %)
  |> angledLineToY({
       angle: 135,
       to: railHeight * 1.75 + 2 - 1
     }, %)
  |> yLine(-railHeight * 1.75, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude004l = extrude(sketch004l, length = 1)

const sketch005l = startSketchOn(plane001)
  |> startProfileAt([serverDepth - 1.25, 1], %)
  |> line(end = [-serverDepth + 2.25, railHeight * 1.75], tag = $lineToIntersect4)
  |> xLine(1, %)
  |> line(end = [serverDepth - 2.25, -railHeight * 1.75], tag = $lineToIntersect5)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude005l = extrude(sketch005l, length = 1)

const sketch006l = startSketchOn(plane001)
  |> startProfileAt([1, 1], %)
  |> angledLineThatIntersects({
       angle: 70,
       intersectTag: lineToIntersect4,
       offset: 0
     }, %)
  |> angledLine({ angle: -70, length: 1.414 }, %)
  |> angledLineToY({ angle: 70 + 180, to: 2 - 1 }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude006l = extrude(sketch006l, length = 1)

const sketch007l = startSketchOn(plane001)
  |> startProfileAt([
       serverDepth - 1.2,
       railHeight * 1.75 + 1
     ], %)
  |> angledLineThatIntersects({
       angle: 70,
       intersectTag: lineToIntersect5,
       offset: 0
     }, %)
  |> angledLine({ angle: -70, length: 1.414 }, %)
  |> angledLineToY({
       angle: 70 + 180,
       to: railHeight * 1.75 + 1
     }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude007l = extrude(sketch007l, length = 1)

// right wall
const plane002 = {
  plane: {
    origin: [
      originStart[0] - 4 + width - 1,
      originStart[1] - 1,
      4.114
    ],
    x_axis: [0, 1, 0],
    y_axis: [0, 0, 1],
    z_axis: [1, 0, 0]
  }
}

const sketch001w = startSketchOn(plane002)
  |> startProfileAt([0, 0], %)
  |> xLine(depth, %)
  |> angledLineToY({ angle: -45, to: 1 }, %)
  |> xLine(-depth + 2, %, $seg01w)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude001w = extrude(sketch001w, length = 1)

const sketch002w = startSketchOn(plane002)
  |> startProfileAt([depth, 0], %)
  |> yLine(railHeight * 1.75 + 2, %)
  |> angledLineToX({ angle: -135, to: depth - 1 }, %)
  |> yLine(-railHeight * 1.75, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude002w = extrude(sketch002w, length = 1)

const sketch003w = startSketchOn(plane002)
  |> startProfileAt([depth, railHeight * 1.75 + 2], %)
  |> xLine(-depth, %, $seg02w)
  |> angledLineToY({
       angle: -45,
       to: railHeight * 1.75 - 1 + 2
     }, %)
  |> xLine(depth - 2, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude003w = extrude(sketch003w, length = 1)

const sketch004w = startSketchOn(plane002)
  |> startProfileAt([0, 0], %)
  |> yLine(railHeight * 1.75 + 2, %)
  |> angledLineToY({
       angle: 135,
       to: railHeight * 1.75 + 2 - 1
     }, %)
  |> yLine(-railHeight * 1.75, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude004w = extrude(sketch004w, length = 1)

const sketch005w = startSketchOn(plane002)
  |> startProfileAt([1, 40.6 + 1.75 / 2], %)
  |> angledLine({ angle: -23, length: 35.5 }, %)
  |> angledLine({ angle: -23 + 90 + 45, length: 1.413 }, %)
  |> angledLineToX({ angle: -23, to: 1 }, %, $lineToIntersect)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude005w = extrude(sketch005w, length = 1)

const sketch006w = startSketchOn(plane002)
  |> startProfileAt([
       1 + 35.5 * cos(23 * pi() / 180),
       40.6 - (35.5 * sin(23 * pi() / 180)) + 1.75 / 2
     ], %)
  |> angledLineToX({ angle: -23 + 90, to: depth - 1 }, %)
  |> yLine(2.56, %)
  |> angledLineThatIntersects({
       angle: -23 + 90 + 180,
       intersectTag: lineToIntersect,
       offset: 0
     }, %, $lineToIntersect2)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude006w = extrude(sketch006w, length = 1)

const sketch007w = startSketchOn(plane002)
  |> startProfileAt([depth - 1, 60.65 + 1.75 / 2], %)
  |> angledLine({ angle: -23 + 180, length: 34.93 }, %, $lineToIntersect3)
  |> angledLine({ angle: 23 - 90, length: 1.414 }, %)
  |> angledLineThatIntersects({
       angle: -23 + 180,
       intersectTag: lineToIntersect2,
       offset: 0
     }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude007w = extrude(sketch007w, length = 1)

const sketch008w = startSketchOn(plane002)
  |> startProfileAt([1, 41.7 + 1.75 / 2], %)
  |> angledLineThatIntersects({
       angle: -23 + 90,
       intersectTag: lineToIntersect3,
       offset: 0
     }, %)
  |> angledLine({ angle: -23 - 45, length: 1.414 }, %)
  |> angledLineThatIntersects({
       angle: -23 - 90,
       intersectTag: lineToIntersect,
       offset: 0
     }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude008w = extrude(sketch008w, length = 1)

const sketch009w = startSketchOn(plane002)
  |> startProfileAt([31.2, 33.3 + 1.75 / 2], %)
  |> angledLine({ angle: -23 - 45, length: 1.414 }, %)
  |> angledLine({ angle: 90 - 23, length: 28 }, %)
  |> angledLine({ angle: -23 + 45, length: -1.414 }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude009w = extrude(sketch009w, length = 1)

const sketch010w = startSketchOn(plane002)
  |> startProfileAt([31.2, 33.3 + 1.75 / 2], %)
  |> angledLine({ angle: -23 - 45, length: 1.414 }, %)
  |> angledLine({ angle: 180 - 23, length: 28 }, %)
  |> angledLine({ angle: -23 + 45, length: 1.414 }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude010w = extrude(sketch010w, length = 1)

const sketch011w = startSketchOn(plane002)
  |> startProfileAt([
       31.2 - ((28 - 2) * cos(23 * pi() / 180)),
       33.3 + (28 - 2) * sin(23 * pi() / 180) + 1.75 / 2
     ], %)
  |> angledLine({ angle: 90 - 23, length: 28 - 2 }, %)
  |> angledLine({ angle: -23 - 45, length: -1.414 }, %)
  |> angledLine({ angle: 90 - 23 + 180, length: 28 }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude011w = extrude(sketch011w, length = 1)

const sketch012w = startSketchOn(plane002)
  |> startProfileAt([
       31.2 + (28 - 2) * sin(23 * pi() / 180),
       33.3 + (28 - 2) * cos(23 * pi() / 180) + 1.75 / 2
     ], %)
  |> angledLine({ angle: 180 - 23, length: 28 - 2 }, %)
  |> angledLine({ angle: -23 - 45, length: -1.414 }, %)
  |> angledLine({ angle: -23, length: 28 }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude012w = extrude(sketch012w, length = 1)

const sketch013w = startSketchOn(plane002)
  |> startProfileAt([
       1 + 4 * cos(23 * pi() / 180),
       40.6 - (4 * sin(23 * pi() / 180)) + 1.75 / 2
     ], %)
  |> angledLine({ angle: -23, length: 1 }, %)
  |> angledLineToX({ angle: -23 + 90, to: 1 }, %)
  |> yLine(2.56, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude013w = extrude(sketch013w, length = 1)

const sketch014w = startSketchOn(plane002)
  |> startProfileAt([
       1 + 12 * cos(23 * pi() / 180),
       40.6 - (12 * sin(23 * pi() / 180)) + 1.75 / 2
     ], %)
  |> angledLine({ angle: -23 - 90, length: 36 / 2 }, %)
  |> angledLine({ angle: -23, length: 1 }, %)
  |> angledLine({ angle: -23 - 90, length: -36 / 2 }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude014w = extrude(sketch014w, length = 1)

const sketch015w = startSketchOn(plane002)
  |> startProfileAt([
       1 + (36 - 5.55 - 8) * cos(23 * pi() / 180),
       40.6 - ((36 - 5.55 - 8) * sin(23 * pi() / 180)) + 1.75 / 2
     ], %)
  |> angledLine({ angle: -23 - 90, length: 36 / 2 }, %)
  |> angledLine({ angle: -23, length: 1 }, %)
  |> angledLine({ angle: -23 - 90, length: -36 / 2 }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude015w = extrude(sketch015w, length = 1)

const sketch016w = startSketchOn(plane002)
  |> startProfileAt([
       1 + (36 - 5.5) * cos(23 * pi() / 180),
       40.6 - ((36 - 5.5) * sin(23 * pi() / 180)) + 1.75 / 2
     ], %)
  |> angledLine({ angle: -23 - 90, length: 36 / 2 }, %)
  |> angledLine({ angle: -23, length: 1 }, %)
  |> angledLine({ angle: -23 - 90, length: -36 / 2 }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude016w = extrude(sketch016w, length = 1)

const sketch017w = startSketchOn(plane002)
  |> startProfileAt([
       depth - 1 - (3.7 * cos(23 * pi() / 180)),
       60.65 + 3.7 * sin(23 * pi() / 180) + 1.75 / 2
     ], %)
  |> arc({
       angleStart: -23,
       angleEnd: 180 - 23,
       radius: 7 / 2 + 2
     }, %)
  |> angledLine({ angle: -23 + 180, length: -1 }, %)
  |> arc({
       angleStart: 180 - 23,
       angleEnd: -23,
       radius: 7 / 2 + 1
     }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude017w = extrude(sketch017w, length = 1)

const sketch018w = startSketchOn(plane002)
  |> startProfileAt([
       depth - 1 - (19.3 * cos(23 * pi() / 180)),
       60.65 + 19.3 * sin(23 * pi() / 180) + 1.75 / 2
     ], %)
  |> arc({
       angleStart: -23,
       angleEnd: 180 - 23,
       radius: 7 / 2 + 2
     }, %)
  |> angledLine({ angle: -23 + 180, length: -1 }, %)
  |> arc({
       angleStart: 180 - 23,
       angleEnd: -23,
       radius: 7 / 2 + 1
     }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude018w = extrude(sketch018w, length = 1)

const sketch019w = startSketchOn(plane002)
  |> startProfileAt([1, 27.8 + 1.75 / 2], %)
  |> angledLine({ angle: -23, length: 7 }, %)
  |> angledLine({ angle: -23 + 90, length: -1 }, %)
  |> angledLineToX({ angle: -23, to: 1 }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude019w = extrude(sketch019w, length = 1)

const sketch020w = startSketchOn(plane002)
  |> startProfileAt([
       1 + (36 - 5.53 - 12) * cos(23 * pi() / 180),
       27.8 + 1.75 / 2 - ((36 - 5.53 - 12) * sin(23 * pi() / 180))
     ], %)
  |> angledLine({ angle: -23, length: 7 }, %)
  |> angledLine({ angle: -23 + 90, length: -1 }, %)
  |> angledLine({ angle: -23 + 180, length: 7 }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude020w = extrude(sketch020w, length = 1)

const sketch021w = startSketchOn(plane002)
  |> startProfileAt([1, 21.9], %)
  |> angledLineToX({ angle: -23, to: depth - 1 }, %)
  |> yLine(-1.1, %)
  |> angledLineToX({ angle: -23, to: 1 }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude021w = extrude(sketch021w, length = 1)

const sketch022w = startSketchOn(plane002)
  |> startProfileAt([depth - 1, 74.1], %)
  |> angledLineToY({
       angle: 180 - 23,
       to: railHeight * 1.75 + 1
     }, %)
  |> xLine(-2.56, %)
  |> angledLineToX({ angle: -23, to: depth - 1 }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude022w = extrude(sketch022w, length = 1)

const sketch023w = startSketchOn(plane002)
  |> startProfileAt([1, 69.53 + 1.75], %)
  |> angledLineToY({
       angle: 90 - 23,
       to: railHeight * 1.75 + 1
     }, %)
  |> xLine(1.086, %)
  |> angledLineToX({ angle: 90 - 23, to: 1 }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude023w = extrude(sketch023w, length = 1)

const sketch024w = startSketchOn(plane002)
  |> startProfileAt([1, 16.5], %)
  |> angledLineToY({ angle: -23, to: 1 }, %)
  |> xLine(-2.56, %)
  |> angledLineToX({ angle: -23, to: 1 }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude024w = extrude(sketch024w, length = 1)

const sketch025w = startSketchOn(plane002)
  |> startProfileAt([1, 4], %)
  |> angledLineToY({ angle: -23, to: 1 }, %)
  |> xLine(-2.56, %)
  |> angledLineToX({ angle: -23, to: 1 }, %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude025w = extrude(sketch025w, length = 1)

// Base plane of rack
const plane003 = {
  plane: {
    origin: [0, 0, 4.114],
    x_axis: [1, 0, 0],
    y_axis: [0, 1, 0],
    z_axis: [0, 0, 1]
  }
}

const sketch005 = startSketchOn(plane003)
  |> startProfileAt([width - 1, 0], %)
  |> line(end = [-width + 2, 3])
  |> line(end = [0, 1])
  |> line(end = [width - 2, -3])
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()

const extrude005 = extrude(sketch005, length = 1)

const sketch006 = startSketchOn(plane003)
  |> startProfileAt([width - 1, 0 + 2.756], %)
  |> line(end = [-width + 2, 3])
  |> line(end = [0, 1])
  |> line(end = [width - 2, -3])
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()

const extrude006 = extrude(sketch006, length = 1)

const sketch007 = startSketchOn(plane003)
  |> startProfileAt([width - 1, depth], %)
  |> line(end = [-width + 1, -depth + serverDepth + 3.8])
  |> line(end = [1, 0])
  |> line(end = [0, -.75])
  |> line([
       width - 2,
       depth - serverDepth - 5 + .6
     ], %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude007 = extrude(sketch007, length = 1)

const sketch008 = startSketchOn(plane003)
  |> startProfileAt([width - 1, depth - 2.8], %)
  |> line(end = [-width + 2, -depth + serverDepth + 4.4])
  |> line(end = [0, -1.32])
  |> line(end = [width - 2, depth - serverDepth - 4.4])
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()

const extrude008 = extrude(sketch008, length = 1)

// Top Plane
const plane004 = {
  plane: {
    origin: [0, 0, 4.114 + railHeight * 1.75 + 2],
    x_axis: [1, 0, 0],
    y_axis: [0, 1, 0],
    z_axis: [0, 0, 1]
  }
}

const sketch005t = startSketchOn(plane004)
  |> startProfileAt([width - 1, 0], %)
  |> line(end = [-width + 2, 3])
  |> line(end = [0, 1])
  |> line(end = [width - 2, -3])
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()

const extrude005t = extrude(sketch005t, length = -1)

const sketch007t = startSketchOn(plane004)
  |> startProfileAt([width - 1, depth], %)
  |> line(end = [-width + 1, -depth + serverDepth + 3.8])
  |> line(end = [1, 0])
  |> line(end = [0, -.75])
  |> line([
       width - 2,
       depth - serverDepth - 5 + .6
     ], %)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude007t = extrude(sketch007t, length = -1)

const sketch008t = startSketchOn(plane004)
  |> startProfileAt([width - 1, 0 + 2.756], %)
  |> line(end = [-width + 2, 3])
  |> line(end = [0, 1])
  |> line(end = [width - 2, -3])
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude008t = extrude(sketch008t, length = -1)

const sketch009t = startSketchOn(plane004)
  |> startProfileAt([width - 1, depth - 2.8], %)
  |> line(end = [-width + 2, -depth + serverDepth + 4.4])
  |> line(end = [0, -1.32])
  |> line(end = [width - 2, depth - serverDepth - 4.4])
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()

const extrude009t = extrude(sketch009t, length = -1)

// front left vertical rail
// Define planes so the rail can be moved
const planeXYfl = {
  plane: {
    origin: [0, 0, originStart[2]],
    xAxis: [1.0, 0.0, 0.0],
    yAxis: [0.0, 1.0, 0.0],
    zAxis: [0.0, 0.0, 1.0]
  }
}

const planeXZfl = {
  plane: {
    origin: [
      originStart[1],
      originStart[0],
      originStart[2]
    ],
    xAxis: [0, 1, 0],
    yAxis: [0, 0, 1],
    zAxis: [1, 0, 0]
  }
}

const planeYZfl = {
  plane: {
    origin: [
      originStart[1],
      originStart[0],
      originStart[2]
    ],
    xAxis: [-1, 0, 0],
    yAxis: [0, 0, 1],
    zAxis: [1, 0, 0]
  }
}

// Base flange
const sketch001fl = startSketchOn(planeXZfl)
  |> startProfileAt([bendRad + thickness, 0], %)
  |> angledLine([0, 2 - bendRad - thickness], %, $rectangleSegmentA001fl)
  |> angledLine([
       segAng(rectangleSegmentA001fl) + 90,
       railHeight * 1.75
     ], %, $rectangleSegmentB001fl)
  |> angledLine([
       segAng(rectangleSegmentA001fl),
       -segLen(rectangleSegmentA001fl)
     ], %, $rectangleSegmentC001fl)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude001fl = extrude(sketch001fl, length = thickness)

// First flange
const sketch002fl = startSketchOn(planeYZfl)
  |> startProfileAt([-bendRad - thickness, 0], %)
  |> angledLine([180, 0.89 - bendRad - thickness], %, $rectangleSegmentA002fl)
  |> angledLine([
       segAng(rectangleSegmentA002fl) - 90,
       railHeight * 1.75
     ], %, $rectangleSegmentB002fl)
  |> angledLine([
       segAng(rectangleSegmentA002fl),
       -segLen(rectangleSegmentA002fl)
     ], %, $rectangleSegmentC002fl)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()

const extrude002fl = extrude(sketch002fl, length = thickness)

// Bend
const sketch003fl = startSketchOn(planeXYfl)
  |> startProfileAt([
       0 + thickness + bendRad + originStart[1],
       originStart[0]
     ], %)
  |> arc({
       angleStart: 270,
       angleEnd: 180,
       radius: bendRad + thickness
     }, %)
  |> xLine(thickness, %)
  |> arc({
       angleStart: 180,
       angleEnd: 270,
       radius: bendRad
     }, %)
  |> yLine(-thickness, %)
  |> close()

const extrude003fl = extrude(sketch003fl, length = railHeight * 1.75)

// define slots
const sketch010fl = startSketchOn(extrude001fl, 'START')
  |> startProfileAt([
       -1.12 + (.75 - .438) / 2 - originStart[0],
       originStart[2] + .81 - (.438 / 2)
     ], %)
  |> xLine(0.75 - .438, %)
  |> tangentialArcTo([
       -0.66 - originStart[0],
       originStart[2] + .81 + .438 / 2
     ], %)
  |> xLine(-0.75 + .438, %)
  |> tangentialArcTo([profileStartX(%), profileStartY(%)], %)
  |> close()
  |> patternLinear2d(
       axis = [0, 1],
       instances = 2,
       distance = 1.22
     )
const extrude010fl = extrude(sketch010fl, length = -thickness)

// define slots
const sketch011fl = startSketchOn(extrude001fl, 'START')
  |> startProfileAt([
       -1.12 + (.75 - .438) / 2 - originStart[0],
       originStart[2] + railHeight * 1.75 / 2 + .438 / 2
     ], %)
  |> xLine(0.75 - .438, %)
  |> tangentialArcTo([
       -0.66 - originStart[0],
       originStart[2] + railHeight * 1.75 / 2 - (.438 / 2)
     ], %)
  |> xLine(-0.75 + .438, %)
  |> tangentialArcTo([profileStartX(%), profileStartY(%)], %)
  |> close()

const extrude011fl = extrude(sketch011fl, length = -thickness)

// define slots
const sketch012fl = startSketchOn(extrude001fl, 'START')
  |> startProfileAt([
       -1.12 + (.75 - .438) / 2 - originStart[0],
       originStart[2] + railHeight * 1.75 - .81 + .438 / 2
     ], %)
  |> xLine(0.75 - .438, %)
  |> tangentialArcTo([
       -0.66 - originStart[0],
       originStart[2] + railHeight * 1.75 - .81 - (.438 / 2)
     ], %)
  |> xLine(-0.75 + .438, %)
  |> tangentialArcTo([profileStartX(%), profileStartY(%)], %)
  |> close()
  |> patternLinear2d(
       axis = [0, -1],
       instances = 2,
       distance = 1.22
     )
const extrude012fl = extrude(sketch012fl, length = -thickness)

// FRONT RIGHT VERTICAL RAIL
// Define planes so the rail can be moved
const planeXYfr = {
  plane: {
    origin: [0, 0, originStart[2]],
    xAxis: [1.0, 0.0, 0.0],
    yAxis: [0.0, 1.0, 0.0],
    zAxis: [0.0, 0.0, 1.0]
  }
}

const planeXZfr = {
  plane: {
    origin: [
      originStart[1] + width - thickness - 2,
      originStart[0],
      originStart[2]
    ],
    xAxis: [0, 1, 0],
    yAxis: [0, 0, 1],
    zAxis: [1, 0, 0]
  }
}

const planeYZfr = {
  plane: {
    origin: [
      originStart[1] + width - 2,
      originStart[0],
      originStart[2]
    ],
    xAxis: [-1, 0, 0],
    yAxis: [0, 0, 1],
    zAxis: [1, 0, 0]
  }
}

// Base flange
const sketch001fr = startSketchOn(planeXZfr)
  |> startProfileAt([bendRad + thickness, 0], %)
  |> angledLine([0, 2 - bendRad - thickness], %, $rectangleSegmentA001fr)
  |> angledLine([
       segAng(rectangleSegmentA001fr) + 90,
       railHeight * 1.75
     ], %, $rectangleSegmentB001fr)
  |> angledLine([
       segAng(rectangleSegmentA001fr),
       -segLen(rectangleSegmentA001fr)
     ], %, $rectangleSegmentC001fr)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude001fr = extrude(sketch001fr, length = thickness)

// First flange
const sketch002fr = startSketchOn(planeYZfr)
  |> startProfileAt([0.89, 0], %)
  |> angledLine([180, 0.89 - bendRad - thickness], %, $rectangleSegmentA002fr)
  |> angledLine([
       segAng(rectangleSegmentA002fr) - 90,
       railHeight * 1.75
     ], %, $rectangleSegmentB002fr)
  |> angledLine([
       segAng(rectangleSegmentA002fr),
       -segLen(rectangleSegmentA002fr)
     ], %, $rectangleSegmentC002fr)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()

const extrude002fr = extrude(sketch002fr, length = thickness)

// Bend
const sketch003fr = startSketchOn(planeXYfr)
  |> startProfileAt([
       bendRad + originStart[1] + width - 2 - thickness - bendRad,
       originStart[0] + bendRad + thickness
     ], %)
  |> arc({
       angleStart: 0,
       angleEnd: -90,
       radius: bendRad
     }, %)
  |> yLine(-thickness, %)
  |> arc({
       angleStart: -90,
       angleEnd: 0,
       radius: bendRad + thickness
     }, %)
  |> close()

const extrude003fr = extrude(sketch003fr, length = railHeight * 1.75)

// define slots
const sketch010fr = startSketchOn(extrude001fr, 'START')
  |> startProfileAt([
       -1.12 + (.75 - .438) / 2 - originStart[0],
       originStart[2] + .81 - (.438 / 2)
     ], %)
  |> xLine(0.75 - .438, %)
  |> tangentialArcTo([
       -0.66 - originStart[0],
       originStart[2] + .81 + .438 / 2
     ], %)
  |> xLine(-0.75 + .438, %)
  |> tangentialArcTo([profileStartX(%), profileStartY(%)], %)
  |> close()
  |> patternLinear2d(
       axis = [0, 1],
       instances = 2,
       distance = 1.22
     )
const extrude010fr = extrude(sketch010fr, length = -thickness)

// define slots
const sketch011fr = startSketchOn(extrude001fr, 'START')
  |> startProfileAt([
       -1.12 + (.75 - .438) / 2 - originStart[0],
       originStart[2] + railHeight * 1.75 / 2 + .438 / 2
     ], %)
  |> xLine(0.75 - .438, %)
  |> tangentialArcTo([
       -0.66 - originStart[0],
       originStart[2] + railHeight * 1.75 / 2 - (.438 / 2)
     ], %)
  |> xLine(-0.75 + .438, %)
  |> tangentialArcTo([profileStartX(%), profileStartY(%)], %)
  |> close()

const extrude011fr = extrude(sketch011fr, length = -thickness)

// define slots
const sketch012fr = startSketchOn(extrude001fr, 'START')
  |> startProfileAt([
       -1.12 + (.75 - .438) / 2 - originStart[0],
       originStart[2] + railHeight * 1.75 - .81 + .438 / 2
     ], %)
  |> xLine(0.75 - .438, %)
  |> tangentialArcTo([
       -0.66 - originStart[0],
       originStart[2] + railHeight * 1.75 - .81 - (.438 / 2)
     ], %)
  |> xLine(-0.75 + .438, %)
  |> tangentialArcTo([profileStartX(%), profileStartY(%)], %)
  |> close()
  |> patternLinear2d(
       axis = [0, -1],
       instances = 2,
       distance = 1.22
     )
const extrude012fr = extrude(sketch012fr, length = -thickness)

// RIGHT REAR VERTICAL RAIL
// Define planes so the rail can be moved
const planeXYrr = {
  plane: {
    origin: [0, serverDepth, originStart[2]],
    xAxis: [1.0, 0.0, 0.0],
    yAxis: [0.0, 1.0, 0.0],
    zAxis: [0.0, 0.0, 1.0]
  }
}

const planeXZrr = {
  plane: {
    origin: [
      originStart[1] + width - thickness - 2,
      originStart[0] + serverDepth - 2 - bendRad,
      originStart[2]
    ],
    xAxis: [0, 1, 0],
    yAxis: [0, 0, 1],
    zAxis: [1, 0, 0]
  }
}

const planeYZrr = {
  plane: {
    origin: [
      originStart[1] + width - 2,
      originStart[0] + serverDepth,
      originStart[2]
    ],
    xAxis: [-1, 0, 0],
    yAxis: [0, 0, 1],
    zAxis: [1, 0, 0]
  }
}

// Base flange
const sketch001rr = startSketchOn(planeXZrr)
  |> startProfileAt([bendRad + thickness, 0], %)
  |> angledLine([0, 2 - bendRad - thickness], %, $rectangleSegmentA001rr)
  |> angledLine([
       segAng(rectangleSegmentA001rr) + 90,
       railHeight * 1.75
     ], %, $rectangleSegmentB001rr)
  |> angledLine([
       segAng(rectangleSegmentA001rr),
       -segLen(rectangleSegmentA001rr)
     ], %, $rectangleSegmentC001rr)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude001rr = extrude(sketch001rr, length = thickness)

// First flange
const sketch002rr = startSketchOn(planeYZrr)
  |> startProfileAt([0.89, 0], %)
  |> angledLine([180, 0.89 - bendRad - thickness], %, $rectangleSegmentA002rr)
  |> angledLine([
       segAng(rectangleSegmentA002rr) - 90,
       railHeight * 1.75
     ], %, $rectangleSegmentB002rr)
  |> angledLine([
       segAng(rectangleSegmentA002rr),
       -segLen(rectangleSegmentA002rr)
     ], %, $rectangleSegmentC002rr)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()

const extrude002rr = extrude(sketch002rr, length = thickness)

// Bend
const sketch003rr = startSketchOn(planeXYrr)
  |> startProfileAt([
       bendRad + originStart[1] + width - 2 - bendRad,
       originStart[0] - bendRad
     ], %)
  |> arc({
       angleStart: 0,
       angleEnd: 90,
       radius: bendRad + thickness
     }, %)
  |> yLine(-thickness, %)
  |> arc({
       angleStart: 90,
       angleEnd: 0,
       radius: bendRad
     }, %)
  |> close()

const extrude003rr = extrude(sketch003rr, length = railHeight * 1.75)

// define slots
const sketch010rr = startSketchOn(extrude001rr, 'START')
  |> startProfileAt([
       -1.12 + (.75 - .438) / 2 - originStart[0] + 1.5 - serverDepth,
       originStart[2] + .81 - (.438 / 2)
     ], %)
  |> xLine(0.75 - .438, %)
  |> tangentialArcTo([
       -0.66 - originStart[0] + 1.5 - serverDepth,
       originStart[2] + .81 + .438 / 2
     ], %)
  |> xLine(-0.75 + .438, %)
  |> tangentialArcTo([profileStartX(%), profileStartY(%)], %)
  |> close()
  |> patternLinear2d(
       axis = [0, 1],
       instances = 2,
       distance = 1.22
     )
const extrude010rr = extrude(sketch010rr, length = -thickness)

// define slots
const sketch011rr = startSketchOn(extrude001rr, 'START')
  |> startProfileAt([
       -1.12 + (.75 - .438) / 2 - originStart[0] + 1.5 - serverDepth,
       originStart[2] + railHeight * 1.75 / 2 + .438 / 2
     ], %)
  |> xLine(0.75 - .438, %)
  |> tangentialArcTo([
       -0.66 - originStart[0] + 1.5 - serverDepth,
       originStart[2] + railHeight * 1.75 / 2 - (.438 / 2)
     ], %)
  |> xLine(-0.75 + .438, %)
  |> tangentialArcTo([profileStartX(%), profileStartY(%)], %)
  |> close()

const extrude011rr = extrude(sketch011rr, length = -thickness)

// define slots
const sketch012rr = startSketchOn(extrude001rr, 'START')
  |> startProfileAt([
       -1.12 + (.75 - .438) / 2 - originStart[0] + 1.5 - serverDepth,
       originStart[2] + railHeight * 1.75 - .81 + .438 / 2
     ], %)
  |> xLine(0.75 - .438, %)
  |> tangentialArcTo([
       -0.66 - originStart[0] + 1.5 - serverDepth,
       originStart[2] + railHeight * 1.75 - .81 - (.438 / 2)
     ], %)
  |> xLine(-0.75 + .438, %)
  |> tangentialArcTo([profileStartX(%), profileStartY(%)], %)
  |> close()
  |> patternLinear2d(
       axis = [0, -1],
       instances = 2,
       distance = 1.22
     )
const extrude012rr = extrude(sketch012rr, length = -thickness)

// REAR LEFT VETCIAL RAIL
// Define planes so the rail can be moved
const planeXYrl = {
  plane: {
    origin: [0, serverDepth, originStart[2]],
    xAxis: [1.0, 0.0, 0.0],
    yAxis: [0.0, 1.0, 0.0],
    zAxis: [0.0, 0.0, 1.0]
  }
}

const planeXZrl = {
  plane: {
    origin: [
      originStart[1],
      originStart[0] + serverDepth - 2 - bendRad,
      originStart[2]
    ],
    xAxis: [0, 1, 0],
    yAxis: [0, 0, 1],
    zAxis: [1, 0, 0]
  }
}

const planeYZrl = {
  plane: {
    origin: [
      originStart[1],
      originStart[0] + serverDepth,
      originStart[2]
    ],
    xAxis: [-1, 0, 0],
    yAxis: [0, 0, 1],
    zAxis: [1, 0, 0]
  }
}
// Base flange
const sketch001rl = startSketchOn(planeXZrl)
  |> startProfileAt([bendRad + thickness, 0], %)
  |> angledLine([0, 2 - bendRad - thickness], %, $rectangleSegmentA001rl)
  |> angledLine([
       segAng(rectangleSegmentA001rl) + 90,
       railHeight * 1.75
     ], %, $rectangleSegmentB001rl)
  |> angledLine([
       segAng(rectangleSegmentA001rl),
       -segLen(rectangleSegmentA001rl)
     ], %, $rectangleSegmentC001rl)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
const extrude001rl = extrude(sketch001rl, length = thickness)

// First flange
const sketch002rl = startSketchOn(planeYZrl)
  |> startProfileAt([-bendRad - thickness, 0], %)
  |> angledLine([180, 0.89 - bendRad - thickness], %, $rectangleSegmentA002rl)
  |> angledLine([
       segAng(rectangleSegmentA002rl) - 90,
       railHeight * 1.75
     ], %, $rectangleSegmentB002rl)
  |> angledLine([
       segAng(rectangleSegmentA002rl),
       -segLen(rectangleSegmentA002rl)
     ], %, $rectangleSegmentC002rl)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()

const extrude002rl = extrude(sketch002rl, length = thickness)

// Bend
const sketch003rl = startSketchOn(planeXYrl)
  |> startProfileAt([
       bendRad + originStart[1] + thickness,
       originStart[0]
     ], %)
  |> arc({
       angleStart: 90,
       angleEnd: 180,
       radius: bendRad
     }, %)
  |> xLine(-thickness, %)
  |> arc({
       angleStart: 180,
       angleEnd: 90,
       radius: bendRad + thickness
     }, %)
  |> close()

const extrude003rl = extrude(sketch003rl, length = railHeight * 1.75)

// define slots
const sketch010rl = startSketchOn(extrude001rl, 'START')
  |> startProfileAt([
       -1.12 + (.75 - .438) / 2 - originStart[0] - serverDepth + 1.5,
       originStart[2] + .81 - (.438 / 2)
     ], %)
  |> xLine(0.75 - .438, %)
  |> tangentialArcTo([
       -0.66 - originStart[0] - serverDepth + 1.5,
       originStart[2] + .81 + .438 / 2
     ], %)
  |> xLine(-0.75 + .438, %)
  |> tangentialArcTo([profileStartX(%), profileStartY(%)], %)
  |> close()
  |> patternLinear2d(
       axis = [0, 1],
       instances = 2,
       distance = 1.22
     )
const extrude010rl = extrude(sketch010rl, length = -thickness)

// define slots
const sketch011rl = startSketchOn(extrude001rl, 'START')
  |> startProfileAt([
       -1.12 + (.75 - .438) / 2 - originStart[0] - serverDepth + 1.5,
       originStart[2] + railHeight * 1.75 / 2 + .438 / 2
     ], %)
  |> xLine(0.75 - .438, %)
  |> tangentialArcTo([
       -0.66 - originStart[0] - serverDepth + 1.5,
       originStart[2] + railHeight * 1.75 / 2 - (.438 / 2)
     ], %)
  |> xLine(-0.75 + .438, %)
  |> tangentialArcTo([profileStartX(%), profileStartY(%)], %)
  |> close()

const extrude011rl = extrude(sketch011rl, length = -thickness)

// define slots
const sketch012rl = startSketchOn(extrude001rl, 'START')
  |> startProfileAt([
       -1.12 + (.75 - .438) / 2 - originStart[0] - serverDepth + 1.5,
       originStart[2] + railHeight * 1.75 - .81 + .438 / 2
     ], %)
  |> xLine(0.75 - .438, %)
  |> tangentialArcTo([
       -0.66 - originStart[0] - serverDepth + 1.5,
       originStart[2] + railHeight * 1.75 - .81 - (.438 / 2)
     ], %)
  |> xLine(-0.75 + .438, %)
  |> tangentialArcTo([profileStartX(%), profileStartY(%)], %)
  |> close()
  |> patternLinear2d(
       axis = [0, -1],
       instances = 2,
       distance = 1.22
     )
const extrude012rl = extrude(sketch012rl, length = -thickness)

// Define planes so the server can be moved
fn streamServer = (serverPos) => {
  const planeXYs = {
    plane: {
      origin: [0, 0 + 2, 4.114 + 1 + serverPos * 1.75],
      xAxis: [1.0, 0.0, 0.0],
      yAxis: [0.0, 1.0, 0.0],
      zAxis: [0.0, 0.0, 1.0]
    }
  }

  const planeXZs = {
    plane: {
      origin: [0 + 1.2 + .1, 0 + 2, 0],
      xAxis: [0, -1, 0],
      yAxis: [0, 0, 1],
      zAxis: [1, 0, 0]
    }
  }
  const planeXZs2 = {
    plane: {
      origin: [18 + 1.4, 0 + 2, 0],
      xAxis: [0, -1, 0],
      yAxis: [0, 0, 1],
      zAxis: [1, 0, 0]
    }
  }

  const sketch001s = startSketchOn(planeXYs)
    |> startProfileAt([1 + 1.2, 1], %)
    |> angledLine([0, 17.2], %, $rectangleSegmentA001)
    |> angledLine([segAng(rectangleSegmentA001) + 90, 29], %, $rectangleSegmentB001)
    |> angledLine([
         segAng(rectangleSegmentA001),
         -segLen(rectangleSegmentA001)
       ], %, $rectangleSegmentC001)
    |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
    |> close()
  const extrude001s = extrude(sketch001s, length = 7)

  const sketch002s = startSketchOn(planeXZs)
    |> startProfileAt([-1, 4.114 + 1 + serverPos * 1.75], %)
    |> yLine(6.98, %)
    |> xLine(0.2, %)
    |> yLine(-0.36, %)
    |> xLine(0.5, %)
    |> tangentialArcTo([
         0.3,
         17.15 + 4.114 + 1 + serverPos * 1.75 - 11.114
       ], %)
    |> yLine(-1.77, %)
    |> tangentialArcTo([
         -0.13,
         14.89 + 4.114 + 1 + serverPos * 1.75 - 11.114
       ], %)
    |> xLine(-0.52, %)
    |> yLine(-0.42, %)
    |> line(end = [0.34, -0.15])
    |> yLine(-2.97, %)
    |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
    |> close()

  const extrude002s = extrude(sketch002s, length = 1.8 / 2)

  const sketch003s = startSketchOn(planeXZs2)
    |> startProfileAt([-1, 4.114 + 1 + serverPos * 1.75], %)
    |> yLine(6.98, %)
    |> xLine(0.2, %)
    |> yLine(-0.36, %)
    |> xLine(0.5, %)
    |> tangentialArcTo([
         0.3,
         17.15 + 4.114 + 1 + serverPos * 1.75 - 11.114
       ], %)
    |> yLine(-1.77, %)
    |> tangentialArcTo([
         -0.13,
         14.89 + 4.114 + 1 + serverPos * 1.75 - 11.114
       ], %)
    |> xLine(-0.52, %)
    |> yLine(-0.42, %)
    |> line(end = [0.34, -0.15])
    |> yLine(-2.97, %)
    |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
    |> close()

  const extrude003s = extrude(sketch003s, length = 1.8 / 2)
  return extrude003s
}

// generate servers at Z height in U's
// streamServer(4)
// streamServer(8)
// streamServer(12)
// streamServer(16)
// streamServer(20)


// streamServer(29)
// streamServer(33)
// streamServer(37)
