// Poopy Shoe
// poop shute for bambu labs printer - optimized for printing.

// Set units
@settings(defaultLengthUnit = in, kclVersion = 1.0)

// Define parameters
wallThickness = 0.125
wallsWidth = 3
height = 5.125
filletRadius = 0.050
backLength = 6
exitHeight = 1
frontLength = 7

// Create the curved portion that catches the printer poop
sketch001 = startSketchOn(-YZ)
  |> startProfile(at = [wallsWidth / 2, 0])
  |> xLine(length = wallThickness / 2)
  |> angledLine(angle = 60, endAbsoluteX = wallsWidth, tag = $seg01)
  |> yLine(endAbsolute = height)
  |> xLine(length = -wallThickness)
  |> yLine(endAbsolute = segEndY(seg01))
  |> angledLine(angle = 60, endAbsoluteX = wallsWidth / 2 + wallThickness / 2)
  |> xLine(length = -wallThickness)
  |> angledLine(angle = 180 - 60, endAbsoluteX = wallThickness)
  |> yLine(endAbsolute = height)
  |> xLine(endAbsolute = 0)
  |> yLine(endAbsolute = segEndY(seg01))
  |> angledLine(angle = 180 - 60, endAbsoluteY = 0)
  |> close()
part001 = revolve(
  sketch001,
  angle = 90,
  axis = {
    direction = [1.0, 0.0],
    origin = [0.0, height + .0001]
  },
)

sketch002 = startSketchOn(-YZ)
  |> startProfile(at = [wallsWidth / 2, 0])
  |> xLine(length = wallThickness / 2)
  |> angledLine(angle = 60, endAbsoluteX = wallsWidth, tag = $seg02)
  |> yLine(endAbsolute = height)
  |> xLine(length = -wallThickness)
  |> yLine(endAbsolute = segEndY(seg01))
  |> angledLine(angle = 60, endAbsoluteX = wallsWidth / 2 + wallThickness / 2)
  |> xLine(length = -wallThickness)
  |> angledLine(angle = 180 - 60, endAbsoluteX = wallThickness)
  |> yLine(endAbsolute = height)
  |> xLine(endAbsolute = 0)
  |> yLine(endAbsolute = segEndY(seg02))
  |> angledLine(angle = 180 - 60, endAbsoluteY = 0)
  |> close()
  |> extrude(length = backLength - height)

customPlane = {
  origin = {
    x = 0,
    y = -(wallsWidth / 2 - (wallThickness / 2)),
    z = 0
  },
  xAxis = { x = 1, y = 0, z = 0 },
  yAxis = { x = 0, y = 0, z = 1 }
}
sketch003 = startSketchOn(customPlane)
  |> startProfile(at = [0, 0])
  |> tangentialArc(angle = 60, radius = height)
  |> angledLine(angle = 60, endAbsoluteY = 0)
  |> close()
  |> extrude(length = wallThickness)

// Create the right side wall of the tub
sketch004 = startSketchOn(sketch002, face = END)
  |> startProfile(at = [0, 0])
  |> yLine(endAbsolute = height)
  |> xLine(endAbsolute = wallThickness)
  |> yLine(endAbsolute = segEndY(seg01))
  |> angledLine(angle = 180 - 60, endAbsoluteX = wallsWidth / 2 - (wallThickness / 2))
  |> xLine(length = wallThickness)
  |> angledLine(angle = 60, endAbsoluteY = segEndY(seg01))
  |> yLine(endAbsolute = height)
  |> xLine(length = wallThickness)
  |> tangentialArc(endAbsolute = [
       (frontLength - wallsWidth) / 2 + wallsWidth,
       height - ((height - exitHeight) / 2)
     ])
  |> tangentialArc(endAbsolute = [frontLength, exitHeight])
  |> yLine(endAbsolute = 0)
  |> close(tag = $seg04)
  |> extrude(length = wallThickness)

customPlane2 = {
  origin = {
    x = -1 * (backLength - height + wallsWidth),
    y = 0,
    z = 0
  },
  xAxis = { x = 0, y = 1, z = 0 },
  yAxis = { x = 0, y = 0, z = 1 }
}
sketch005 = startSketchOn(customPlane2)
  |> startProfile(at = [0, 0])
  |> yLine(endAbsolute = height)
  |> xLine(endAbsolute = -wallsWidth)
  |> tangentialArc(endAbsolute = [
       -1 * ((frontLength - wallsWidth) / 2 + wallsWidth),
       height - ((height - exitHeight) / 2)
     ])
  |> tangentialArc(endAbsolute = [-frontLength, exitHeight])
  |> yLine(endAbsolute = 0, tag = $seg03)
  |> close()
  |> extrude(length = wallThickness)

sketch006 = startSketchOn(sketch005, face = seg03)
  |> startProfile(at = [0, -1 * (backLength - height)])
  |> xLine(endAbsolute = -exitHeight)
  |> yLine(length = -wallsWidth)
  |> xLine(endAbsolute = 0)
  |> close()
  |> extrude(length = wallThickness)

sketch007 = startSketchOn(sketch004, face = END)
  |> startProfile(at = [0, 0])
  |> xLine(endAbsolute = wallThickness)
  |> yLine(endAbsolute = height)
  |> xLine(endAbsolute = 0)
  |> close()
  |> extrude(length = wallsWidth - (2 * wallThickness))

customPlane3 = {
  origin = {
    x = -1 * (backLength - height + wallsWidth),
    y = 0,
    z = wallThickness
  },
  xAxis = { x = 0, y = -1, z = 0 },
  yAxis = { x = 1, y = 0, z = 0 }
}

sketch008 = startSketchOn(customPlane3)
  |> startProfile(at = [wallThickness, wallThickness])
  |> xLine(endAbsolute = frontLength)
  |> yLine(length = wallsWidth - (2 * wallThickness))
  |> xLine(endAbsolute = wallThickness)
  |> close()
  |> extrude(length = -wallThickness)
