package uk.co.nickthecoder.foocad.woodworking.v1 class Woodworking { // Values suitable for the `side` parameter when creating joints. // See [PieceOfWood].lap( side ) etc. class val FACE_SIDE = 0 class val FACE_EDGE = 1 class val END_GRAIN = 2 class val OPPOSITE_SIDE = 3 class val OPPOSITE_EDGE = 4 class val START_GRAIN = 5 // The side we need to start cutting a groove from in order for the groove // to appear on the side required. class val _grooveSide = intArrayOf( END_GRAIN, FACE_SIDE, FACE_EDGE, START_GRAIN, OPPOSITE_SIDE, OPPOSITE_EDGE ) func Wood( name : String, width : double, thickness : double ) = Wood( name, Square( width, thickness ) ) func Wood( name : String, width : double, thickness : double, color : String ) = Wood( name, Square( width, thickness ).color( color ) ) func Plywood( name : String, thickness : double ) = Plywood( name, thickness, Color.valueOf("Khaki") ) func Plywood( name : String, thickness : double, color : String ) = Plywood( name, thickness, Color.valueOf(color) ) func mitreShape( size : double ) = PolygonBuilder().apply { moveTo(0,0) lineTo( 0, size ) lineTo( size, 0 ) lineTo( 0,0 ) }.build() func mitreShape( size : double, angle : double ) = PolygonBuilder().apply { moveTo(0,0) lineTo( 0, size / Math.tan(angle * Math.PI / 180.0) ) lineTo( size, 0 ) lineTo( 0,0 ) }.build() /** * An isosceles Triangle with width=[depth]*2 and height=[depth] */ func vGrooveShape( depth : double ) = PolygonBuilder().apply { moveTo( -depth, 0 ) lineTo( 0, depth ) lineTo( depth, 0 ) lineTo( -depth, 0 ) }.build() func roundedShape( radius : double ) = (Square( radius + 0.1 ) - Circle( radius )) .rotate(180).toOrigin() .margin( -0.1 ) func mortiseShape( wood : Wood, marginX : double, marginY : double ) : Shape2d { return Square( wood.width - marginX * 2, wood.thickness - marginY * 2 ) .translate( marginX, marginY ) .margin( marginX, marginY ) } func tenonShape( wood : Wood, marginX : double, marginY : double ) : Shape2d { return Square( wood.width, wood.thickness ) - mortiseShape( wood, marginX, marginY ) } class var showCutouts = false func debugCutout( shape : Shape3d ) : Shape3d = if (showCutouts) shape.previewOnly() else null }