// Wheel rotor
// A component of a disc brake system. It provides a surface for brake pads to press against, generating the friction needed to slow or stop the vehicle.

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

// Import parameters
import rotorDiameter, rotorInnerDiameter, rotorSinglePlateThickness, rotorInnerDiameterThickness, lugHolePatternDia, lugSpacing, rotorTotalThickness, spacerPatternDiameter, spacerDiameter, spacerLength, spacerCount, wheelDiameter, lugCount, yAxisOffset, drillAndSlotCount from "parameters.kcl"

rotorSketch = startSketchOn(XZ)
  |> circle(center = [0, 0], radius = rotorDiameter / 2)
rotor = extrude(rotorSketch, length = rotorSinglePlateThickness)
  |> appearance(color = "#dbcd70", roughness = 90, metalness = 90)

rotorBumpSketch = startSketchOn(rotor, face = END)
  |> circle(center = [0, 0], radius = rotorInnerDiameter / 2)
rotorBump = extrude(rotorBumpSketch, length = rotorInnerDiameterThickness)

lugHoles = startSketchOn(rotorBump, face = END)
  |> circle(center = [-lugSpacing / 2, 0], radius = 0.315)
  |> patternCircular2d(
       arcDegrees = 360,
       center = [0, 0],
       instances = lugCount,
       rotateDuplicates = true,
     )
  |> extrude(%, length = -(rotorInnerDiameterThickness + rotorSinglePlateThickness))
  |> appearance(color = "#dbcd70", roughness = 90, metalness = 90)

// (update when boolean is available)
centerSpacer = startSketchOn(rotor, face = START)
  |> circle(%, center = [0, 0], radius = .25)
  |> extrude(%, length = spacerLength)

secondaryRotorSketch = startSketchOn(centerSpacer, face = END)
  |> circle(center = [0, 0], radius = rotorDiameter / 2)
secondRotor = extrude(secondaryRotorSketch, length = rotorSinglePlateThickness)

lugHoles2 = startSketchOn(secondRotor, face = END)
  |> circle(center = [lugSpacing / 2, 0], radius = 0.315)
  |> patternCircular2d(
       arcDegrees = 360,
       center = [0, 0],
       instances = lugCount,
       rotateDuplicates = true,
     )
  |> extrude(length = -rotorSinglePlateThickness)

spacerSketch = startSketchOn(rotor, face = START)
  |> circle(center = [spacerPatternDiameter / 2, 0], radius = spacerDiameter)
  |> patternCircular2d(
       arcDegrees = 360,
       center = [0, 0],
       instances = spacerCount,
       rotateDuplicates = true,
     )
spacers = extrude(spacerSketch, length = spacerLength)

rotorSlottedSketch = startSketchOn(rotor, face = START)
  |> startProfile(at = [2.17, 2.56])
  |> xLine(length = 0.12)
  |> yLine(length = 2.56)
  |> xLine(length = -0.12)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
  |> patternCircular2d(
       center = [0, 0],
       instances = drillAndSlotCount,
       arcDegrees = 360,
       rotateDuplicates = true,
     )
rotorSlotted = extrude(rotorSlottedSketch, length = -rotorSinglePlateThickness / 2)

secondRotorSlottedSketch = startSketchOn(secondRotor, face = END)
  |> startProfile(at = [-2.17, 2.56])
  |> xLine(length = -0.12)
  |> yLine(length = 2.56)
  |> xLine(length = 0.12)
  |> line(endAbsolute = [profileStartX(%), profileStartY(%)])
  |> close()
  |> patternCircular2d(
       center = [0, 0],
       instances = drillAndSlotCount,
       arcDegrees = 360,
       rotateDuplicates = true,
     )

carRotor = extrude(secondRotorSlottedSketch, length = -rotorSinglePlateThickness / 2)
  |> appearance(color = "#dbcd70", roughness = 90, metalness = 90)
