Security News
The Push to Ban Ransom Payments Is Gaining Momentum
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
@jiaminghi/bezier-curve
Advanced tools
Readme
将贝塞尔曲线抽象成由 N 个点构成的折线
获取贝塞尔曲线的长度
将由 N 个点构成的折线抽象成光滑的贝塞尔曲线
$ npm install @jiaminghi/bezier-curve
import bezierCurve from '@jiaminghi/bezier-curve'
// do something
<!--调试版-->
<script src="https://unpkg.com/@jiaminghi/color/dist/index.js"></script>
<!--压缩版-->
<script src="https://unpkg.com/@jiaminghi/color/dist/index.min.js"></script>
<script>
const { bezierCurveToPolyline, getBezierCurveLength, polylineToBezierCurve } = window.BezierCurve
// do something
</script>
type Point = [number, number]
/**
* [控制点1,控制点2,结束点]
*/
type BezierCurveSegment = [Point, Point, Point]
/**
* [起始点, 贝塞尔曲线段, ...]
* 下一段贝塞尔曲线的起始点是上一段的结束点
*/
type BezierCurve = [Point, BezierCurveSegment, ...BezierCurveSegment[]]
const bezierCurve: BezierCurve = [
[20, 20],
[
[100, 20],
[100, 80],
[180, 80],
],
]
bezierCurve in SVG
/**
* @description 将贝塞尔曲线转换为折线
* @param {BezierCurve} bezierCurve 贝塞尔曲线
* @param {number} precision 需要的计算精度
* @param {number} recursiveCount 迭代次数
* @return {Point[]} 转换的折线
*/
type bezierCurveToPolyline = (
bezierCurve: BezierCurve,
precision = 5,
resursiveCount = 0
) => Point[]
const polyline = bezierCurveToPolyline(bezierCurve)
// polyline = [
// [[20,20],
// [25.998752507628243,20.11632023466343],[31.698106846035834,20.457189096242345],
// [37.11424670004552,21.010468821119716],[42.263355754480024,21.764021645678454],
// ...]
polyline in SVG
/**
* @description 计算贝塞尔曲线的长度
* @param {BezierCurve} bezierCurve 贝塞尔曲线
* @param {number} precision 需要的计算精度
* @param {number} recursiveCount 迭代次数
* @return {number} 转换的折线
*/
type getBezierCurveLength = (bezierCurve: BezierCurve, precision = 5, resursiveCount = 0) => Point[]
// 通常情况下,默认精度已经能够达到较好的视觉效果。
const length = getBezierCurveLength(bezierCurve)
const polyline: Point[] = [
[20, 70],
[50, 30],
[100, 70],
[150, 30],
[180, 70],
]
polyline in SVG
/**
* @description 将折线转换为贝塞尔曲线
* @param {Point[]} polyline 折线
* @param {boolean} close 转换的贝塞尔曲线是否需要闭合
* @param {number} offsetA 光滑程度
* @param {number} offsetB 光滑程度
* @return {BezierCurve} 转换的贝塞尔曲线
*/
type polylineToBezierCurve = (
polyline: Point[],
close = false,
offsetA = 0.25,
offsetB = 0.25
) => BezierCurve
const bezierCurve = polylineToBezierCurve(polyline)
// bezierCurve = [
// [
// [20,70],
// [[27.5,60],[30,30],[50,30]],
// [[70,30],[75,70],[100,70]],
// [[125,70],[130,30],[150,30]],
// [[170,30],[172.5,60],[180,70]]]
//]
const closedBezierCurve = polylineToBezierCurve(polyline, true)
// closedBezerCurve = [
// [20,70],
// [[-12.5,60],[30,30],[50,30]],
// [[70,30],[75,70],[100,70]],
// [[125,70],[130,30],[150,30]],
// [[170,30],[212.5,60],[180,70]],
// [[147.5,80],[52.5,80],[20,70]]
// ]
bezierCurve in SVG
closedBezierCurve in SVG
FAQs
Bezier curve extension
We found that @jiaminghi/bezier-curve demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ransomware costs victims an estimated $30 billion per year and has gotten so out of control that global support for banning payments is gaining momentum.
Application Security
New SEC disclosure rules aim to enforce timely cyber incident reporting, but fear of job loss and inadequate resources lead to significant underreporting.
Security News
The Python Software Foundation has secured a 5-year sponsorship from Fastly that supports PSF's activities and events, most notably the security and reliability of the Python Package Index (PyPI).