2019-09-21 19:57:29 +02:00
import { CreateCrotchPoints } from './util'
2019-08-21 08:55:57 -07:00
export default function ( part ) {
2019-09-21 19:57:29 +02:00
let { options , measurements , Point , Path , points , paths } = part . shorthand ( )
let seatDepth = measurements . seatDepth + measurements . seatDepth * options . waistRaise
let circumference = measurements . seatCircumference
let circumference4 = circumference / 4
points . mWaist = new Point ( 0 , 0 )
CreateCrotchPoints ( part )
points . mLeg = points . mHip . shift ( 270 , measurements . inseam * ( 1 - options . legShortening ) )
points . fLegSide = points . mLeg . shift ( 180 , options . crotchFront * circumference4 )
points . bLegSide = points . mLeg . shift ( 0 , options . crotchBack * circumference4 )
points . fWaistFront = points . fWaistSide . shift ( 180 , circumference4 )
points . fWaistFrontOverlap = points . fWaistFront . shift ( 180 , options . waistOverlap * circumference4 )
points . fHipFront = points . fHipSide . shift ( 180 , circumference4 )
points . fHipFrontOverlap = points . fHipFront . shift ( 180 , options . waistOverlap * circumference4 )
points . fLegFront = points . fLegSide . shift ( 180 , circumference4 )
points . fLegFrontOverlap = points . fLegFront . shift ( 180 , options . waistOverlap * circumference4 )
2019-08-21 08:55:57 -07:00
// Calculate the distance we need to move horizontally to get to the point that will
// diagonally be the distance we're looking for (circumference/4)
let bHorDistance = Math . sqrt (
2019-09-21 19:57:29 +02:00
circumference4 * circumference4 - options . backRaise * seatDepth * options . backRaise * seatDepth
)
2019-08-21 08:55:57 -07:00
// Create a point that is this distance from the side.
points . bWaistBack = points . mWaist
. shift ( 90 , options . waistBand )
2019-09-21 19:57:29 +02:00
. shift ( 0 , options . crotchBack * circumference4 + bHorDistance )
points . bWaistBackOverlap = points . bWaistBack . shift ( 0 , options . waistOverlap * circumference4 )
points . bHipBack = points . bHipSide . shift ( 0 , circumference4 )
points . bHipBackOverlap = points . bHipBack . shift ( 0 , options . waistOverlap * circumference4 )
points . bLegBack = points . bLegSide . shift ( 0 , circumference4 )
points . bLegBackOverlap = points . bLegBack . shift ( 0 , options . waistOverlap * circumference4 )
points . bWaistSideTemp = points . bWaistSide . shift ( 0 , 2 ) // This is a trick to make the offset() call work. Without it, the offset is crossing the cutout line.
2019-08-21 08:55:57 -07:00
paths . waistBack = new Path ( )
. move ( points . bWaistBackOverlap )
. line ( points . bWaistBack )
. line ( points . bWaistSideTemp ) // This is a trick to make the offset() call work. Without it, the offset is crossing the cutout line.
. line ( points . bWaistSide )
2019-09-21 19:57:29 +02:00
. setRender ( false )
2019-08-21 08:55:57 -07:00
paths . waistFront = new Path ( )
. move ( points . fWaistSide )
. line ( points . fWaistFront )
. line ( points . fWaistFrontOverlap )
2019-09-21 19:57:29 +02:00
. setRender ( false )
2019-08-21 08:55:57 -07:00
paths . front = new Path ( )
. move ( points . fWaistFrontOverlap )
. line ( points . fHipFrontOverlap )
. line ( points . fLegFrontOverlap )
2019-09-21 19:57:29 +02:00
. setRender ( false )
2019-08-21 08:55:57 -07:00
paths . back = new Path ( )
. move ( points . bLegBackOverlap )
. line ( points . bHipBackOverlap )
. line ( points . bWaistBackOverlap )
2019-09-21 19:57:29 +02:00
. setRender ( false )
2019-08-21 08:55:57 -07:00
paths . leg = new Path ( )
. move ( points . fLegFrontOverlap )
. line ( points . bLegBackOverlap )
2019-09-21 19:57:29 +02:00
. setRender ( false )
2019-08-21 08:55:57 -07:00
paths . cutout = new Path ( )
. move ( points . bWaistSide )
. curve ( points . bWaistCrotchCP , points . bHipCrotchCP , points . mHip )
. curve ( points . fHipCrotchCP , points . fWaistCrotchCP , points . fWaistSide )
2019-09-21 19:57:29 +02:00
. setRender ( false )
2019-08-21 08:55:57 -07:00
paths . seam = paths . waistFront
. join ( paths . front )
. join ( paths . leg )
. join ( paths . back )
. join ( paths . waistBack )
. join ( paths . cutout )
. close ( )
2019-09-21 19:57:29 +02:00
. attr ( 'class' , 'fabric' )
2019-08-21 08:55:57 -07:00
if ( options . frontPocket ) {
points . frontPocketTop = points . fWaistSide
. shift (
270 ,
2019-09-21 19:57:29 +02:00
options . frontPocketVerticalOffset * measurements . seatDepth + options . waistBand * 2
2019-08-21 08:55:57 -07:00
)
2019-09-21 19:57:29 +02:00
. shift ( 180 , options . frontPocketHorizontalOffset * measurements . seatCircumference )
2019-08-21 08:55:57 -07:00
2019-09-21 19:57:29 +02:00
points . frontPocketTop2 = points . frontPocketTop . shift ( 340 , 12 )
2019-08-21 08:55:57 -07:00
points . frontPocketBottom = points . frontPocketTop . shift (
250 ,
options . frontPocketSize * measurements . seatDepth
2019-09-21 19:57:29 +02:00
)
points . frontPocketBottom2 = points . frontPocketBottom . shift ( 340 , 12 )
2019-08-21 08:55:57 -07:00
paths . frontPocket = new Path ( )
. move ( points . frontPocketTop )
. line ( points . frontPocketBottom )
. line ( points . frontPocketBottom2 )
. line ( points . frontPocketTop2 )
. close ( )
2019-09-21 19:57:29 +02:00
. attr ( 'class' , 'fabric' )
2019-08-21 08:55:57 -07:00
}
if ( options . backPocket ) {
points . backPocketRight = points . bWaistBack
. shiftTowards (
points . bWaistSide ,
options . backPocketHorizontalOffset * measurements . seatCircumference
)
2019-09-21 19:57:29 +02:00
. shift ( 270 , options . backPocketVerticalOffset * measurements . seatDepth + options . waistBand * 2 )
2019-08-21 08:55:57 -07:00
points . backPocketLeft = points . bWaistBack
. shiftTowards (
points . bWaistSide ,
options . backPocketHorizontalOffset * measurements . seatCircumference +
options . backPocketSize * measurements . seatDepth
)
2019-09-21 19:57:29 +02:00
. shift ( 270 , options . backPocketVerticalOffset * measurements . seatDepth + options . waistBand * 2 )
2019-08-21 08:55:57 -07:00
points . backPocketRight2 = points . backPocketRight . shift (
points . backPocketRight . angle ( points . backPocketLeft ) + 90 ,
12
2019-09-21 19:57:29 +02:00
)
2019-08-21 08:55:57 -07:00
points . backPocketLeft2 = points . backPocketLeft . shift (
points . backPocketLeft . angle ( points . backPocketRight ) - 90 ,
12
2019-09-21 19:57:29 +02:00
)
2019-08-21 08:55:57 -07:00
paths . backPocket = new Path ( )
. move ( points . backPocketLeft )
. line ( points . backPocketLeft2 )
. line ( points . backPocketRight2 )
. line ( points . backPocketRight )
. close ( )
2019-09-21 19:57:29 +02:00
. attr ( 'class' , 'fabric' )
2019-08-21 08:55:57 -07:00
}
2019-09-21 19:57:29 +02:00
part . render = false
return part
2019-08-21 08:55:57 -07:00
}