zoukankan      html  css  js  c++  java
  • xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

    svg rect to polygon points & points order bug

    https://codepen.io/xgqfrms/pen/vYOWjYr?editors=1000

    points 数据类型转换 bug, string + string !== number + number

    https://codepen.io/xgqfrms/pen/vYOWjYr?editors=1000

    error

      const x = rect.getAttribute('x');
      const y = rect.getAttribute('y');
      const width = rect.getAttribute('width');
      const height = rect.getAttribute('height');
      const points = [];
      points.push(pointGenerator(x, y));
      points.push(pointGenerator((x + width), y));
      points.push(pointGenerator((x + width), (y + height)));
      points.push(pointGenerator(x, (y + height)));
    
    

    OK

      const x = +rect.getAttribute('x');
      const y = +rect.getAttribute('y');
      const width = +rect.getAttribute('width');
      const height = +rect.getAttribute('height');
      const points = [];
      points.push(pointGenerator(x, y));
      points.push(pointGenerator((x + width), y));
      points.push(pointGenerator((x + width), (y + height)));
      points.push(pointGenerator(x, (y + height)));
    
    

    object map to array, order change bug

    bug

    
    const pointGenerator = (x, y) => {
      // return [
      //   x,
      //   y,
      // ];
      return {
        x,
        y,
      };
    }
    
    
      // const points_str = points.flat(2).join(` `);
      const points_str = points.map(({x, y}) => [x, y]).flat(2).join(` `);
    

    ok

    
    
    const pointGenerator = (x, y) => {
      return [
        x,
        y,
      ];
      // return {
      //   x,
      //   y,
      // };
    }
    
      const points_str = points.flat(2).join(` `);
      // const points_str = points.map(({x, y}) => [x, y]).flat(2).join(` `);
    
    

  • 相关阅读:
    二分图的最大匹配
    染色法判定二分图
    kruskal求最小生成树
    prim算法求最小生成树
    floyd
    spfa算法
    bellman_ford
    Dijkstra
    文件操作_1-18 选择题
    会话控制_2-5 编程练习
  • 原文地址:https://www.cnblogs.com/xgqfrms/p/12440243.html
Copyright © 2011-2022 走看看