This project is part of the @thi.ng/umbrella monorepo.
2D line clipping (Liang-Barsky).
Current implementation is based on toxiclibs (Java) and Clojure version of thi.ng/geom.
This package has been extracted from the former (now obsolete) @thi.ng/geom-clip package.
STABLE - used in production
yarn add @thi.ng/geom-clip-line
Package sizes (gzipped): ESM: 0.3KB / CJS: 0.3KB / UMD: 0.4KB
liangBarsky2
liangBarksy2Raw
import { liangBarsky2 } from "@thi.ng/geom-clip-line";
liangBarsky2(
// line end points
[-10, -20], [30, 400],
// min/max clip rect
[0, 0], [100, 200]
)
// [ [ 0, 85 ], [ 10.952380952380953, 200 ], 0.25, 0.5238095238095238 ]
// returns undefined if line is completely outside the clip rect
liangBarsky2(
// line end points
[-10, -20], [-30, 400],
// min/max bbox
[0, 0], [100, 200]
)
// undefined
Karsten Schmidt
© 2013 - 2020 Karsten Schmidt // Apache Software License 2.0