From 9ed7a3ec48c0c66076b0f6066991076c944f6c8b Mon Sep 17 00:00:00 2001 From: Adrian Mariano Date: Wed, 11 Dec 2024 16:20:58 -0500 Subject: [PATCH] add highlight and highlight_this --- attachments.scad | 42 ++++++++++++++++++---------- color.scad | 73 +++++++++++++++++++++++++++++++++++++++++------- math.scad | 8 ++++++ 3 files changed, 99 insertions(+), 24 deletions(-) diff --git a/attachments.scad b/attachments.scad index 6c4173f..a31c8f3 100644 --- a/attachments.scad +++ b/attachments.scad @@ -43,6 +43,9 @@ $ghost_this=false; $ghost=false; $ghosting=false; // Ghosting is in effect, so don't apply it again +$highlight_this=false; +$highlight=false; + _ANCHOR_TYPES = ["intersect","hull"]; @@ -1154,8 +1157,8 @@ module tag_this(tag) // that don't use {{attachable()}} or built in modules such as // - `polygon()` // - `projection()` -// - `polyhedron()` (or use [`vnf_polyhedron()`](vnf.scad#vnf_polyhedron)) -// - `linear_extrude()` (or use [`linear_sweep()`](regions.scad#linear_sweep)) +// - `polyhedron()` (or use {{vnf_polyhedron()}}) +// - `linear_extrude()` (or use {{linear_sweep()}}) // - `rotate_extrude()` // - `surface()` // - `import()` @@ -3107,24 +3110,15 @@ module attachable( if (expose_tags || _is_shown()){ if (!keep_color) _color($color) - if (($ghost || $ghost_this) && !$ghosting) - %union(){ - $ghosting=true; - children(0); - } - else children(0); + _show_ghost() children(0); else { $save_color=undef; // Force color_this() color in effect to persist for the entire object - if (($ghost || $ghost_this) && !$ghosting) - %union(){ - $ghosting=true; - children(0); - } - else children(0); + _show_ghost() children(0); } } let( $ghost_this=false, + $highlight_this=false, $tag=default($save_tag,$tag), $save_tag=undef, $color=default($save_color,$color), @@ -3134,6 +3128,26 @@ module attachable( } } +module _show_highlight() +{ + if ($highlight || $highlight_this) + #children(); + else + children(); +} + + +module _show_ghost() +{ + if (($ghost || $ghost_this) && !$ghosting) + %union(){ + $ghosting=true; + _show_highlight()children(); + } + else _show_highlight()children(); +} + + // Function: reorient() // Synopsis: Calculates the transformation matrix needed to reorient an object. // SynTags: Trans, Path, VNF diff --git a/color.scad b/color.scad index d601e6f..4195c1b 100644 --- a/color.scad +++ b/color.scad @@ -161,21 +161,74 @@ module color_overlaps(color="red") { %children(); } -// Section: Setting Object Transparency +// Section: Setting Object Modifiers + + + + +// Module: highlight() +// Synopsis: Sets # modifier for attachable children and their descendents. +// SynTags: Trans +// Topics: Attachments, Modifiers +// See Also: highlight_this(), ghost(), ghost_this(), recolor(), color_this() +// Usage: +// highlight([highlight]) CHILDREN; +// Description: +// Sets the `#` modifier for the attachable children and their descendents until another {{highlight()}} or {{highlight_this()}}. +// By default, turns `#` on, which makes the children transparent pink and displays them even if they are subtracted from the model. +// Give the `false` parameter to disable the modifier and restore children to normal. +// Do not mix this with user supplied `#` modifiers anywhere in the geometry tree. +// Arguments: +// highlight = If true set the descendents to use `#`; if false, disable `#` for descendents. Default: true +// Example(3D): +// highlight() cuboid(10) +// highlight(false) attach(RIGHT,BOT)cuboid(5); +function highlight(highlight) = no_function("highlight"); +module highlight(highlight=true) +{ + $highlight=highlight; + children(); +} + + +// Module: highlight_this() +// Synopsis: Apply # modifier to children at a single level. +// SynTags: Trans +// Topics: Attachments, Modifiers +// See Also: highlight(), ghost(), ghost_this(), recolor(), color_this() +// Usage: +// highlight_this() CHILDREN; +// Description: +// Applies the `#` modifier to the children at a single level, reverting to the previous highlight state for further descendents. +// This works only with attachables and you cannot give the `#` operator anywhere in the geometry tree. +// Example(3D): +// highlight_this() +// cuboid(10) +// attach(TOP,BOT)cuboid(5); +function highlight_this() = no_function("highlight_this"); +module highlight_this() +{ + $highlight_this=true; + children(); +} + + + // Module: ghost() -// Synopsis: Sets transparency for attachable children and their descendents. +// Synopsis: Sets % modifier for attachable children and their descendents. // SynTags: Trans -// Topics: Attachments +// Topics: Attachments, Modifiers // See Also: ghost_this(), recolor(), color_this() // Usage: // ghost([ghost]) CHILDREN; // Description: -// Sets the transparency for the attachable children and their descendents until another {{ghost()}} or {{ghost_this()}}. -// By default, turns transparency on. Give the `false` parameter to disable transparency. -// Do not mix this with user supplied `%` operators anywhere in the geometry tree. +// Sets the `%` modifier for the attachable children and their descendents until another {{ghost()}} or {{ghost_this()}}. +// By default, turns `%` on, which makes the children gray and also removes them from interaction with the model. +// Give the `false` parameter to disable the modifier and restore children to normal. +// Do not mix this with user supplied `%` modifiers anywhere in the geometry tree. // Arguments: -// ghost = If true set the descendents to be transparent; if false, disable transparency. Default: true +// ghost = If true set the descendents to use `%`; if false, disable `%` for descendents. Default: true // Example(3D): // ghost() cuboid(10) // ghost(false) cuboid(5); @@ -188,14 +241,14 @@ module ghost(ghost=true) // Module: ghost_this() -// Synopsis: Makes the children at a single level transparent. +// Synopsis: Apply % modifier to children at a single level. // SynTags: Trans -// Topics: Attachments +// Topics: Attachments, Modifiers // See Also: ghost(), recolor(), color_this() // Usage: // ghost_this() CHILDREN; // Description: -// Makes the children transparent for one level, reverting to the previous transparency state for further descendents. +// Applies the `%` modifier to the children at a single level, reverting to the previous ghost state for further descendents. // This works only with attachables and you cannot give the `%` operator anywhere in the geometry tree. // Example(3D): // ghost_this() cuboid(10) diff --git a/math.scad b/math.scad index 0058d02..272738a 100644 --- a/math.scad +++ b/math.scad @@ -1609,6 +1609,14 @@ function real_roots(p,eps=undef,tol=1e-14) = // x0 = endpoint of interval to search for root // x1 = second endpoint of interval to search for root // tol = tolerance for solution. Default: 1e-15 +// Example(2D): Solve x*sin(x)=4 +// f = function (x) x*sin(x)-4; +// root=root_find(f, 0,25); // root = 15.2284 +// // Graphical verification +// stroke([for(x=[0:25]) [x,f(x)]],width=.2); +// color("red")move([root,f(root)]) +// circle(r=.25,$fn=16); + // The algorithm is based on Brent's method and is a combination of // bisection and inverse quadratic approximation, where bisection occurs