mirror of
https://github.com/revarbat/BOSL2.git
synced 2025-01-16 13:50:23 +01:00
Merge pull request #672 from adrianVmariano/master
builtins "use" fails if BOSL2 installed in a different directory add center option to path_text
This commit is contained in:
commit
724e49385b
46
regions.scad
46
regions.scad
@ -302,14 +302,8 @@ function _path_path_closest_vertices(path1,path2) =
|
||||
i2 = dists[i1][0]
|
||||
) [dists[i1][1], i1, i2];
|
||||
|
||||
function _join_paths_at_vertices(path1,path2,seg1,seg2) =
|
||||
let(
|
||||
path1 = close_path(clockwise_polygon(polygon_shift(path1, seg1))),
|
||||
path2 = close_path(ccw_polygon(polygon_shift(path2, seg2)))
|
||||
) cleanup_path(deduplicate([each path1, each path2]));
|
||||
|
||||
|
||||
function new_join_paths_at_vertices(path1,path2,v1,v2) =
|
||||
function _join_paths_at_vertices(path1,path2,v1,v2) =
|
||||
let(
|
||||
repeat_start = !approx(path1[v1],path2[v2]),
|
||||
path1 = clockwise_polygon(polygon_shift(path1,v1)),
|
||||
@ -325,7 +319,7 @@ function new_join_paths_at_vertices(path1,path2,v1,v2) =
|
||||
|
||||
// Given a region that is connected and has its outer border in region[0],
|
||||
// produces a polygon with the same points that has overlapping connected paths
|
||||
// to join internal holes to the outer border.
|
||||
// to join internal holes to the outer border. Output is a single path.
|
||||
function _cleave_connected_region(region) =
|
||||
len(region)==0? [] :
|
||||
len(region)<=1? clockwise_polygon(region[0]) :
|
||||
@ -335,36 +329,7 @@ function _cleave_connected_region(region) =
|
||||
_path_path_closest_vertices(region[0],region[i])
|
||||
],
|
||||
idxi = min_index(subindex(dists,0)),
|
||||
outline = _join_paths_at_vertices(
|
||||
region[0], region[idxi+1],
|
||||
dists[idxi][1], dists[idxi][2]
|
||||
)
|
||||
)
|
||||
len(region)==2? clockwise_polygon(outline) : // We joined 2 regions, so we're done
|
||||
let(
|
||||
newregion = [
|
||||
outline,
|
||||
for (i=idx(region))
|
||||
if (i>0 && i!=idxi+1)
|
||||
region[i]
|
||||
]
|
||||
)
|
||||
assert(len(newregion)<len(region))
|
||||
_cleave_connected_region(newregion);
|
||||
|
||||
|
||||
|
||||
|
||||
function new_cleave_connected_region(region) =
|
||||
len(region)==0? [] :
|
||||
len(region)<=1? clockwise_polygon(region[0]) :
|
||||
let(
|
||||
dists = [
|
||||
for (i=[1:1:len(region)-1])
|
||||
_path_path_closest_vertices(region[0],region[i])
|
||||
],
|
||||
idxi = min_index(subindex(dists,0)),
|
||||
newoline = new_join_paths_at_vertices(
|
||||
newoline = _join_paths_at_vertices(
|
||||
region[0], region[idxi+1],
|
||||
dists[idxi][1], dists[idxi][2]
|
||||
)
|
||||
@ -378,8 +343,9 @@ function new_cleave_connected_region(region) =
|
||||
]
|
||||
)
|
||||
assert(len(orgn)<len(region))
|
||||
new_cleave_connected_region(orgn);
|
||||
|
||||
_cleave_connected_region(orgn);
|
||||
|
||||
|
||||
|
||||
// Function: region_faces()
|
||||
// Usage:
|
||||
|
@ -14,7 +14,7 @@
|
||||
// include <BOSL2/std.scad>
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
use <BOSL2/builtins.scad>
|
||||
use <builtins.scad>
|
||||
|
||||
|
||||
// Section: 2D Primitives
|
||||
|
@ -2112,6 +2112,7 @@ function _cut_interp(pathcut, path, data) =
|
||||
// font = font to use
|
||||
// ---
|
||||
// lettersize = scalar or array giving size of letters
|
||||
// center = center text on the path instead of starting at the first point. Default: false
|
||||
// offset = distance to shift letters "up" (towards the reader). Not allowed for 2D path. Default: 0
|
||||
// normal = direction or list of directions pointing towards the reader of the text. Not allowed for 2D path.
|
||||
// top = direction or list of directions pointing toward the top of the text
|
||||
@ -2173,7 +2174,7 @@ function _cut_interp(pathcut, path, data) =
|
||||
// path = zrot(-120,p=concat(arc(100, r=25, angle=[0,90]), back(50,p=arc(100, r=25, angle=[268, 180]))));
|
||||
// color("red")stroke(path,width=.2);
|
||||
// path_text(path, "A shorter example", size=5, lettersize=5/1.2, font="Courier");
|
||||
module path_text(path, text, font, size, thickness, lettersize, offset=0, reverse=false, normal, top, textmetrics=false)
|
||||
module path_text(path, text, font, size, thickness, lettersize, offset=0, reverse=false, normal, top, center=false, textmetrics=false)
|
||||
{
|
||||
dummy2=assert(is_path(path,[2,3]),"Must supply a 2d or 3d path")
|
||||
assert(num_defined([normal,top])<=1, "Cannot define both \"normal\" and \"top\"");
|
||||
@ -2200,9 +2201,12 @@ module path_text(path, text, font, size, thickness, lettersize, offset=0, revers
|
||||
: textmetrics ? [for(letter=text) let(t=textmetrics(letter, font=font, size=size)) t.advance[0]]
|
||||
: assert(false, "textmetrics disabled: Must specify letter size");
|
||||
|
||||
dummy1 = assert(sum(lsize)<=path_length(path),"Path is too short for the text");
|
||||
textlength = sum(lsize);
|
||||
dummy1 = assert(textlength<=path_length(path),"Path is too short for the text");
|
||||
|
||||
start = center ? (path_length(path) - textlength)/2 : 0;
|
||||
|
||||
pts = _path_cut_points(path, add_scalar([0, each cumsum(lsize)],lsize[0]/2), direction=true);
|
||||
pts = _path_cut_points(path, add_scalar([0, each cumsum(lsize)],start+lsize[0]/2), direction=true);
|
||||
|
||||
usernorm = is_def(normal);
|
||||
usetop = is_def(top);
|
||||
|
Loading…
x
Reference in New Issue
Block a user