 ;; `[0 0]`, pixel `[0 0]`) in pixels into distance from the sinusoidal
 ;; origin (`[0 0]` in meters, corresponding to (lat, lon) = `[-90
 ;; -180]`).
+
+(defn latlon-rad->sinu-xy
+  "Returns the sinusoidal x and y coordinates for the supplied
+  latitude and longitude (in radians)."
+  [lat lon]
+  (scale rho [(* (cos lat) lon) lat]))
+
+(defn latlon->sinu-xy
+  "Returns the sinusoidal x and y coordinates for the supplied
+  latitude and longitude (in degrees)."
+  [lat lon]
+  (apply latlon-rad->sinu-xy
+         (map #(Math/toRadians %) [lat lon])))
 
 (defn sinu-xy->latlon
   "Returns the latitude and longitude (in degrees) for a given set of

(defn scale
  "Scales each element in a collection of numbers by the supplied
  factor."
  [fact sequence]
  (for [x sequence] (* x fact)))

;; From [Wikipedia](http://goo.gl/qG7Hi), "the sinusoidal projection
;; is a pseudocylindrical equal-area map projection, sometimes called

        lon (/ x (* rho (cos lat)))]
    (map #(Math/toDegrees %) [lat lon])))

(defmacro conversion-comp
  [& conversions]
  `(fn [& args#]
     (reduce (fn [val-seq# f#]
               (apply f# val-seq#))
             args#
             [~@conversions])))

;; Returns the map position in meters of the supplied MODIS tile
;;  coordinate at the specified resolution

(def modis->latlon
  (conversion-comp modis->global-mags
                   global-mags->sinu-xy
                    sinu-xy->latlon))

;; TODO -- get the damned global pixel
