Comments (5)
标准的 canvas 的 api 下没有这个接口,当然这个方法的本质是重新绘制一遍,性能开销也比数学运算要差。
http://www.w3school.com.cn/tags/html_ref_canvas.asp
from g.
https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/isPointInStroke
这个浏]览器兼容性在最下面,基本都支持了 @dxq613
为什么isPointInPath这个用了原生的实现?
from g.
isPointInPath 的性能很差,这个方法需要把图形重新绘制一遍,如果图形的量非常大的时候开销非常大。所以大多数图形的计算都是数学计算,只有 path 才使用了 isPointInPath,这个也是在包围盒筛选后才调用的,后续可以测试一下数学运算和isPointInStroke 在大量图形(1W)下的性能对比。
from g.
@dxq613 多谢 找到了个https://jsperf.com/ispointinpath-boundary-test-speed
from g.
@CraigZeng 实际项目中 isPointInPath 的性能更差,这个示例中绘制和拾取一起处理了,但是在真正的项目中还有一系列层级问题,包括矩阵之类的。之前尝试过增加一个缓冲 canvas 作为拾取性能确实能够到达 O(1)但是绘制开销会加倍,特别在高交互、高动画的场景下,得不偿失。
拾取和绘制的优化没有极限,后面还会不断进行,欢迎提 MR
from g.
Related Issues (20)
- 我在electron项目中使用官方示例代码来尝试使用webgpu,求助 HOT 3
- [g-plugin-device-render] 超出一定数目的图形未被渲染出来
- [react-g] 支持 createRoot 以及 render
- insertBefore 插入的位置不对 HOT 1
- 求助:文本渐变色无法起作用 HOT 1
- 关于group里面事件的疑惑,不知道是不是bug HOT 3
- [g] Image 支持获知何时图片加载完成 HOT 1
- [g-svg] 关闭 CSS 解析后生成的 SVG 结构不正常
- [g-plugin-device-renderer] Path 渲染有误 HOT 1
- [g-plugin-device-renderer] WebGPU 不支持 divisor
- [g] timing 对象上 easingFunction 类型报错 HOT 1
- [g] 多个画布下可交互 HTML 造成页面卡死
- How to cut a hole in a shape or closed path using antvis/g.
- [g-canvas] stroke 为空字符串时计算包围盒有误
- [g]使用antv/g的动画会造成内存泄露 HOT 8
- [g] 动效使用cubic-bezier效果严重不符 HOT 1
- [g] Path 修改 transform 有误 HOT 6
- WebGPU demo报错 HOT 1
- [g]即使动画都停掉,requestAnimationFrame的调用不会停止 HOT 2
- [g-webgl] emoji 无法渲染
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from g.