//Zoo server rack model with fully detailed vertical rails

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, %)
    |> lineTo([profileStartX(%), profileStartY(%)], %)
    |> close(%)
    |> hole(circle([
         (3.543 - 2.756) / 2,
         (3.543 - 2.756) / 2
       ], 8.8 / 2 / 25.4, %), %)
    |> hole(circle([
         (3.543 - 2.756) / 2 + 2.756,
         (3.543 - 2.756) / 2
       ], 8.8 / 2 / 25.4, %), %)
    |> hole(circle([
         (3.543 - 2.756) / 2,
         (3.543 - 2.756) / 2 + 2.756
       ], 8.8 / 2 / 25.4, %), %)
    |> hole(circle([
         (3.543 - 2.756) / 2 + 2.756,
         (3.543 - 2.756) / 2 + 2.756
       ], 8.8 / 2 / 25.4, %), %)
    |> extrude(-.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(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([0, 1.2], 2.48 / 2, %)
  const examplec = extrude(-1 - (3 / 16), sketch003c)
  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)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude001l = extrude(1, sketch001l)

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

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, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude003l = extrude(1, sketch003l)

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, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude004l = extrude(1, sketch004l)

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

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 }, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude006l = extrude(1, sketch006l)

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
     }, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude007l = extrude(1, sketch007l)

// 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)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude001w = extrude(1, sketch001w)

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

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, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude003w = extrude(1, sketch003w)

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, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude004w = extrude(1, sketch004w)

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)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude005w = extrude(1, sketch005w)

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)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude006w = extrude(1, sketch006w)

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
     }, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude007w = extrude(1, sketch007w)

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
     }, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude008w = extrude(1, sketch008w)

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 }, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude009w = extrude(1, sketch009w)

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 }, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude010w = extrude(1, sketch010w)

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 }, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude011w = extrude(1, sketch011w)

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 }, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude012w = extrude(1, sketch012w)

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, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude013w = extrude(1, sketch013w)

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 }, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude014w = extrude(1, sketch014w)

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 }, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude015w = extrude(1, sketch015w)

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 }, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude016w = extrude(1, sketch016w)

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
     }, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude017w = extrude(1, sketch017w)

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
     }, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude018w = extrude(1, sketch018w)

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 }, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude019w = extrude(1, sketch019w)

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 }, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude020w = extrude(1, sketch020w)

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

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 }, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude022w = extrude(1, sketch022w)

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 }, %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude023w = extrude(1, sketch023w)

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

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

// 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([-width + 2, 3], %)
  |> line([0, 1], %)
  |> line([width - 2, -3], %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)

const extrude005 = extrude(1, sketch005)

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

const extrude006 = extrude(1, sketch006)

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

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

const extrude008 = extrude(1, sketch008)

// 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([-width + 2, 3], %)
  |> line([0, 1], %)
  |> line([width - 2, -3], %)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)

const extrude005t = extrude(-1, sketch005t)

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

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

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

const extrude009t = extrude(-1, sketch009t)

// 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)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude001fl = extrude(thickness, sketch001fl)

// 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)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)

const extrude002fl = extrude(thickness, sketch002fl)

// 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(railHeight * 1.75, sketch003fl)

// EIA-310-D standard hole pattern
const sketch004fl = startSketchOn(extrude002fl, 'START')
  |> startProfileAt([0.72 + originStart[1], originStart[2] + 0.15], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA003fl)
  |> angledLine([
       segAng(rectangleSegmentA003fl) - 90,
       0.375
     ], %, $rectangleSegmentB003fl)
  |> angledLine([
       segAng(rectangleSegmentA003fl),
       -segLen(rectangleSegmentA003fl)
     ], %, $rectangleSegmentC003fl)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude004fl = extrude(-thickness, sketch004fl)

// EIA-310-D standard hole pattern
const sketch005fl = startSketchOn(extrude002fl, 'START')
  |> startProfileAt([0.72 + originStart[1],originStart[2] +  0.15 + .62], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA004fl)
  |> angledLine([
       segAng(rectangleSegmentA004fl) - 90,
       0.375
     ], %, $rectangleSegmentB004fl)
  |> angledLine([
       segAng(rectangleSegmentA004fl),
       -segLen(rectangleSegmentA004fl)
     ], %, $rectangleSegmentC004fl)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude005fl = extrude(-thickness, sketch005fl)

