Giter VIP home page Giter VIP logo

Comments (6)

pshihn avatar pshihn commented on May 26, 2024 1

@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.

pshihn avatar pshihn commented on May 26, 2024

@dwelle Does this bug affect only SVG?

from rough.

dwelle avatar dwelle commented on May 26, 2024

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.

dwelle avatar dwelle commented on May 26, 2024

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.

pshihn avatar pshihn commented on May 26, 2024

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.

dwelle avatar dwelle commented on May 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.