'use strict';

import normalizeCoords from './normalize-coords';

export default function centerCoords(pairs, opts) {
  var opts = opts || {};
  var xMin, xMax, yMin, yMax;
  var xCoords = $.map(pairs, function(i) { return normalizeCoords(i)[0] });
  var yCoords = $.map(pairs, function(i) { return normalizeCoords(i)[1] });
  var xCenter, yCenter, center;

  xMin = Math.min.apply(Math, xCoords);
  yMin = Math.min.apply(Math, yCoords);
  xMax = Math.max.apply(Math, xCoords);
  yMax = Math.max.apply(Math, yCoords);

  xCenter = xMin + ((xMax - xMin) / 2);
  yCenter = yMin + ((yMax - yMin) / 2);
  center = [xCenter, yCenter];

  if (opts.debug) {
    console.log('pairs: ' + pairs);
    console.log('length: ' + pairs.length);
    console.log('first pair: ' + normalizeCoords(pairs[0]));
    console.log('x_coords: ' + x_coords);
    console.log('x_min: ' + x_min);
    console.log('x_max: ' + x_max);
    console.log('y_coords: ' + y_coords);
    console.log('y_max: ' + y_max);
    console.log('center: ' + center);
  }

  return center;
}

@@ -803,18 +803,17 @@
 e.log('x
-_c
+C
 oords: '
@@ -816,18 +816,17 @@
 s: ' + x
-_c
+C
 oords);%0A
@@ -843,18 +843,17 @@
 e.log('x
-_m
+M
 in: ' + 
@@ -853,18 +853,17 @@
 n: ' + x
-_m
+M
 in);%0A   
@@ -877,18 +877,17 @@
 e.log('x
-_m
+M
 ax: ' + 
@@ -887,18 +887,17 @@
 x: ' + x
-_m
+M
 ax);%0A   
@@ -911,18 +911,17 @@
 e.log('y
-_c
+C
 oords: '
@@ -928,10 +928,9 @@
  + y
-_c
+C
 oord
@@ -951,18 +951,17 @@
 e.log('y
-_m
+M
 ax: ' + 
@@ -965,10 +965,9 @@
  + y
-_m
+M
 ax);

fix debug vars