mirror of
https://github.com/BelfrySCAD/BOSL2.git
synced 2024-12-28 15:59:45 +00:00
Added triplet() and triplet_wrap().
This commit is contained in:
parent
02da52c097
commit
d069cf39ce
1 changed files with 25 additions and 3 deletions
28
arrays.scad
28
arrays.scad
|
@ -433,7 +433,7 @@ function subindex(v, idx) = [
|
|||
// Usage:
|
||||
// pair(v)
|
||||
// Description:
|
||||
// Takes a list, and returns a list of adjacent pairs from it, with the last item paired with the first at the end.
|
||||
// Takes a list, and returns a list of adjacent pairs from it.
|
||||
// Example:
|
||||
// l = ["A","B","C",D"];
|
||||
// echo([for (p=pair(l)) str(p.y,p.x)]); // Outputs: ["BA", "CB", "DC"]
|
||||
|
@ -444,13 +444,35 @@ function pair(v) = [for (i=[0:1:len(v)-2]) [v[i],v[i+1]]];
|
|||
// Usage:
|
||||
// pair_wrap(v)
|
||||
// Description:
|
||||
// Takes a list, and returns a list of adjacent pairs from it, with the last item paired with the first at the end.
|
||||
// Takes a list, and returns a list of adjacent pairss from it, wrapping around from the end to the start of the list.
|
||||
// Example:
|
||||
// l = ["A","B","C",D"];
|
||||
// l = ["A","B","C","D"];
|
||||
// echo([for (p=pair_wrap(l)) str(p.y,p.x)]); // Outputs: ["BA", "CB", "DC", "AD"]
|
||||
function pair_wrap(v) = [for (i=[0:1:len(v)-1]) [v[i],v[(i+1)%len(v)]]];
|
||||
|
||||
|
||||
// Function: triplet()
|
||||
// Usage:
|
||||
// triplet(v)
|
||||
// Description:
|
||||
// Takes a list, and returns a list of adjacent triplets from it.
|
||||
// Example:
|
||||
// l = ["A","B","C","D","E"];
|
||||
// echo([for (p=triplet(l)) str(p.z,p.y,p.x)]); // Outputs: ["CBA", "DCB", "EDC"]
|
||||
function triplet(v) = [for (i=[0:1:len(v)-3]) [v[i],v[i+1],v[i+2]]];
|
||||
|
||||
|
||||
// Function: triplet_wrap()
|
||||
// Usage:
|
||||
// triplet_wrap(v)
|
||||
// Description:
|
||||
// Takes a list, and returns a list of adjacent triplets from it, wrapping around from the end to the start of the list.
|
||||
// Example:
|
||||
// l = ["A","B","C","D"];
|
||||
// echo([for (p=triplet_wrap(l)) str(p.z,p.y,p.x)]); // Outputs: ["CBA", "DCB", "ADC", "BAD"]
|
||||
function triplet_wrap(v) = [for (i=[0:1:len(v)-1]) [v[i],v[(i+1)%len(v)],v[(i+2)%len(v)]]];
|
||||
|
||||
|
||||
// Function: zip()
|
||||
// Usage:
|
||||
// zip(v1, v2, v3, [fit], [fill]);
|
||||
|
|
Loading…
Reference in a new issue