Git Product home page Git Product logo

Comments (2)

jondavidjohn avatar jondavidjohn commented on September 18, 2024

Thanks for the report! Conceptually this makes sense since we are tinkering with the drawing dimensions behind the scenes. In reviewing the documentation for isPointInPath, it looks like it can sometimes take arguments that are not just x and y. Do you happen to be using any of those arguments? fillRule or path?

This fix might entail overriding isPointInPath and explicitly handling the argument cases with some type checking, etc... Because we only want to inflate the x / y arguments, not the possible Path2D or fillRule.

The quickest path to a fix would likely be writing a few simplified failing tests that emulate your use case here.

from hidpi-canvas-polyfill.

tsofiyai avatar tsofiyai commented on September 18, 2024

Hi,

Thank you for your quick reply.

As for your question about the fillRule or path arguments, I did not use any of them.

Unfortunately, I have never written tests and don't know how to use them.

Here is a simplified example of what I'm trying to achieve (I use d3.js):

HTML:

<canvas id="test-canvas" width="310" height="310" style="background-color:transparent; border-radius:50%; border:1px solid orange;" />

JS:

    var testCanvas = d3.select("#test-canvas"),
    testCtx = testCanvas.node().getContext("2d");

    testCanvas.on("touchstart", function (e) {
        var mouse = d3.mouse(this);
        var isInPath = false,
            isInPath2 = false,
            mouseX = mouse[0],
            mouseY = mouse[1];
        var cx = testCanvas.node().getBoundingClientRect().width / 2;
        var cy = testCanvas.node().getBoundingClientRect().height / 2;
        testCtx.strokeStyle = "black";

        //outer circle
        testCtx.save();
        testCtx.translate(cx, cy);
        testCtx.beginPath();
        testCtx.arc(0, 0, 145, 0, Math.PI * 2, false);
        testCtx.stroke();
        testCtx.closePath();
        testCtx.restore();
        isInPath = testCtx.isPointInPath(mouseX, mouseY);

        //inner circle
        testCtx.save();
        testCtx.translate(cx, cy);
        testCtx.beginPath();
        testCtx.arc(0, 0, 75, 0, Math.PI * 2, false);
        testCtx.stroke();
        testCtx.closePath();
        testCtx.restore();
        isInPath2 = testCtx.isPointInPath(mouseX, mouseY);

       if(isInPath && !isInPath2){
            d3.event.preventDefault();
            console.log('should rotate');
        } 
    });

Thank you for your help

from hidpi-canvas-polyfill.

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.