mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-04 22:07:44 +02:00
add has doc
This commit is contained in:
25
docs/lib2x-has.md
Normal file
25
docs/lib2x-has.md
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
# has
|
||||||
|
|
||||||
|
If `lt` contains `elem`, this function returns `true`. If you want to test elements repeatly, sorting `lt` first and setting `sorted` to `true` will be faster.
|
||||||
|
|
||||||
|
**Since:** 2.3
|
||||||
|
|
||||||
|
## Parameters
|
||||||
|
|
||||||
|
- `lt` : A list of vectors.
|
||||||
|
- `elem` : A vector.
|
||||||
|
- `sorted` : If `false`, use native `search`. If `true`, `lt` must be sorted by zyx (from the last idx to first) and `has` will use binary search internally.
|
||||||
|
|
||||||
|
## Examples
|
||||||
|
|
||||||
|
use <pixel/px_circle.scad>;
|
||||||
|
use <util/sort.scad>;
|
||||||
|
use <util/has.scad>;
|
||||||
|
|
||||||
|
pts = px_circle(10);
|
||||||
|
assert(has(pts, [2, -10]));
|
||||||
|
assert(!has(pts, [0, 0]));
|
||||||
|
|
||||||
|
sorted_pts = sort(sort(pts, by = "x"), by = "y");
|
||||||
|
assert(has(sorted_pts, [2, -10]));
|
||||||
|
assert(!has(sorted_pts, [0, 0]));
|
@@ -1,3 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* has.scad
|
||||||
|
*
|
||||||
|
* @copyright Justin Lin, 2020
|
||||||
|
* @license https://opensource.org/licenses/lgpl-3.0.html
|
||||||
|
*
|
||||||
|
* @see https://openhome.cc/eGossip/OpenSCAD/lib2x-has.html
|
||||||
|
*
|
||||||
|
**/
|
||||||
|
|
||||||
use <util/bsearch.scad>;
|
use <util/bsearch.scad>;
|
||||||
|
|
||||||
function has(lt, elem, sorted = false) =
|
function has(lt, elem, sorted = false) =
|
||||||
|
Reference in New Issue
Block a user