Comments (6)
@dwelle I've published support for fixedDecimalPlaceDigits
in canvas as well in v4.4.4
. (#192) So you can set this property to 0
when drawing any shape. The shape gets generated with floating points. But when roughjs draws the shape, it rounds the value before drawing.
rc.rectangle(10, 10, 80, 80, {
fixedDecimalPlaceDigits: 0
});
Keep in mind this may not solve all your problems though. Internally it's bound to use floating points when you zoom or when using screens with higher resolution. Also I think excalidraw also does canvas copy where it sores a shape in another canvas and then copies from that canvas. Doing that when zoomed in, you may get floating point issues.
Hope this fix helps though
from rough.
@dwelle Does this bug affect only SVG?
from rough.
It actually affects only drawing onto Canvas. But I understand you're first generating SVG shapes before drawing them onto canvas? (I haven't checked).
Be it as it may, if I generate to SVG & then manually draw that SVG onto canvas, it's affected too. You can check here: https://codesandbox.io/s/sweet-mcnulty-w7zbs?file=/src/index.js
One fix (for our use case) is to either disable CanvasRenderingContext2D.lineCap = "round"
(which we don't want to do), or rounding all the numbers in Drawable.sets[].ops[].data
.
from rough.
I noticed there's opts.fixedDecimalPlaceDigits
for SVGs — can we expose that for canvas-SVG rendering as well? It can be accomplished in userland, but would be faster & simpler if it's supported natively.
The only problem is 1) accuracy and 2) effectiveness. From testing around (1), we need to retain as least 2 decimal places otherwise the output is changed noticeably. But 2 decimal places doesn't solve the issue completely (2) — from testing it still happens in around 1/500 cases.
from rough.
But I understand you're first generating SVG shapes before drawing them onto canvas?
No roughjs does not do that. It draws directly to canvas using Canvas api. Unless you give svg to Rough to draw.
You can definitely do fixedDecimalPlaceDigits
for canvas as well. Let me double check if it works as intended
from rough.
Thanks! excalidraw/excalidraw#4200
Strange thing is today I'm seeing minimal difference between full decimal and 0 decimal render outputs. Whereas yesterday the difference between 2 decimals and 1 decimal renders were striking. Also 2 decimals were enough to fix the render issues, whereas today I need to strip all the decimals. Can't repro anymore — unclear what I was doing differently (I've lost the diff).
from rough.
Related Issues (20)
- Solid fill goes out of bounds for arcs larger than 180 degrees HOT 4
- "Dots" fill looks weird when units are scaled up HOT 6
- Is there a way to use other attributes of the the SVG rectangle, such as "rx?" HOT 4
- 0-roughness ellipse not closed in specific cases HOT 3
- Ellipse not completely filled HOT 1
- Feature Request HOT 3
- mermaid language to rough HOT 2
- support inside/outside strokes
- Scanline hachutre lines drawing outside polygon for certain angles HOT 1
- Roughjs not running on Typescript files
- Compatibility roughs.js - gsap for animation HOT 1
- Interoperability with Pencil HOT 2
- Ability to pass fill rule through options HOT 2
- Dot filling is not constant with fixed seed
- Is this project abandoned?
- Any examples of this used in React Typescript? HOT 1
- Hachure fill is randomly missing for certain fractional hachureGap values HOT 2
- how to stroke with gradient?
- Interactive code examples
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 rough.