npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@geeeger/viewbox-offset

v1.0.0

Published

计算svg path的offset值

Downloads

1

Readme

viewbox-offset

自用

产生原因

UI给的矢量图,导出时width height写死了,然后因为旋转了不同组,导致多余了很多冗余信息,并且自动伸缩不能,所以制作了这个沙雕工具.

适用范围

path元素的d属性值,只支持以三次贝塞尔画的曲线和直线,也就是M和C

计算内容

整个path距离画布的偏移值x和y

原理

收集各个点,计算三次贝塞尔曲线的顶点,入栈,然后寻找最小的x值和最小的y值作为offset值

公式依据

设 Bt 为要计算的贝塞尔曲线上的坐标,N 为控制点个数,P0,P1,P2..Pn 为贝塞尔曲线控制点的坐标,当 N 值不同时有如下计算公式:

如 N 为 3 表示贝塞尔曲线的控制点有 3 个点,这时 n 为 2 ,这三个点分别用 P0,P1,P2 表示。

  • N = 3: P = (1-t)^2P0 + 2(1-t)tP1 + t^2*P2
  • N = 4: P = (1-t)^3P0 + 3(1-t)^2tP1 + 3(1-t)t^2P2 + t^3*P3
  • N = 5: P = (1-t)^4P0 + 4(1-t)^3tP1 + 6(1-t)^2t^2P2 + 4*(1-t)t^3P3 + t^4*P4

版权声明:本文为CSDN博主「DuanJiaNing_」的原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/aimeimeits/article/details/72809382

简化公式

const t = .5;
const coefficient = Math.pow(t, 3);
const x = coefficient * (this.start.x + 3.0 * this.ctrl0.x + 3.0 * this.ctrl1.x + this.end.x);
const y = coefficient * (this.start.y + 3.0 * this.ctrl0.y + 3.0 * this.ctrl1.y + this.end.y);