// Compiled by ClojureScript 1.10.520 {}
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.ft_per_m = (weathergen.coordinates.ft_per_km / (1000));
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_per_map2 = (function weathergen$coordinates$nm_per_map2(mission){
return ((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.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);
});
weathergen.coordinates.m__GT_ft = (function weathergen$coordinates$m__GT_ft(m){
return (m * weathergen.coordinates.ft_per_m);
});
/**
 * 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.m__GT_nm = (function weathergen$coordinates$m__GT_nm(m){
return weathergen.coordinates.km__GT_nm.call(null,(m / (1000)));
});
weathergen.coordinates.dm__GT_deg = (function weathergen$coordinates$dm__GT_deg(p__27956){
var vec__27957 = p__27956;
var d = cljs.core.nth.call(null,vec__27957,(0),null);
var m = cljs.core.nth.call(null,vec__27957,(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__27960,theater,p__27961){
var vec__27962 = p__27960;
var nx = cljs.core.nth.call(null,vec__27962,(0),null);
var ny = cljs.core.nth.call(null,vec__27962,(1),null);
var vec__27965 = p__27961;
var lat = cljs.core.nth.call(null,vec__27965,(0),null);
var long$ = cljs.core.nth.call(null,vec__27965,(1),null);
var map__27968 = 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__27968__$1 = (((((!((map__27968 == null))))?(((((map__27968.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__27968.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__27968):map__27968);
var left = cljs.core.get.call(null,map__27968__$1,new cljs.core.Keyword(null,"left","left",-399115937));
var top = cljs.core.get.call(null,map__27968__$1,new cljs.core.Keyword(null,"top","top",-1856271961));
var bottom = cljs.core.get.call(null,map__27968__$1,new cljs.core.Keyword(null,"bottom","bottom",-1550509018));
var top_right = cljs.core.get.call(null,map__27968__$1,new cljs.core.Keyword(null,"top-right","top-right",284698505));
var vec__27969 = 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__27969,(0),null);
var top_STAR_ = cljs.core.nth.call(null,vec__27969,(1),null);
var bottom_STAR_ = cljs.core.nth.call(null,vec__27969,(2),null);
var top_right_STAR_ = cljs.core.nth.call(null,vec__27969,(3),null);
var lat_STAR_ = cljs.core.nth.call(null,vec__27969,(4),null);
var long_STAR_ = cljs.core.nth.call(null,vec__27969,(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__27974,theater,airbase){
var vec__27975 = p__27974;
var nx = cljs.core.nth.call(null,vec__27975,(0),null);
var ny = cljs.core.nth.call(null,vec__27975,(1),null);
var map__27978 = cljs.core.first.call(null,cljs.core.filter.call(null,((function (vec__27975,nx,ny){
return (function (p1__27973_SHARP_){
return cljs.core._EQ_.call(null,new cljs.core.Keyword(null,"name","name",1843675177).cljs$core$IFn$_invoke$arity$1(p1__27973_SHARP_),airbase);
});})(vec__27975,nx,ny))
,weathergen.database.airbases.call(null,theater)));
var map__27978__$1 = (((((!((map__27978 == null))))?(((((map__27978.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__27978.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__27978):map__27978);
var x = cljs.core.get.call(null,map__27978__$1,new cljs.core.Keyword(null,"x","x",2099068185));
var y = cljs.core.get.call(null,map__27978__$1,new cljs.core.Keyword(null,"y","y",-1757859776));
if(cljs.core.truth_((function (){var and__4120__auto__ = x;
if(cljs.core.truth_(and__4120__auto__)){
return y;
} else {
return and__4120__auto__;
}
})())){
var vec__27980 = 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__27980,(0),null);
var height = cljs.core.nth.call(null,vec__27980,(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__27983,x,y){
var vec__27984 = p__27983;
var nx = cljs.core.nth.call(null,vec__27984,(0),null);
var ny = cljs.core.nth.call(null,vec__27984,(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);
});
/**
 * Returns fractional weatherspace coordinates given Falcon-style x/y feet
 */
weathergen.coordinates.ffeet__GT_weather2 = (function weathergen$coordinates$ffeet__GT_weather2(mission,x,y){
return new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"y","y",-1757859776),((weathergen.coordinates.ft__GT_nm.call(null,y) / weathergen.coordinates.nm_per_map2.call(null,mission)) * (59)),new cljs.core.Keyword(null,"x","x",2099068185),((59) - ((weathergen.coordinates.ft__GT_nm.call(null,x) / weathergen.coordinates.nm_per_map2.call(null,mission)) * (59)))], null);
});
/**
 * Given a position in ACMI space (like ffeet, but in meters), return
 *   one in weather space.
 */
weathergen.coordinates.acmi__GT_weather = (function weathergen$coordinates$acmi__GT_weather(mission,u,v){
return new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"x","x",2099068185),((weathergen.coordinates.m__GT_nm.call(null,u) / weathergen.coordinates.nm_per_map2.call(null,mission)) * (59)),new cljs.core.Keyword(null,"y","y",-1757859776),((59) - ((weathergen.coordinates.m__GT_nm.call(null,v) / weathergen.coordinates.nm_per_map2.call(null,mission)) * (59)))], null);
});
/**
 * Converts from weatherspace coordinates to fgrid coords.
 */
weathergen.coordinates.weather__GT_fgrid = (function weathergen$coordinates$weather__GT_fgrid(mission,p__27987){
var map__27988 = p__27987;
var map__27988__$1 = (((((!((map__27988 == null))))?(((((map__27988.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__27988.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__27988):map__27988);
var x = cljs.core.get.call(null,map__27988__$1,new cljs.core.Keyword(null,"x","x",2099068185));
var y = cljs.core.get.call(null,map__27988__$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__27990){
var map__27991 = p__27990;
var map__27991__$1 = (((((!((map__27991 == null))))?(((((map__27991.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__27991.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__27991):map__27991);
var coords = map__27991__$1;
var x = cljs.core.get.call(null,map__27991__$1,new cljs.core.Keyword(null,"x","x",2099068185));
var y = cljs.core.get.call(null,map__27991__$1,new cljs.core.Keyword(null,"y","y",-1757859776));
if(cljs.core.truth_(mission)){
var map__27993 = mission;
var map__27993__$1 = (((((!((map__27993 == null))))?(((((map__27993.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__27993.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__27993):map__27993);
var campaign_info = cljs.core.get.call(null,map__27993__$1,new cljs.core.Keyword(null,"campaign-info","campaign-info",1158908966));
var map__27994 = campaign_info;
var map__27994__$1 = (((((!((map__27994 == null))))?(((((map__27994.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__27994.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__27994):map__27994);
var bullseye_x = cljs.core.get.call(null,map__27994__$1,new cljs.core.Keyword(null,"bullseye-x","bullseye-x",-1698783852));
var bullseye_y = cljs.core.get.call(null,map__27994__$1,new cljs.core.Keyword(null,"bullseye-y","bullseye-y",904460818));
var map__27995 = weathergen.coordinates.weather__GT_fgrid.call(null,mission,coords);
var map__27995__$1 = (((((!((map__27995 == null))))?(((((map__27995.cljs$lang$protocol_mask$partition0$ & (64))) || ((cljs.core.PROTOCOL_SENTINEL === map__27995.cljs$core$ISeq$))))?true:false):false))?cljs.core.apply.call(null,cljs.core.hash_map,map__27995):map__27995);
var fx = cljs.core.get.call(null,map__27995__$1,new cljs.core.Keyword(null,"x","x",2099068185));
var fy = cljs.core.get.call(null,map__27995__$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;
}
});
