
include <BOSL2/std.scad>;

module finfit(base_length, mirror_vec,screw = true,pin=true)
{
    front_offset = tab_length;
    length = base_length + tab_length;
    mirror(mirror_vec)
        translate([0,-front_offset, 0])
            chinook( length, screw ,pin );
}

module chinook(length,screw = true,pin=true,thick = 9.2,height=25,tab_height=13,)
{
    difference()
    {
        base_cube( length, thick, height );
        tab_cut( thick ,height, tab_height );
        if (screw) 
            screw_cut(tab_height);
        back_round_cut(length,thick,height);
        if (pin) 
            pin_cut(length,tab_height);
        thickness_cut(length,height, thick/2);
        thickness_cut(length,height, -thick/2);
    }
}

module chinook_profile(length,thick = 9.2,height=25,tab_height=13,tab_round=13,tab_length=9.6*2)
{
    difference(){ 
        rect(
            [height,length],
            rounding=[tab_round,0,0,0],
            anchor=BOTTOM+LEFT
        )
        {
            align(RIGHT+BOTTOM,inside=true,shiftout=0.1) 
                rect( [ height-tab_height, tab_length+tab_round ],rounding=[0,tab_round-1,0,0] );
        }
    }    
  
    //region(difference(shape1,shape2));
    
 }

module base_cube( length,thick,height )
{
    translate([0,0,-thick/2])
        cube(
            size=[
                height,
                length,
                thick
            ],
            center=false
        );
}

module tab_cut( thick, height,tab_height,tab_round=13,tab_length=9.6*2 )
{
    translate([tab_height,0,-thick/2*1.1])
    union()
    {
        translate([0,-thick,0])
            cube(
                size=[height, tab_length+thick, thick*1.1],
             center=false);
        translate([tab_round,tab_length,0])
            cylinder(h=thick*1.1,r=tab_round,center=false);
    }
}



module screw_cut(tab_height,screw_pos=9.6,screw_dia=4.5)
{
    translate([tab_height/2,screw_pos,0])
    rotate([0,90,0])
    cylinder(h=tab_height*1.1,
             d=screw_dia,
             center=true);
}

module back_round_cut(BaseLength,thick,height,tab_round=13)
{
    translate([height-tab_round,
               BaseLength-tab_round,
               -thick/2*1.1])
    difference()
    {
        cube(size=[tab_round*1.1,
                   tab_round*1.1,
                   thick*1.1],
             center=false);
        cylinder(h=thick*1.2,
                 r=tab_round,
                 center=false);
    }
}

module pin_cut(BaseLength,tab_height,pin_dia=3, pin_back=9,pin_depth=16.4)
{
    translate([pin_depth,
               BaseLength-pin_back,
               0])
        rotate([0,0,0])
            cylinder(
                h=tab_height*1.1,
                d=pin_dia,
                center=true
            );
}

module thickness_cut(BaseLength,height, zOffset,pin_depth=16.4, pin_back=9,thick_cut = 1 )
{
    translate([
        pin_depth,
        BaseLength-pin_back,
        zOffset])
        rotate([0,0,45])
            cube(
                size=[
                    pin_depth*2.2,
                    height*3,
                    thick_cut
                ],
                center=true
            );
}

if (true) {
   
   chinook(130+20); 
   //up(5.2) left() color("Yellow")chinook_profile(130+20); 


}




