// Compiled by ClojureScript 1.9.562 {}
goog.provide('weathergen.coordinates');
goog.require('cljs.core');
goog.require('weathergen.math');
goog.require('weathergen.database');
weathergen.coordinates.ft_per_nm = 6076.12;
weathergen.coordinates.ft_per_km = 3280.84;
weathergen.coordinates.nm_per_km = (weathergen.coordinates.ft_per_km / weathergen.coordinates.ft_per_nm);
weathergen.coordinates.nm_per_map = (((1024) * weathergen.coordinates.ft_per_km) / weathergen.coordinates.ft_per_nm);
weathergen.coordinates.nm__GT_ft = (function weathergen$coordinates$nm__GT_ft(nm){
return (nm * weathergen.coordinates.ft_per_nm);
});
/**
 * Converts from Falcon grid (km) to nm
 */
weathergen.coordinates.fgrid__GT_nm = (function weathergen$coordinates$fgrid__GT_nm(km){
return (km * weathergen.coordinates.nm_per_km);
});
weathergen.coordinates.km__GT_nm = weathergen.coordinates.fgrid__GT_nm;
weathergen.coordinates.ft__GT_nm = (function weathergen$coordinates$ft__GT_nm(ft){
return (ft / weathergen.coordinates.ft_per_nm);
});
weathergen.coordinates.dm__GT_deg = (function weathergen$coordinates$dm__GT_deg(p__34958){
var vec__34962 = p__34958;
var d = cljs.core.nth.call(null,vec__34962,(0),null);
var m = cljs.core.nth.call(null,vec__34962,(1),null);
return (d + (m / 60.0));
});
/**
 * Convert from degree/minute coordinates to fractional grid coordinates
 */
