mirror of
https://github.com/JustinSDK/dotSCAD.git
synced 2025-08-29 01:11:30 +02:00
refactor
This commit is contained in:
8
src/__private__/__in_line.scad
Normal file
8
src/__private__/__in_line.scad
Normal file
@@ -0,0 +1,8 @@
|
||||
function __in_line(line_pts, pt, epsilon = 0.0001) =
|
||||
let(
|
||||
pts = len(line_pts[0]) == 2 ? [for(pt = line_pts) __to3d(pt)] : line_pts,
|
||||
pt3d = len(pt) == 2 ? __to3d(pt) : pt,
|
||||
v1 = pts[0] - pt3d,
|
||||
v2 = pts[1] - pt3d
|
||||
)
|
||||
(norm(cross(v1, v2)) < epsilon) && ((v1 * v2) <= epsilon);
|
@@ -1,6 +0,0 @@
|
||||
function __in_line2d(line_pts, pt, epsilon = 0.0001) =
|
||||
let(
|
||||
v1 = line_pts[0] - pt,
|
||||
v2 = line_pts[1] - pt
|
||||
)
|
||||
(norm(cross(v1, v2)) < epsilon) && ((v1 * v2) <= epsilon);
|
@@ -1,16 +1,12 @@
|
||||
include <__private__/__to3d.scad>;
|
||||
include <__private__/__in_line2d.scad>;
|
||||
include <__private__/__in_line.scad>;
|
||||
|
||||
function _in_polyline_sub(pts, pt, epsilon, iend, i = 0) =
|
||||
i == iend ? false : (
|
||||
__in_line2d([pts[i], pts[i + 1]], pt, epsilon) ? true :
|
||||
__in_line([pts[i], pts[i + 1]], pt, epsilon) ? true :
|
||||
_in_polyline_sub(pts, pt, epsilon, iend, i + 1)
|
||||
);
|
||||
|
||||
function in_polyline(line_pts, pt, epsilon = 0.0001) =
|
||||
let(
|
||||
pts = len(line_pts[0]) == 2 ? [for(pt = line_pts) __to3d(pt)] : line_pts,
|
||||
pt3d = len(pt) == 2 ? __to3d(pt) : pt
|
||||
)
|
||||
_in_polyline_sub(pts, pt3d, epsilon, len(pts) - 1);
|
||||
_in_polyline_sub(line_pts, pt, epsilon, len(pts) - 1);
|
||||
|
Reference in New Issue
Block a user