package main;

# add_ease2 ($piece)
#basic_ease_mln 
#sub cup_ease

########################################################################################
  
sub add_ease2{
local ($piece) = @_;


# Call to obtain the appropriate ease values.
# Then add the ease values to the base values.
#
# note that "hip" is a misnomer.  It is really the width above the welt.
# generally, this is narrower than the persons real hip
# because most sweaters are shorter than hip lenght.

$cup_ease = 0; $cup_length = 0;
#&cup_ease;


&basic_ease_mln;


$d_hip = $hip + $e_hip +$e_chest_dif;      # later on put in an "if".
			                            # if the sweater is longer than hip length, my ease is no good.
																																# e_chest_dif is for tedy bears.

$d_chest = $chest + $e_chest_d;  # these are full ease values.  $e_chest_d accounts for cup ease and teddy bear stuff
$d_waist = $waist + $e_waist;
$d_shoulder = $natural_shoulder + $e_shoulder;
$diam_armhole = $chest + $e_armhole;
if(($natural_shoulder-$neck_width) != 0) {
    $d_shoulder_slope = $d_shoulder_slope * 
           ($d_shoulder-$e_neck_width-$neck_width)/($natural_shoulder-$neck_width);}

       else { print "<br> ERROR. You input a zero for your shoulder width."; }

# estimate the front line.  This is hard for people to measure on themselves, so I'm not having them adjust it.

$d_back_waist = $back_waist + $e_back_waist + $jewel_neck_depth;
$d_bust_depth = $bust_depth + $e_bust_depth;

if($adjust_hip_rib eq "yes"){
#     $d_hip_welt = $d_hip - $e_hip + $e_hip_rib; # old indirect way of calculating.
      $d_hip_welt = $hip + $e_hip_rib +$e_chest_dif; }
     else {$d_hip_welt = $d_hip;}   # this saves this for adjusting the ribbing.
#####################
## overwrite some values based on style choices.

  if($body_style eq "straight") { $d_chest = &max($d_chest,$d_hip) ; #found problme!!
                             $d_hip = $d_chest;    }

# note: chest hip and waist widths are full -- not divided by two for per piece.
  
       if($body_style eq "hip_waist_chest"){
          
           $new_waist =  $d_waist;}

     else{   $new_waist =  &min($d_chest,$d_hip); 
             $new_waist =  &max($new_waist,$d_chest); }  # yes, I'll make sure I clear the waist!


$diam_armhole=$d_chest; # change if bust darts are implemented
####################################################################

# these are full measurements not halved.

# adjustments for non-fitted sleeve
#		 semi_drop and snug semi drop are dropped halfway between shoulder and armhole.
#   

if ($sleeve_cap eq "semi_drop") {$d_shoulder = 0.5 * ($natural_shoulder + $diam_armhole/2);}
if ($sleeve_cap eq "snug_semi_drop") {$d_shoulder = 0.5 * ($natural_shoulder + $diam_armhole/2);}
if ($sleeve_cap eq "drop") {$d_shoulder = $diam_armhole/2;}

if ($debug eq "on") {print "<br> In add ease2: natural shoulder, $natural_shoulder diam_armhole/2= $diam_armhole/2
dshoulder $d_shoulder ";} 

return ( $d_hip, $d_chest, $d_waist,$d_shoulder,$d_back_waist);

}

# this is used for teh boat neck.  It will advise how much to overlap the neck.

#calculate the approximate armhole scye:
 
1;

########################################################################################
sub basic_ease_mln {

# this is the ease suggested for the basic by Mary Louise Norman.
# I'd generally apply this for nice fitted sweaters. 
# but it is easier to keep track of all MLN's recommendations by calling this first.
# 
# These are the ease values suggested for the "basic" in Norman.
#ease information.  These make some sense in inches.
# I am taking the total ease from Mary Louise Norman's book for the "basic form".
# however, I am putting a real ease in for the waiste because her basic form doesn't use this. 
# I will end up implementing it slightly differently.

# in centimeters, for the *whole* body
				#MLN suggests an average slope of 3.25 cm .  Knit to fit suggests that womens
    # shoulders have become more square and 1" is fine.  I'm going to split the difference
    # and use 2.8 cm. That way, people with sloping shoulders can stick in a
    # shoulder pad.


# These are added to the length from the shoulder to the waist.
# these aren't used yet, so they aren't proof-run or proof knitted yet.
  $e_back_waist_b =   $e_snug_scye_b +$e_shoulder_slope_back;  # this is the sum of the extra added in page 8 comment 4 and page 10 comment 2
  $e_back_waist_f  =  $e_snug_scye_f +$e_shoulder_slope_front; # this is the sum of the extra in comment 3 on page 8.  

# right now, $e_snug_scye_f is always zero. $e_shoulder_slope_front and $e_shoulder_slope_back are zero.

# sleeve ease
  $e_cap_scye = -0.05  ;#(Page 21 MLN.  I changed to a fraction. Later on I must multiply instead of adding.)


# the back is this much longer than the front:

$dif_sweater_length = $e_back_waist_b - $e_back_waist_f;  

# This should take care of the fact that the teddy bears arms stick out towards the front.

if($size eq "Teddy") {

  if( $arms_forward eq "yes"){ $e_chest_dif = 0.18 * $chest;}
  else                      {$e_chest_dif = 0;}

  $e_neck_teddy = $e_chest_dif * &min( 2* $neck_width/$chest,1);  # neck is a single sided measure

$e_neck_teddy  = &round($e_neck_teddy,0.01);
$e_chest_dif =&round($e_chest_dif,0.01);

   if( $print eq "yes"){
     
       if( $arms_forward eq "yes"){
       print "<p> To accommodate Teddies whose arms stick forward, the back chest width
       will be  $e_chest_dif $unit larger than the front chest width. 
       The back neck width will be $e_neck_teddy $unit wider than the front neck width ";
       }
       else {
        print "<p> You requested a sweater for a teddy whose arms stick straight out to the sides.  
        The back and front widths will be identical. "}

    }

    $e_neck_teddy =$e_neck_teddy/2;
} #end teddy if


else {$e_chest_dif = 0;
      $e_neck_teddy = 0;}
 
if ($piece eq "front") {
       $e_back_waist = $e_back_waist_f + $cup_length;
       $e_bust_depth = $e_back_waist_f;
       $e_snug_scye =$e_snug_scye_f;
       $d_shoulder_slope = $shoulder_slope + $e_shoulder_slope_front;
       $d_sweater_length = $sweater_length -$dif_sweater_length;      
	# for chest and armhole part, 	the cup ease is added, and the teddy bear ease subtracted.		

      	$e_armhole =  $e_chest - $cup_ease - $e_chest_dif; # this makes it match the back
       $e_chest_d =    $e_chest + $cup_ease - $e_chest_dif; # I've added the cup ease.
       $front_line = 0.95 * $d_shoulder;  # Norman measures this.  I am scaling from a butterick pattern.
       $e_chest_dif = - $e_chest_dif;  #forlater call to adjust the hip.

        $e_neck_teddy = - $e_neck_teddy;  #change sign.

}

 if($piece eq "back")  
   
     {$e_back_waist = $e_back_waist_b; 
      $e_bust_depth = $e_back_waist_b;
      $e_snug_scye =$e_snug_scye_b;
      $d_shoulder_slope = $shoulder_slope + $e_shoulder_slope_back;
      $d_sweater_length = $sweater_length;
      
      $e_armhole =   $e_chest - $cup_ease + $e_chest_dif ;
      $e_chest_d =     $e_chest - $cup_ease + $e_chest_dif ;  # on back, straight up to armhole.
                                        # note: front chest + back chest = whole chest. 
   }



} 1;


########################################################################################
sub cup_ease {

# This adjust ease on front and back to accommodate bust.
# I use Butterick's standard body measurements to conclude that the length for the dart increase by
# 3/8 per cup size.  The bust is all in the front, and each larger cup size adds 1" to the front chest 
# measurement.

# Some one one the list suggested 1/2" per cup size.  So, the 3/8" should avoid 
#Over fitting.
#
# I have no dart for an A cup.  I will need to make sure that men's and children's sweater get set to cup size A.

 

# Unless the customer rejects it, I want to add eased or real darts.  This is the amount I will add.
#  
# A reader from the list says this:
# I'm a 36/38DDD ....some fitting manuals suggest
#> ending 1" from the apex, my personal preference is 2". I usually add a 2" in
#> depth dart.  
#  She makes the front 10" wider than the back.  So, I am *way* underestimating here.
#  Note that the first armhole decrease up to Armhole 3 should be developed from the back.
# after that,the decreases should continue on the front down the shoulder.
#I need to figure out the geometry to make this work in rotation.
#

$cup_ease = 0; $cup_length = 0;
 if($piece eq "front") {

  if($dart_ease = "yes") {
      if($cup eq "B") {$cup_ease = 0.5/2; $cup_length = 1/8;}
      if($cup eq "C") {$cup_ease = 1.5/2; $cup_length = 0.5;}
      if($cup eq "D") {$cup_ease = 2.5/2; $cup_length = 7/8;}
      if($cup eq "DD") {$cup_ease = 3.5/2; $cup_length = 10/8;}
      if($cup eq "DDD") {$cup_ease = 4.5/2; $cup_length = 13/8;}
						if($cup eq "DDDD") {$cup_ease = 5.5/2; $cup_length = 16/8;}
     
   }

if($units eq "cm") {$cup_ease = $cup_ease*2.54; $cup_length = $cup_length * 2.54;}

}
} 1;
########################################