// EIA-310-D standard hole pattern
const sketch006fl = startSketchOn(extrude002fl, 'START')
  |> startProfileAt([
       0.72 + originStart[1],
      originStart[2] + 0.15 + 0.62 + 0.50
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA005fl)
  |> angledLine([
       segAng(rectangleSegmentA005fl) - 90,
       0.375
     ], %, $rectangleSegmentB005fl)
  |> angledLine([
       segAng(rectangleSegmentA005fl),
       -segLen(rectangleSegmentA005fl)
     ], %, $rectangleSegmentC005fl)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude006fl = extrude(-thickness, sketch006fl)

// EIA-310-D standard hole pattern
const sketch007fl = startSketchOn(extrude001fl, 'START')
  |> startProfileAt([-1.45 - originStart[0], originStart[2] + 0.15], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA006fl)
  |> angledLine([
       segAng(rectangleSegmentA006fl) - 90,
       0.375
     ], %, $rectangleSegmentB006fl)
  |> angledLine([
       segAng(rectangleSegmentA006fl),
       -segLen(rectangleSegmentA006fl)
     ], %, $rectangleSegmentC006fl)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude007fl = extrude(-thickness, sketch007fl)

// EIA-310-D standard hole pattern
const sketch008fl = startSketchOn(extrude001fl, 'START')
  |> startProfileAt([-1.45 - originStart[0],originStart[2] + 0.15 + 0.62], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA007fl)
  |> angledLine([
       segAng(rectangleSegmentA007fl) - 90,
       0.375
     ], %, $rectangleSegmentB007fl)
  |> angledLine([
       segAng(rectangleSegmentA007fl),
       -segLen(rectangleSegmentA007fl)
     ], %, $rectangleSegmentC007fl)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude008fl = extrude(-thickness, sketch008fl)

// EIA-310-D standard hole pattern
const sketch009fl = startSketchOn(extrude001fl, 'START')
  |> startProfileAt([
       -1.45 - originStart[0],
       originStart[2] + 0.15 + 0.62 + 0.5
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA008fl)
  |> angledLine([
       segAng(rectangleSegmentA008fl) - 90,
       0.375
     ], %, $rectangleSegmentB008fl)
  |> angledLine([
       segAng(rectangleSegmentA008fl),
       -segLen(rectangleSegmentA008fl)
     ], %, $rectangleSegmentC008fl)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude009fl = extrude(-thickness, sketch009fl)

// 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],
       repetitions: 1,
       distance: 1.22
     }, %)
const extrude010fl = extrude(-thickness, sketch010fl)

// 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(-thickness, sketch011fl)

// 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],
       repetitions: 1,
       distance: 1.22
     }, %)
const extrude012fl = extrude(-thickness, sketch012fl)

// 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)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude001fr = extrude(thickness, sketch001fr)

// 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)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)

const extrude002fr = extrude(thickness, sketch002fr)

// 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(railHeight * 1.75, sketch003fr)

