Fixed labels which previously went off edges of bar and tower.
This commit is contained in:
parent
d9e3b5520f
commit
85ee00dc19
2 changed files with 299 additions and 3 deletions
|
|
@ -147,8 +147,48 @@ module rounded_box_uncentered(x, y, z, r) {
|
|||
square([x, y], center=false);
|
||||
}
|
||||
|
||||
|
||||
module place_top_label(txt, x, y, z, center_it=false) {
|
||||
|
||||
// --- parameters ---
|
||||
margin = 2; // mm clearance from edges
|
||||
|
||||
// usable space
|
||||
usable_x = x - margin;
|
||||
usable_y = y - margin;
|
||||
|
||||
// choose orientation: run along long axis
|
||||
rotate_text = (y > x);
|
||||
|
||||
// limiting width after orientation
|
||||
limit = rotate_text ? usable_y : usable_x;
|
||||
|
||||
// crude text width estimate factor (~0.6 * size * chars)
|
||||
est_char_width = 1.0;
|
||||
est_len = len(txt) * est_char_width;
|
||||
|
||||
// compute size that fits
|
||||
auto_size = limit / est_len;
|
||||
|
||||
// clamp to your preferred max size
|
||||
final_size = min(label_size, auto_size);
|
||||
|
||||
// placement
|
||||
tx = center_it ? 0 : x/2;
|
||||
ty = center_it ? 0 : y/2;
|
||||
tz = center_it ? z/2 : z;
|
||||
|
||||
translate([tx, ty, tz - label_depth])
|
||||
rotate([0, 0, rotate_text ? 90 : 0])
|
||||
linear_extrude(height=label_depth + 0.02)
|
||||
text(
|
||||
txt,
|
||||
size=final_size,
|
||||
font=label_font,
|
||||
halign="center",
|
||||
valign="center"
|
||||
);
|
||||
}
|
||||
module place_top_labelOLD(txt, x, y, z, center_it=false) {
|
||||
tx = center_it ? 0 : x/2;
|
||||
ty = center_it ? 0 : y/2;
|
||||
tz = center_it ? z/2 : z;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue