export function createPoint(options = {}) {
  const { lng, lat } = options
  return new CLatLng(lng, lat)
}

export function createIcon(options = {}) {
  const { url, size, anchor, popupAnchor } = options
  return new CIcon({
    iconUrl: url,
    iconSize: size,
    iconAncor: anchor,
    popupAnchor: popupAnchor
  })
}

export function intersectBox(bounds1, bounds2) {
  if (bounds1.intersects(bounds2) === false) return null
  if (bounds1.equals(bounds2) === true) return bounds1
  if (bounds1.contains(bounds2) === true) return bounds2
  if (bounds2.contains(bounds1) === true) return bounds1
  var xMin = Math.min(bounds1.getSouthWest().lng, bounds1.getSouthWest().lng)
  var yMin = Math.min(bounds1.getSouthWest().lat, bounds1.getSouthWest().lat)
  var xMax = Math.min(bounds1.getNorthEast().lng, bounds1.getNorthEast().lng)
  var yMax = Math.min(bounds1.getNorthEast().lat, bounds1.getNorthEast().lat)

  var maxbox = new CLatLngBounds(new CLatLng(yMin, xMin), new CLatLng(yMax, xMax))
  var x = (Math.abs(bounds1.getSouthWest().lng - maxbox.getNorthEast().lng) < 1e-16 ? bounds1.getNorthEast().lng : bounds1.getSouthWest().lng)
  var y = (Math.abs(bounds1.getSouthWest().lat - maxbox.getNorthEast().lat) < 1e-16 ? bounds1.getNorthEast().lat : bounds1.getSouthWest().lat)

  var p1 = new CLatLng(y, x)

  x = (Math.abs(bounds2.getSouthWest().lng - maxbox.getNorthEast().lng) < 1e-16 ? bounds2.getNorthEast().lng : bounds2.getSouthWest().lng)
  y = (Math.abs(bounds2.getSouthWest().lat - maxbox.getNorthEast().lat) < 1e-16 ? bounds2.getNorthEast().lat : bounds2.getSouthWest().lat)
  var p2 = new CLatLng(y, x)
  return new CLatLngBounds(new CLatLng(Math.min(p1.lat, p2.lat), Math.min(p1.lng, p2.lng)), new CLatLng(Math.max(p1.lat, p2.lat), Math.max(p1.lng, p2.lng)))
}

export function getGlobalBounds() {
  return new CLatLngBounds(new CLatLng(-90, -180), new CLatLng(90, 180))
}