// EIA-310-D standard hole pattern
const sketch004fr = startSketchOn(extrude002fr, 'START')
  |> startProfileAt([
       -0.35 + originStart[1] + width - 2,
       originStart[2] + 0.15
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA003fr)
  |> angledLine([
       segAng(rectangleSegmentA003fr) - 90,
       0.375
     ], %, $rectangleSegmentB003fr)
  |> angledLine([
       segAng(rectangleSegmentA003fr),
       -segLen(rectangleSegmentA003fr)
     ], %, $rectangleSegmentC003fr)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude004fr = extrude(-thickness, sketch004fr)

// EIA-310-D standard hole pattern
const sketch005fr = startSketchOn(extrude002fr, 'START')
  |> startProfileAt([
       -0.35 + originStart[1] + width - 2,
       originStart[2] + 0.15 + .62
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA004fr)
  |> angledLine([
       segAng(rectangleSegmentA004fr) - 90,
       0.375
     ], %, $rectangleSegmentB004fr)
  |> angledLine([
       segAng(rectangleSegmentA004fr),
       -segLen(rectangleSegmentA004fr)
     ], %, $rectangleSegmentC004fr)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude005fr = extrude(-thickness, sketch005fr)

// EIA-310-D standard hole pattern
const sketch006fr = startSketchOn(extrude002fr, 'START')
  |> startProfileAt([
       -0.35 + originStart[1] + width - 2,
       originStart[2] + 0.15 + 0.62 + 0.50
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA005fr)
  |> angledLine([
       segAng(rectangleSegmentA005fr) - 90,
       0.375
     ], %, $rectangleSegmentB005fr)
  |> angledLine([
       segAng(rectangleSegmentA005fr),
       -segLen(rectangleSegmentA005fr)
     ], %, $rectangleSegmentC005fr)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude006fr = extrude(-thickness, sketch006fr)

// EIA-310-D standard hole pattern
const sketch007fr = startSketchOn(extrude001fr, 'START')
  |> startProfileAt([
       -1.45 - originStart[0],
       originStart[2] + 0.15
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA006fr)
  |> angledLine([
       segAng(rectangleSegmentA006fr) - 90,
       0.375
     ], %, $rectangleSegmentB006fr)
  |> angledLine([
       segAng(rectangleSegmentA006fr),
       -segLen(rectangleSegmentA006fr)
     ], %, $rectangleSegmentC006fr)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude007fr = extrude(-thickness, sketch007fr)

// EIA-310-D standard hole pattern
const sketch008fr = startSketchOn(extrude001fr, 'START')
  |> startProfileAt([
       -1.45 - originStart[0],
       originStart[2] + 0.15 + 0.62
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA007fr)
  |> angledLine([
       segAng(rectangleSegmentA007fr) - 90,
       0.375
     ], %, $rectangleSegmentB007fr)
  |> angledLine([
       segAng(rectangleSegmentA007fr),
       -segLen(rectangleSegmentA007fr)
     ], %, $rectangleSegmentC007fr)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude008fr = extrude(-thickness, sketch008fr)

// EIA-310-D standard hole pattern
const sketch009fr = startSketchOn(extrude001fr, 'START')
  |> startProfileAt([
       -1.45 - originStart[0],
       originStart[2] + 0.15 + 0.62 + 0.5
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA008fr)
  |> angledLine([
       segAng(rectangleSegmentA008fr) - 90,
       0.375
     ], %, $rectangleSegmentB008fr)
  |> angledLine([
       segAng(rectangleSegmentA008fr),
       -segLen(rectangleSegmentA008fr)
     ], %, $rectangleSegmentC008fr)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude009fr = extrude(-thickness, sketch009fr)

// 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],
       repetitions: 1,
       distance: 1.22
     }, %)
const extrude010fr = extrude(-thickness, sketch010fr)

// 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(-thickness, sketch011fr)

// 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],
       repetitions: 1,
       distance: 1.22
     }, %)
const extrude012fr = extrude(-thickness, sketch012fr)

// 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)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude001rr = extrude(thickness, sketch001rr)

// 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)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)

const extrude002rr = extrude(thickness, sketch002rr)

// 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(railHeight * 1.75, sketch003rr)

// EIA-310-D standard hole pattern
const sketch004rr = startSketchOn(extrude002rr, 'START')
  |> startProfileAt([
       -0.35 + originStart[1] + width - 2,
       originStart[2] + 0.15
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA003rr)
  |> angledLine([
       segAng(rectangleSegmentA003rr) - 90,
       0.375
     ], %, $rectangleSegmentB003rr)
  |> angledLine([
       segAng(rectangleSegmentA003rr),
       -segLen(rectangleSegmentA003rr)
     ], %, $rectangleSegmentC003rr)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude004rr = extrude(-thickness, sketch004rr)

// EIA-310-D standard hole pattern
const sketch005rr = startSketchOn(extrude002rr, 'START')
  |> startProfileAt([
       -0.35 + originStart[1] + width - 2,
       originStart[2] + 0.15 + .62
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA004rr)
  |> angledLine([
       segAng(rectangleSegmentA004rr) - 90,
       0.375
     ], %, $rectangleSegmentB004rr)
  |> angledLine([
       segAng(rectangleSegmentA004rr),
       -segLen(rectangleSegmentA004rr)
     ], %, $rectangleSegmentC004rr)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude005rr = extrude(-thickness, sketch005rr)

// EIA-310-D standard hole pattern
const sketch006rr = startSketchOn(extrude002rr, 'START')
  |> startProfileAt([
       -0.35 + originStart[1] + width - 2,
       originStart[2] + 0.15 + 0.62 + 0.50
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA005rr)
  |> angledLine([
       segAng(rectangleSegmentA005rr) - 90,
       0.375
     ], %, $rectangleSegmentB005rr)
  |> angledLine([
       segAng(rectangleSegmentA005rr),
       -segLen(rectangleSegmentA005rr)
     ], %, $rectangleSegmentC005rr)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude006rr = extrude(-thickness, sketch006rr)

// EIA-310-D standard hole pattern
const sketch007rr = startSketchOn(extrude001rr, 'START')
  |> startProfileAt([
       -originStart[0]-serverDepth+1.7,
       originStart[2] + 0.15
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA006rr)
  |> angledLine([
       segAng(rectangleSegmentA006rr) - 90,
       0.375
     ], %, $rectangleSegmentB006rr)
  |> angledLine([
       segAng(rectangleSegmentA006rr),
       -segLen(rectangleSegmentA006rr)
     ], %, $rectangleSegmentC006rr)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude007rr = extrude(-thickness, sketch007rr)

// EIA-310-D standard hole pattern
const sketch008rr = startSketchOn(extrude001rr, 'START')
  |> startProfileAt([
       -originStart[0]-serverDepth+1.7,
       originStart[2] + 0.15 + 0.62
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA007rr)
  |> angledLine([
       segAng(rectangleSegmentA007rr) - 90,
       0.375
     ], %, $rectangleSegmentB007rr)
  |> angledLine([
       segAng(rectangleSegmentA007rr),
       -segLen(rectangleSegmentA007rr)
     ], %, $rectangleSegmentC007rr)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude008rr = extrude(-thickness, sketch008rr)

// EIA-310-D standard hole pattern
const sketch009rr = startSketchOn(extrude001rr, 'START')
  |> startProfileAt([
       -originStart[0]-serverDepth+1.7,
       originStart[2] + 0.15 + 0.62 + 0.5
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA008rr)
  |> angledLine([
       segAng(rectangleSegmentA008rr) - 90,
       0.375
     ], %, $rectangleSegmentB008rr)
  |> angledLine([
       segAng(rectangleSegmentA008rr),
       -segLen(rectangleSegmentA008rr)
     ], %, $rectangleSegmentC008rr)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude009rr = extrude(-thickness, sketch009rr)

// 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],
       repetitions: 1,
       distance: 1.22
     }, %)
const extrude010rr = extrude(-thickness, sketch010rr)

// 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(-thickness, sketch011rr)

// 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],
       repetitions: 1,
       distance: 1.22
     }, %)
const extrude012rr = extrude(-thickness, sketch012rr)

// 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)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
const extrude001rl = extrude(thickness, sketch001rl)

// 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)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)

const extrude002rl = extrude(thickness, sketch002rl)

// 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(railHeight * 1.75, sketch003rl)

// EIA-310-D standard hole pattern
const sketch004rl = startSketchOn(extrude002rl, 'START')
  |> startProfileAt([
       -1.38 + 2 + thickness + originStart[1],
       originStart[2] + 0.15
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA003rl)
  |> angledLine([
       segAng(rectangleSegmentA003rl) - 90,
       0.375
     ], %, $rectangleSegmentB003rl)
  |> angledLine([
       segAng(rectangleSegmentA003rl),
       -segLen(rectangleSegmentA003rl)
     ], %, $rectangleSegmentC003rl)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude004rl = extrude(-thickness, sketch004rl)

// EIA-310-D standard hole pattern
const sketch005rl = startSketchOn(extrude002rl, 'START')
  |> startProfileAt([
       -1.38 + 2 + thickness + originStart[1],
       originStart[2] + 0.15 + .62
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA004rl)
  |> angledLine([
       segAng(rectangleSegmentA004rl) - 90,
       0.375
     ], %, $rectangleSegmentB004rl)
  |> angledLine([
       segAng(rectangleSegmentA004rl),
       -segLen(rectangleSegmentA004rl)
     ], %, $rectangleSegmentC004rl)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude005rl = extrude(-thickness, sketch005rl)

// EIA-310-D standard hole pattern
const sketch006rl = startSketchOn(extrude002rl, 'START')
  |> startProfileAt([
       -1.38 + 2 + thickness + originStart[1],
       originStart[2] + 0.15 + 0.62 + 0.50
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA005rl)
  |> angledLine([
       segAng(rectangleSegmentA005rl) - 90,
       0.375
     ], %, $rectangleSegmentB005rl)
  |> angledLine([
       segAng(rectangleSegmentA005rl),
       -segLen(rectangleSegmentA005rl)
     ], %, $rectangleSegmentC005rl)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude006rl = extrude(-thickness, sketch006rl)

// EIA-310-D standard hole pattern
const sketch007rl = startSketchOn(extrude001rl, 'START')
  |> startProfileAt([
       1.75 - originStart[0] - serverDepth,
       originStart[2] + 0.15
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA006rl)
  |> angledLine([
       segAng(rectangleSegmentA006rl) - 90,
       0.375
     ], %, $rectangleSegmentB006rl)
  |> angledLine([
       segAng(rectangleSegmentA006rl),
       -segLen(rectangleSegmentA006rl)
     ], %, $rectangleSegmentC006rl)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude007rl = extrude(-thickness, sketch007rl)

// EIA-310-D standard hole pattern
const sketch008rl = startSketchOn(extrude001rl, 'START')
  |> startProfileAt([
       1.75 - originStart[0] - serverDepth,
       originStart[2] + 0.15 + 0.62
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA007rl)
  |> angledLine([
       segAng(rectangleSegmentA007rl) - 90,
       0.375
     ], %, $rectangleSegmentB007rl)
  |> angledLine([
       segAng(rectangleSegmentA007rl),
       -segLen(rectangleSegmentA007rl)
     ], %, $rectangleSegmentC007rl)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude008rl = extrude(-thickness, sketch008rl)

// EIA-310-D standard hole pattern
const sketch009rl = startSketchOn(extrude001rl, 'START')
  |> startProfileAt([
       1.75 - originStart[0] - serverDepth,
       originStart[2] + 0.15 + 0.62 + 0.5
     ], %)
  |> angledLine([0, -0.375], %, $rectangleSegmentA008rl)
  |> angledLine([
       segAng(rectangleSegmentA008rl) - 90,
       0.375
     ], %, $rectangleSegmentB008rl)
  |> angledLine([
       segAng(rectangleSegmentA008rl),
       -segLen(rectangleSegmentA008rl)
     ], %, $rectangleSegmentC008rl)
  |> lineTo([profileStartX(%), profileStartY(%)], %)
  |> close(%)
  |> patternLinear2d({
       axis: [0, 1],
       repetitions: railHeight - 1,
       distance: 0.62 + 0.62 + 0.5
     }, %)
const extrude009rl = extrude(-thickness, sketch009rl)

// 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],
       repetitions: 1,
       distance: 1.22
     }, %)
const extrude010rl = extrude(-thickness, sketch010rl)

// 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(-thickness, sketch011rl)

// 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],
       repetitions: 1,
       distance: 1.22
     }, %)
const extrude012rl = extrude(-thickness, sketch012rl)

// GENERATE SERVER MODELS
// 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)
    |> lineTo([profileStartX(%), profileStartY(%)], %, $seg01)
    |> close(%)
  const extrude001s = extrude(7, sketch001s)

  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([0.34, -0.15], %)
    |> yLine(-2.97, %)
    |> lineTo([profileStartX(%), profileStartY(%)], %)
    |> close(%)

  const extrude002s = extrude(1.8 / 2, sketch002s)

  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([0.34, -0.15], %)
    |> yLine(-2.97, %)
    |> lineTo([profileStartX(%), profileStartY(%)], %)
    |> close(%)

  const extrude003s = extrude(1.8 / 2, sketch003s)
  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)
