+module CaseAperture(pos, dia, $fn) {
+ theta = 180/$fn;
+ translate([ pos[0] + bumper[0],
+ -epp2i[0],
+ -pos[1] ])
+ rotate([-90, theta, 0])
+ cylinder(r = dia/2 / cos(theta),
+ h = 60);
+}
+
+module SideButton(y, y_ref_sign, l){
+ // y_ref_sign:
+ // +1 measured from top of actual phone to top of button
+ // -1 measured from bottom of actual phone to bottom of button
+ // 0 y is centre of button in coordinate system
+ $button_l= l;
+ eff_y = y_ref_sign > 0 ? -bumper [1] -y -l/2 :
+ y_ref_sign < 0 ? (-phone -bumper)[1] +y +l/2 :
+ y;
+ //echo(eff_y);
+ translate([0, eff_y, 0])
+ children();
+}
+
+module LidButtonishLeg(y, y_ref_sign, l=buttonishleg_default_l_is_fudge) {
+ $button_leg_only = true;
+ SideButton(y, y_ref_sign, l) children();
+}
+
+module Buttons(){
+ Flip_rhs(1) SideButton(15.580, +1, 8.9) children(); // power
+ Flip_rhs(1) SideButton(48.700, -1, 8.920) children(); // camera
+ Flip_rhs(0) SideButton(30.800, +1, 21.96) children(); // volume
+ Flip_rhs( ) LidButtonishLeg(14, -1) children();
+// Flip_rhs(0) LidButtonishLeg(20, +1, 20) children();
+}
+
+module Struts(x_start, z_min, th){
+ // if th is negative, starts at z_min and works towards -ve z
+ // and object should then be printed other way up
+ for (i= [1 : 1 : case_struts_count]) {
+ translate([0,
+ 0,
+ z_min])
+ mirror([0,0, th<0 ? 1 : 0])
+ translate([0,
+ -phone_height * i / (case_struts_count+1),
+ case_struts_solid_below])
+ linear_extrude(height= abs(th)
+ -(case_struts_solid_below+case_struts_solid_above))
+ rectfromto([ x_start, -0.5 * case_struts_width ],
+ [ phone_width - x_start, +0.5 * case_struts_width ]);
+ }
+}
+
+module OrdinaryRearAperture(rhs,bot, pos){
+ Flip_rhs(rhs) Flip_bot(bot)
+ linextr(-20, 20)
+ mirror([0,1])
+ translate(pos + bumper)
+ children();
+}
+
+module MicroUSB(){
+ Flip_bot(1){
+ rotate([90,0,0])
+ mirror([0,0,1])
+ linextr(-epp2i[0], 60)
+ translate([0.5 * phone_width, 0, 0])
+ rectfromto([-microusb_width/2, epp2i[1] + microusb_below],
+ [+microusb_width/2, epp0[1] + -microusb_above]);
+ }
+}
+
+module OrdinaryRearApertures(){
+ // rear speaker
+ OrdinaryRearAperture(1,1, rearspeaker_pos_bl)
+ rectfromto(-rearspeaker_gap,
+ rearspeaker_size + rearspeaker_gap);
+
+ // finger hole to remove phone
+ if (len(fingerpushhole_dias))
+ OrdinaryRearAperture(1,0, [ fingerpushhole_dias[0]/2 + epp2i[0],
+ phone[1]/2 ])
+ scale(fingerpushhole_dias)
+ circle(r= 0.5 );
+}
+
+module RearCameraAperture(){
+ Flip_rhs(1)
+ mirror([0, 0, 1])
+ linear_extrude(height = 20)
+ mirror([0, 1, 0])
+ translate(bumper)
+ rectfromto(camera_pos_tl, camera_pos_br);
+}
+
+module HingeLidProfile(){
+ hull(){
+ circleat(hppT, hp_r1);
+ circleat(lpp12, lp_r12);
+ polygon([lpp10,
+ lpp13 + [2,0],
+ lpp12,
+ hppT]);
+ }
+}
+
+module HingeBaseProfile(){
+ difference(){
+ hull(){
+ circleat(hppB, hp_r1);
+ circleat(hppE, hp_r1);
+ circleat(epp2o, case_th_bottom);
+ circleat(hppB + [10,0], hp_r1);
+ }
+ polygon([epp5, epp1, epp2i, epp3, bppL]);
+ }
+}
+
+module HingeLeverOuterProfile(){
+ hull(){
+ circleat(hppT, hp_r2);
+ circleat(hppB, hp_r2);
+ }
+}
+
+module HingeLeverInnerProfile(){
+ for (s = [-1,+1]) {
+ c = s > 0 ? hppT : hppB;
+ translate(c)
+ mirror([0,0,s>0])
+ hull()
+ for (x=[-20,20])
+ for (y=[0, s * 10])
+ translate([x,y])
+ circle(hp_rn);
+ }
+}
+
+module Flip_hinge(){
+ hinge_origin = [0, -(phone_height - hppB[0]), hppB[1]];
+ translate(hinge_origin)
+ rotate([180,0,0])
+ translate(-hinge_origin)
+ children();
+}
+
+module HingePortion(x0,x1){
+ Flip_rhs() Flip_bot(1)
+ translate([x0,0,0])
+ mirror([1,0,0])
+ rotate([90,0,-90])
+ linear_extrude(height=x1-x0)
+ children(0);
+}
+
+module CatchPortion(width){
+ translate([phone_width/2, 0,0])
+ rotate([90,0,-90])
+ linextr(-width/2, width/2)
+ children(0);
+}
+
+module CaseBase(){
+ AroundEdges(epp3[1], case_th_bottom, 1)
+ EdgeProfile();
+}
+
+function prop_x(gamma) = hp_k / (2 * sin(gamma/2)) - hppT[0];
+
+module PropProfileAssignments(gamma){
+ // https://en.wikipedia.org/wiki/Solution_of_triangles#Two_sides_and_the_included_angle_given_(SAS)
+ x = prop_x(gamma);
+ p = phone_height + prlp10[0] - hppB[0];
+ b = p + x;
+
+ q = phone_height - hppT[0] - prcp1[0]; // $prpp7[0] is 0 by definition
+ a = q + x;
+ c = sqrt(a*a + b*b - 2*a*b*cos(gamma));
+ $prp_alpha = acos( (b*b + c*c - a*a) / (2*b*c) );
+
+ $prp_theta = 90 - $prp_alpha;
+ beta = 180 - $prp_alpha - gamma;
+ psi = 90 - beta;
+
+ //echo("abc", a,b,c);
+
+ v1 = [ [ cos(psi), -sin(psi) ], // x
+ [ sin(psi), cos(psi) ] ]; // y
+
+ $prpp7 = [0, c + (lpp13[1] - $prpp10[1] - hp_k) ];
+
+ $prp_r1 = prc_r1;
+ $prp_r11 = prop_main_th/2;
+
+ $prpp1 = $prpp7 + [1,0] *
+ // this is approximate, but will do
+ (prop_main_th/2 + prop_prop_gap + prcp1[0] - cppA[0]);
+ $prpp3 = $prpp1 +
+ v1[0] * -$prp_r1 +
+ v1[1] * ((prcp2[1] - prcp1[1]) - prop_prop_gap);
+ $prpp12 = $prpp3 + v1[0] *
+ (prop_end_dia + prop_caserecess_taper * ($prpp1[1] - $prpp3[1]));
+ $prp_r8 = prop_main_th;
+ $prpp4 = [ prop_main_th/2, $prpp3[1] ];
+ $prp_r5 = $prp_r8;
+ $prpp5 = [ $prpp12[0] - $prp_r5,
+ $prpp3[1] - prop_prong_h + $prp_r5 ];
+ $prpp6 = $prpp4 + [0,-1] * (prop_prong_h +
+ prop_prong_heel_slope * ($prpp5[0] - $prpp4[0]));
+ $prpp8 = $prpp4 + [0,-1] * $prp_r8;
+ $prpp9 = $prpp8 + [-1,0] * $prp_r8;
+
+ children();
+}
+
+module PropProfile(gamma, cut=0, rot=0){ ////toplevel
+ PropProfileAssignments(gamma){
+
+ //#circleat($prpp3,1);
+ //#circleat($prpp12,1);
+
+ if (!cut) {
+ hull(){
+ translate($prpp8)
+ intersection(){
+ circle($prp_r8);
+ polygon([[-20,-0], [20,20], [0,0]]);
+ }
+ rectfromto($prpp6, $prpp9);
+ translate($prpp5) intersection(){
+ circle($prp_r5);
+ polygon([[-10,-10], [0,0], [10,0]]);
+ }
+ rectfromto($prpp12 + [0,-0.1], $prpp3);
+ }
+ hull(){
+ circleat($prpp1, $prp_r1);
+ rectfromto($prpp12 + [0,-0.1], $prpp3);
+ }
+ }
+ // main shaft
+ rotate([0,0, rot*-$prp_theta]){
+ hull(){
+ extra = cut ? prop_recess_slop : 0;
+ rectfromto($prpp6, $prpp9);
+ circleat($prpp11, $prp_r11 + extra);
+ circleat($prpp10, $prp_r10 + extra);
+ }
+ }
+ }
+}
+
+module PropAggregateProfile(){
+ for (angle = prop_angles)
+ PropProfile(angle, 0,0);
+}
+
+module Prop(){ ////toplevel
+ hw = prop_main_width/2;
+ linextr(-hw, +hw)
+ PropAggregateProfile();
+}
+