weathergen.coordinates.lat_long__GT_grid = (function weathergen$coordinates$lat_long__GT_grid(p__34965,theater,p__34966){
var vec__34978 = p__34965;
var nx = cljs.core.nth.call(null,vec__34978,(0),null);
var ny = cljs.core.nth.call(null,vec__34978,(1),null);
var vec__34981 = p__34966;
var lat = cljs.core.nth.call(null,vec__34981,(0),null);
var long$ = cljs.core.nth.call(null,vec__34981,(1),null);
var map__34984 = cljs.core.get_in.call(null,weathergen.database.theater_info,new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [theater,new cljs.core.Keyword(null,"mapping","mapping",-1242405430)], null));
var map__34984__$1 = ((((!((map__34984 == null)))?((((map__34984.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34984.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34984):map__34984);
var left = cljs.core.get.call(null,map__34984__$1,new cljs.core.Keyword(null,"left","left",-399115937));
var top = cljs.core.get.call(null,map__34984__$1,new cljs.core.Keyword(null,"top","top",-1856271961));
var bottom = cljs.core.get.call(null,map__34984__$1,new cljs.core.Keyword(null,"bottom","bottom",-1550509018));
var top_right = cljs.core.get.call(null,map__34984__$1,new cljs.core.Keyword(null,"top-right","top-right",284698505));
var vec__34985 = cljs.core.map.call(null,weathergen.coordinates.dm__GT_deg,new cljs.core.PersistentVector(null, 6, 5, cljs.core.PersistentVector.EMPTY_NODE, [left,top,bottom,top_right,lat,long$], null));
var left_STAR_ = cljs.core.nth.call(null,vec__34985,(0),null);
var top_STAR_ = cljs.core.nth.call(null,vec__34985,(1),null);
var bottom_STAR_ = cljs.core.nth.call(null,vec__34985,(2),null);
var top_right_STAR_ = cljs.core.nth.call(null,vec__34985,(3),null);
var lat_STAR_ = cljs.core.nth.call(null,vec__34985,(4),null);
var long_STAR_ = cljs.core.nth.call(null,vec__34985,(5),null);
var topr = weathergen.math.deg__GT_rad.call(null,top_STAR_);
var latr = weathergen.math.deg__GT_rad.call(null,lat_STAR_);
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [(((((long_STAR_ - left_STAR_) / (top_right_STAR_ - left_STAR_)) / Math.cos(topr)) * Math.cos(latr)) * nx),(((lat_STAR_ - top_STAR_) / (bottom_STAR_ - top_STAR_)) * ny)], null);
});
/**
 * Returns the grid coordinates of an airbase
 */
weathergen.coordinates.airbase_coordinates = (function weathergen$coordinates$airbase_coordinates(p__34990,theater,airbase){
var vec__34999 = p__34990;
var nx = cljs.core.nth.call(null,vec__34999,(0),null);
var ny = cljs.core.nth.call(null,vec__34999,(1),null);
var map__35002 = cljs.core.first.call(null,cljs.core.filter.call(null,((function (vec__34999,nx,ny){
return (function (p1__34989_SHARP_){
return cljs.core._EQ_.call(null,new cljs.core.Keyword(null,"name","name",1843675177).cljs$core$IFn$_invoke$arity$1(p1__34989_SHARP_),airbase);
});})(vec__34999,nx,ny))
,weathergen.database.airbases.call(null,theater)));
var map__35002__$1 = ((((!((map__35002 == null)))?((((map__35002.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35002.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35002):map__35002);
var x = cljs.core.get.call(null,map__35002__$1,new cljs.core.Keyword(null,"x","x",2099068185));
var y = cljs.core.get.call(null,map__35002__$1,new cljs.core.Keyword(null,"y","y",-1757859776));
if(cljs.core.truth_((function (){var and__23136__auto__ = x;
if(cljs.core.truth_(and__23136__auto__)){
return y;
} else {
return and__23136__auto__;
}
})())){
var vec__35004 = new cljs.core.Keyword(null,"size","size",1098693007).cljs$core$IFn$_invoke$arity$1(theater.call(null,weathergen.database.theater_info));
var width = cljs.core.nth.call(null,vec__35004,(0),null);
var height = cljs.core.nth.call(null,vec__35004,(1),null);
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [(((x / width) * nx) | (0)),((ny - (1)) - (((y / height) * ny) | (0)))], null);
} else {
return null;
}
});
/**
 * Returns fractional weatherspace coordinates given Falcon-style x/y feet
 */
weathergen.coordinates.ffeet__GT_weather = (function weathergen$coordinates$ffeet__GT_weather(p__35007,x,y){
var vec__35011 = p__35007;
var nx = cljs.core.nth.call(null,vec__35011,(0),null);
var ny = cljs.core.nth.call(null,vec__35011,(1),null);
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [((weathergen.coordinates.ft__GT_nm.call(null,y) / weathergen.coordinates.nm_per_map) * ny),(nx - ((weathergen.coordinates.ft__GT_nm.call(null,x) / weathergen.coordinates.nm_per_map) * nx))], null);
});
/**
 * Converts from weatherspace coordinates to fgrid coords.
 */
weathergen.coordinates.weather__GT_fgrid = (function weathergen$coordinates$weather__GT_fgrid(mission,p__35014){
var map__35017 = p__35014;
var map__35017__$1 = ((((!((map__35017 == null)))?((((map__35017.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35017.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35017):map__35017);
var x = cljs.core.get.call(null,map__35017__$1,new cljs.core.Keyword(null,"x","x",2099068185));
var y = cljs.core.get.call(null,map__35017__$1,new cljs.core.Keyword(null,"y","y",-1757859776));
return new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"x","x",2099068185),((x / 59.0) * new cljs.core.Keyword(null,"theater-size-x","theater-size-x",1642493141).cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"campaign-info","campaign-info",1158908966).cljs$core$IFn$_invoke$arity$1(mission))),new cljs.core.Keyword(null,"y","y",-1757859776),(((1) - (y / 59.0)) * new cljs.core.Keyword(null,"theater-size-y","theater-size-y",-1863614166).cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"campaign-info","campaign-info",1158908966).cljs$core$IFn$_invoke$arity$1(mission)))], null);
});
/**
 * Converts from weatherspace linear units (squares) to nm
 */
weathergen.coordinates.weather__GT_nm = (function weathergen$coordinates$weather__GT_nm(mission,squares){
return (((squares / 59.0) * new cljs.core.Keyword(null,"theater-size-x","theater-size-x",1642493141).cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"campaign-info","campaign-info",1158908966).cljs$core$IFn$_invoke$arity$1(mission))) * weathergen.coordinates.nm_per_km);
});
/**
 * Converts from nm to weatherspace linear units (squares).
 */
weathergen.coordinates.nm__GT_weather = (function weathergen$coordinates$nm__GT_weather(mission,nm){
return (((nm / weathergen.coordinates.nm_per_km) / new cljs.core.Keyword(null,"theater-size-x","theater-size-x",1642493141).cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"campaign-info","campaign-info",1158908966).cljs$core$IFn$_invoke$arity$1(mission))) * (59));
});
/**
 * Returns a map of :x and :y coordinates (in weather space) given
 *   coordinates in Falcon grid space.
 */
