// ============================================
// SaltyLab — Bumper (Front/Rear)
// 350×50×30mm TPU
// Absorbs falls, protects frame and floor
// ============================================
include <dimensions.scad>

bumper_w = 350;
bumper_h = 50;
bumper_d = 30;
bumper_wall = 2.5;

// Honeycomb crush structure for energy absorption
hex_size = 8;
hex_wall = 1.2;

module honeycomb_cell(size, height) {
    difference() {
        cylinder(d=size, h=height, $fn=6);
        translate([0, 0, -1])
            cylinder(d=size - hex_wall*2, h=height + 2, $fn=6);
    }
}

module bumper() {
    difference() {
        union() {
            // Outer shell (curved front face)
            hull() {
                translate([-bumper_w/2, 0, 0])
                    cube([bumper_w, 1, bumper_h]);
                translate([-bumper_w/2 + 10, bumper_d - 5, 5])
                    cube([bumper_w - 20, 1, bumper_h - 10]);
            }
        }
        
        // Hollow interior (leave outer shell)
        hull() {
            translate([-bumper_w/2 + bumper_wall, bumper_wall, bumper_wall])
                cube([bumper_w - bumper_wall*2, 1, bumper_h - bumper_wall*2]);
            translate([-bumper_w/2 + 10 + bumper_wall, bumper_d - 5 - bumper_wall, 5 + bumper_wall])
                cube([bumper_w - 20 - bumper_wall*2, 1, bumper_h - 10 - bumper_wall*2]);
        }
        
        // Mounting bolt holes (M5, through back face, 4 points)
        for (x = [-120, -40, 40, 120]) {
            translate([x, -1, bumper_h/2])
                rotate([-90, 0, 0])
                    cylinder(d=m5_clear, h=10, $fn=25);
        }
    }
    
    // Internal honeycomb ribs for crush absorption
    intersection() {
        // Bound to bumper volume
        hull() {
            translate([-bumper_w/2 + bumper_wall, bumper_wall, bumper_wall])
                cube([bumper_w - bumper_wall*2, 1, bumper_h - bumper_wall*2]);
            translate([-bumper_w/2 + 15, bumper_d - 8, 8])
                cube([bumper_w - 30, 1, bumper_h - 16]);
        }
        
        // Honeycomb grid
        for (x = [-170:hex_size*1.5:170]) {
            for (z = [0:hex_size*1.3:60]) {
                offset_x = (floor(z / (hex_size*1.3)) % 2) * hex_size * 0.75;
                translate([x + offset_x, 0, z])
                    rotate([-90, 0, 0])
                        honeycomb_cell(hex_size, bumper_d);
            }
        }
    }
}

bumper();
