Search code examples
javascriptreact-konvakonva

Snapping Issue For Regular Polygons in React Konva


This is the bounding box of a custom shape Bounding box of regular polygon with 3 sides Here the bounding box of the triangle is not getting attached correctly to the ends of the triangle ,same is the case for all regular polygons.So when we are trying to snap shapes ,shapes are not getting snapped to the ends of regular polygons correctly due to the above mentioned issue. Here is the link:- https://codesandbox.io/s/react-konva-basic-demo-btuum?file=/index.js


Solution

  • Update:

    The issue was solved from Konva side. Updated and working demo: https://codesandbox.io/s/react-konva-transformer-on-polygon-kodm7

    Old answer:

    Konva calculating the bounding box for regular polygon approximately. Konva just rounds that regular polygon into a circle with the same radius.

    As the solution just use Konva.Line or Konva.Path for drawing regular polygons.