weathergen.coordinates.fgrid__GT_weather = (function weathergen$coordinates$fgrid__GT_weather(mission,x,y){
return new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"x","x",2099068185),((x / new cljs.core.Keyword(null,"theater-size-x","theater-size-x",1642493141).cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"campaign-info","campaign-info",1158908966).cljs$core$IFn$_invoke$arity$1(mission))) * 59.0),new cljs.core.Keyword(null,"y","y",-1757859776),(((1) - (y / new cljs.core.Keyword(null,"theater-size-y","theater-size-y",-1863614166).cljs$core$IFn$_invoke$arity$1(new cljs.core.Keyword(null,"campaign-info","campaign-info",1158908966).cljs$core$IFn$_invoke$arity$1(mission)))) * 59.0)], null);
});
/**
 * Convert from weatherspace coordinates to bullseye, a map with
 *   `:heading` and `:distance` keys. Distance is in nm, heading in
 *   degrees.
 */
weathergen.coordinates.weather__GT_bullseye = (function weathergen$coordinates$weather__GT_bullseye(mission,p__35019){
var map__35028 = p__35019;
var map__35028__$1 = ((((!((map__35028 == null)))?((((map__35028.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35028.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35028):map__35028);
var coords = map__35028__$1;
var x = cljs.core.get.call(null,map__35028__$1,new cljs.core.Keyword(null,"x","x",2099068185));
var y = cljs.core.get.call(null,map__35028__$1,new cljs.core.Keyword(null,"y","y",-1757859776));
if(cljs.core.truth_(mission)){
var map__35030 = mission;
var map__35030__$1 = ((((!((map__35030 == null)))?((((map__35030.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35030.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35030):map__35030);
var campaign_info = cljs.core.get.call(null,map__35030__$1,new cljs.core.Keyword(null,"campaign-info","campaign-info",1158908966));
var map__35031 = campaign_info;
var map__35031__$1 = ((((!((map__35031 == null)))?((((map__35031.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35031.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35031):map__35031);
var bullseye_x = cljs.core.get.call(null,map__35031__$1,new cljs.core.Keyword(null,"bullseye-x","bullseye-x",-1698783852));
var bullseye_y = cljs.core.get.call(null,map__35031__$1,new cljs.core.Keyword(null,"bullseye-y","bullseye-y",904460818));
var map__35032 = weathergen.coordinates.weather__GT_fgrid.call(null,mission,coords);
var map__35032__$1 = ((((!((map__35032 == null)))?((((map__35032.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35032.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35032):map__35032);
var fx = cljs.core.get.call(null,map__35032__$1,new cljs.core.Keyword(null,"x","x",2099068185));
var fy = cljs.core.get.call(null,map__35032__$1,new cljs.core.Keyword(null,"y","y",-1757859776));
var dx = (fx - bullseye_x);
var dy = (fy - bullseye_y);
var d = new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [dx,dy], null);
return new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"heading","heading",-1312171873),weathergen.math.heading.call(null,d),new cljs.core.Keyword(null,"distance","distance",-1671893894),(weathergen.math.magnitude.call(null,d) * weathergen.coordinates.nm_per_km)], null);
} else {
return null;
}
});
