Coder Social home page Coder Social logo

polygon-centroid's Issues

rewrite index.js for TS

thx for your job :o
this package is very usefull for me but no accepted in ts project

here my updates:

interface Point {
  x: number;
  y: number;
}
type Callback = (p1: Point, p2: Point, i: number, array: Point[]) => number;

const pairwiseSumReduce = (array: Point[], func: Callback, init = 0) => {
  const n = array.length;
  return array.reduce((acc, p, i) => {
    if (i + 1 >= n) {
      return acc;
    }
    return acc + func(p, array[i + 1], i, array);
  }, init);
};

const polygonCentroid = (points: Point[]) => {
  const area = pairwiseSumReduce(points, (p1, p2) => p1.x * p2.y - p1.y * p2.x) / 2;

  // Calculate the x coordinate of the centroid.
  const cx =
    pairwiseSumReduce(
      points,
      (p1, p2) => (p1.x + p2.x) * (p1.x * p2.y - p1.y * p2.x)
    ) /
    (6 * area);

  // Calculate the y coordinate of the centroid.
  const cy =
    pairwiseSumReduce(
      points,
      (p1, p2) => (p1.y + p2.y) * (p1.x * p2.y - p1.y * p2.x)
    ) /
    (6 * area);

  return { x: cx, y: cy };
};

export default polygonCentroid;

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Edited/Blocked

These updates have been manually edited so Renovate will no longer make changes. To discard all commits and start over, click on a checkbox.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • ava ^4.0.1
  • nyc ^15.1.0
  • node >=6.4.0
travis
.travis.yml
  • node 6.4

  • Check this box to trigger a request for Renovate to run again on this repository

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.