// 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__34948){
var vec__34952 = p__34948;
var d = cljs.core.nth.call(null,vec__34952,(0),null);
var m = cljs.core.nth.call(null,vec__34952,(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__34955,theater,p__34956){
var vec__34968 = p__34955;
var nx = cljs.core.nth.call(null,vec__34968,(0),null);
var ny = cljs.core.nth.call(null,vec__34968,(1),null);
var vec__34971 = p__34956;
var lat = cljs.core.nth.call(null,vec__34971,(0),null);
var long$ = cljs.core.nth.call(null,vec__34971,(1),null);
var map__34974 = 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__34974__$1 = ((((!((map__34974 == null)))?((((map__34974.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34974.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34974):map__34974);
var left = cljs.core.get.call(null,map__34974__$1,new cljs.core.Keyword(null,"left","left",-399115937));
var top = cljs.core.get.call(null,map__34974__$1,new cljs.core.Keyword(null,"top","top",-1856271961));
var bottom = cljs.core.get.call(null,map__34974__$1,new cljs.core.Keyword(null,"bottom","bottom",-1550509018));
var top_right = cljs.core.get.call(null,map__34974__$1,new cljs.core.Keyword(null,"top-right","top-right",284698505));
var vec__34975 = 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__34975,(0),null);
var top_STAR_ = cljs.core.nth.call(null,vec__34975,(1),null);
var bottom_STAR_ = cljs.core.nth.call(null,vec__34975,(2),null);
var top_right_STAR_ = cljs.core.nth.call(null,vec__34975,(3),null);
var lat_STAR_ = cljs.core.nth.call(null,vec__34975,(4),null);
var long_STAR_ = cljs.core.nth.call(null,vec__34975,(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__34980,theater,airbase){
var vec__34989 = p__34980;
var nx = cljs.core.nth.call(null,vec__34989,(0),null);
var ny = cljs.core.nth.call(null,vec__34989,(1),null);
var map__34992 = cljs.core.first.call(null,cljs.core.filter.call(null,((function (vec__34989,nx,ny){
return (function (p1__34979_SHARP_){
return cljs.core._EQ_.call(null,new cljs.core.Keyword(null,"name","name",1843675177).cljs$core$IFn$_invoke$arity$1(p1__34979_SHARP_),airbase);
});})(vec__34989,nx,ny))
,weathergen.database.airbases.call(null,theater)));
var map__34992__$1 = ((((!((map__34992 == null)))?((((map__34992.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__34992.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__34992):map__34992);
var x = cljs.core.get.call(null,map__34992__$1,new cljs.core.Keyword(null,"x","x",2099068185));
var y = cljs.core.get.call(null,map__34992__$1,new cljs.core.Keyword(null,"y","y",-1757859776));
if(cljs.core.truth_((function (){var and__23326__auto__ = x;
if(cljs.core.truth_(and__23326__auto__)){
return y;
} else {
return and__23326__auto__;
}
})())){
var vec__34994 = 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__34994,(0),null);
var height = cljs.core.nth.call(null,vec__34994,(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__34997,x,y){
var vec__35001 = p__34997;
var nx = cljs.core.nth.call(null,vec__35001,(0),null);
var ny = cljs.core.nth.call(null,vec__35001,(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__35004){
var map__35007 = p__35004;
var map__35007__$1 = ((((!((map__35007 == null)))?((((map__35007.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35007.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35007):map__35007);
var x = cljs.core.get.call(null,map__35007__$1,new cljs.core.Keyword(null,"x","x",2099068185));
var y = cljs.core.get.call(null,map__35007__$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__35009){
var map__35018 = p__35009;
var map__35018__$1 = ((((!((map__35018 == null)))?((((map__35018.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35018.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35018):map__35018);
var coords = map__35018__$1;
var x = cljs.core.get.call(null,map__35018__$1,new cljs.core.Keyword(null,"x","x",2099068185));
var y = cljs.core.get.call(null,map__35018__$1,new cljs.core.Keyword(null,"y","y",-1757859776));
if(cljs.core.truth_(mission)){
var map__35020 = mission;
var map__35020__$1 = ((((!((map__35020 == null)))?((((map__35020.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35020.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35020):map__35020);
var campaign_info = cljs.core.get.call(null,map__35020__$1,new cljs.core.Keyword(null,"campaign-info","campaign-info",1158908966));
var map__35021 = campaign_info;
var map__35021__$1 = ((((!((map__35021 == null)))?((((map__35021.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35021.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35021):map__35021);
var bullseye_x = cljs.core.get.call(null,map__35021__$1,new cljs.core.Keyword(null,"bullseye-x","bullseye-x",-1698783852));
var bullseye_y = cljs.core.get.call(null,map__35021__$1,new cljs.core.Keyword(null,"bullseye-y","bullseye-y",904460818));
var map__35022 = weathergen.coordinates.weather__GT_fgrid.call(null,mission,coords);
var map__35022__$1 = ((((!((map__35022 == null)))?((((map__35022.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__35022.cljs$core$ISeq$)))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__35022):map__35022);
var fx = cljs.core.get.call(null,map__35022__$1,new cljs.core.Keyword(null,"x","x",2099068185));
var fy = cljs.core.get.call(null,map__35022__$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;
}
});
