/**
 * END USER LICENSE AGREEMENT (“EULA”)
 *
 * READ THIS AGREEMENT CAREFULLY (date: 9/13/2011):
 * http://www.akiban.com/licensing/20110913
 *
 * BY INSTALLING OR USING ALL OR ANY PORTION OF THE SOFTWARE, YOU ARE ACCEPTING
 * ALL OF THE TERMS AND CONDITIONS OF THIS AGREEMENT. YOU AGREE THAT THIS
 * AGREEMENT IS ENFORCEABLE LIKE ANY WRITTEN AGREEMENT SIGNED BY YOU.
 *
 * IF YOU HAVE PAID A LICENSE FEE FOR USE OF THE SOFTWARE AND DO NOT AGREE TO
 * THESE TERMS, YOU MAY RETURN THE SOFTWARE FOR A FULL REFUND PROVIDED YOU (A) DO
 * NOT USE THE SOFTWARE AND (B) RETURN THE SOFTWARE WITHIN THIRTY (30) DAYS OF
 * YOUR INITIAL PURCHASE.
 *
 * IF YOU WISH TO USE THE SOFTWARE AS AN EMPLOYEE, CONTRACTOR, OR AGENT OF A
 * CORPORATION, PARTNERSHIP OR SIMILAR ENTITY, THEN YOU MUST BE AUTHORIZED TO SIGN
 * FOR AND BIND THE ENTITY IN ORDER TO ACCEPT THE TERMS OF THIS AGREEMENT. THE
 * LICENSES GRANTED UNDER THIS AGREEMENT ARE EXPRESSLY CONDITIONED UPON ACCEPTANCE
 * BY SUCH AUTHORIZED PERSONNEL.
 *
 * IF YOU HAVE ENTERED INTO A SEPARATE WRITTEN LICENSE AGREEMENT WITH AKIBAN FOR
 * USE OF THE SOFTWARE, THE TERMS AND CONDITIONS OF SUCH OTHER AGREEMENT SHALL
 * PREVAIL OVER ANY CONFLICTING TERMS OR CONDITIONS IN THIS AGREEMENT.
 */

package com.akiban.ais.model;

import com.akiban.server.geophile.Space;

import com.akiban.server.error.InvalidArgumentTypeException;

import java.math.BigInteger;

public class SpaceHelper
{
    /** Given the types of latitude and longitude decimal columns, return an appropriate
     * {@link Space}.
     */
    public static Space latLon(Column latCol, Column lonCol) {
        if ((latCol.getType() != Types.DECIMAL) ||
            (lonCol.getType() != Types.DECIMAL)) {
            throw new InvalidArgumentTypeException("Columns must both be DECIMAL");
        }
        long latScale = BigInteger.TEN.pow(latCol.getTypeParameter2().intValue()).longValue();
        long lonScale = BigInteger.TEN.pow(lonCol.getTypeParameter2().intValue()).longValue();
        // TODO: Maybe there should be subclasses of Space for
        // different coordinate systems?
        // Latitude is actually -90 - +90 or 0 - 180, but dims apparently have to be the same.
        return new Space(new long[] { 0, 0 },
                         new long[] { 360 * latScale, 360 * lonScale });
    }

    private SpaceHelper() {
    }
}

@@ -1597,24 +1597,57 @@
 n lonCol) %7B%0A
+        long latScale, lonScale;%0A
         if (
@@ -1645,17 +1645,16 @@
      if 
-(
 (latCol.
@@ -1659,33 +1659,33 @@
 l.getType() 
-!
+=
 = Types.
 DECIMAL) %7C%7C%0A
@@ -1676,36 +1676,59 @@
 pes.
-DECIMAL) %7C%7C%0A            (lon
+INT)%0A            latScale = 1;%0A        else if (lat
 Col.
@@ -1741,9 +1741,9 @@
 e() 
-!
+=
 = Ty
@@ -1754,19 +1754,123 @@
 DECIMAL)
-) %7B
+%0A            latScale = BigInteger.TEN.pow(latCol.getTypeParameter2().intValue()).longValue();%0A        else
 %0A       
@@ -1918,26 +1918,22 @@
 on(%22
-Columns
+Latitude
  must 
-both 
 be D
@@ -1938,16 +1938,23 @@
  DECIMAL
+ or INT
 %22);%0A    
@@ -1957,18 +1957,55 @@
         
-%7D%0A
+if (lonCol.getType() == Types.INT)%0A    
         
@@ -2011,21 +2011,16 @@
  lon
-g lat
 Scale = 
 BigI
@@ -2019,78 +2019,62 @@
 e = 
-BigInteger.TEN.pow(latCol.getTypeParameter2().intValue()).longValue();
+1;%0A        else if (lonCol.getType() == Types.DECIMAL)
 %0A   
@@ -2078,20 +2078,19 @@
         
-long
+   
  lonScal
@@ -2156,32 +2156,134 @@
 )).longValue();%0A
+        else%0A            throw new InvalidArgumentTypeException(%22Longitude must be DECIMAL or INT%22);%0A%0A
         // TODO:
@@ -2477,42 +2477,140 @@
     
-return new Space(new long%5B%5D %7B 0, 0
+// Jack says that's because I let the third argument default.%0A        return new Space(new long%5B%5D %7B -180 * latScale, -180 * lonScale
  %7D,%0A
@@ -2647,18 +2647,18 @@
 ong%5B%5D %7B 
-36
+18
 0 * latS
@@ -2667,10 +2667,10 @@
 le, 
-36
+18
 0 * 

Allow INT as well as DECIMAL for now.