{"size": 1811, "ext": "js", "max_stars_repo_path": "solutions/javascript/2kyu/voronoi-cells.js", "max_stars_repo_name": "alaindet/codewars-solutions", "max_stars_repo_stars_event_min_datetime": "2018-09-01T22:03:19.000Z", "max_stars_repo_stars_event_max_datetime": "2018-09-01T22:03:19.000Z", "max_issues_repo_path": "solutions/javascript/2kyu/voronoi-cells.js", "max_issues_repo_name": "alaindet/codewars-solutions", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "solutions/javascript/2kyu/voronoi-cells.js", "max_forks_repo_name": "alaindet/codewars-solutions", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 19.6847826087, "max_line_length": 79, "alphanum_fraction": 0.5190502485}
// ATTEMPT
// https://www.codewars.com/kata/58bf8041aa4014a09e000013/train/javascript
// https://en.wikipedia.org/wiki/Voronoi_diagram

// Aux
class Point {
  constructor(x, y) {
    this.x = x;
    this.y = y;
  }
}

class Line {
  constructor (m, q) {
    this.m = m;
    this.q = q;
  }
}

const pointMiddle = (a, b) => new Point(
  a.x + (a.x - b.x) / 2,
  a.y + (a.y - b.y) / 2
);

const pointCrossing = (a, b) => {
  const x = (b.q - a.q) / (a.m - b.m);
  return new Line(x, a.m * x + a.q);
};

const lineBetweenPoints = (a, b) => new Line(
  1 / (b.x - a.x),
  a.y / b.y - a.y - a.x / (b.x - a.x)
);

const linePerpendicularTo = (line) => -1 / line.m;
const lineThroughPoint = (m, p) => new Line(m, p.y - m * p.x);

const middleBisectLine = (a, b) => {
  const line = lineBetweenPoints(a, b);
  const perpendicularCoeff = linePerpendicularTo(line);
  const midpoint = pointMiddle(a, b);
  const bisect = lineThroughPoint(perpendicularCoeff, midpoint);
  return bisect;
};


const voronoi_areas = (points) => {
  return false;
};

// TESTS ----------------------------------------------------------------------

const FUNC = voronoi_areas;

const tests = [

  // Test #1
  {
    given: [
      new Point(0.0, 0.0),
      new Point(2.0, 0.0),
      new Point(-2.0, 0.0),
      new Point(0.0, 2.0),
      new Point(0.0, -2.0),
    ],
    expected: [4.0, -1, -1, -1, -1],
  },

  // Test #2
  {
    given: [
      new Point(2.0, 1.0),
      new Point(2.0, -1.0),
      new Point(4.4, 2.2),
      new Point(4.4, -2.2),
      new Point(-0.4, 2.2),
      new Point(-0.4, -2.2),
    ],
    expected: [8, 8, -1, -1, -1, -1],
  }

];

for (const test of tests) {
  const outcome = voronoi_areas(test.given) === test.expected;
  if (outcome) {
    console.log('PASSED');
  } else {
    console.log('FAILED');
  }
}
