Fixed issue 190. Bottom left and upper right points can be either the first or the second arguments when creating a rectangle.

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization@770 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-app/src/test/resources/runtimets/queries/spatial/rectangle-intersect-rectangle.aql b/asterix-app/src/test/resources/runtimets/queries/spatial/rectangle-intersect-rectangle.aql
index 90c9f77..b32b6a3 100644
--- a/asterix-app/src/test/resources/runtimets/queries/spatial/rectangle-intersect-rectangle.aql
+++ b/asterix-app/src/test/resources/runtimets/queries/spatial/rectangle-intersect-rectangle.aql
@@ -15,7 +15,7 @@
 write output to nc1:"rttest/spatial_rectangle-intersect-rectangle.adm";
 
 for $o in dataset('MyData')
-where spatial-intersect($o.rec, create-rectangle(create-point(-1.0,5.0), create-point(4.5,9.0)))
+where spatial-intersect($o.rec, create-rectangle(create-point(4.5,9.0), create-point(-1.0,5.0)))
 order by $o.id
 return {"id":$o.id}
  
diff --git a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ARectangleSerializerDeserializer.java b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ARectangleSerializerDeserializer.java
index f285a08..c926da4 100644
--- a/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ARectangleSerializerDeserializer.java
+++ b/asterix-om/src/main/java/edu/uci/ics/asterix/dataflow/data/nontagged/serde/ARectangleSerializerDeserializer.java
@@ -86,11 +86,14 @@
                     Double.parseDouble(points[0].split(",")[1]));
             aRectanglePoint2.setValue(Double.parseDouble(points[1].split(",")[0]),
                     Double.parseDouble(points[1].split(",")[1]));
-            if (aRectanglePoint1.getX() > aRectanglePoint2.getX() || aRectanglePoint1.getY() > aRectanglePoint2.getY()) {
+            if (aRectanglePoint1.getX() > aRectanglePoint2.getX() && aRectanglePoint1.getY() > aRectanglePoint2.getY()) {
+                aRectangle.setValue(aRectanglePoint2, aRectanglePoint1);
+            } else if (aRectanglePoint1.getX() < aRectanglePoint2.getX() && aRectanglePoint1.getY() < aRectanglePoint2.getY()) {
+                aRectangle.setValue(aRectanglePoint1, aRectanglePoint2);
+            } else {
                 throw new IllegalArgumentException(
-                        "The low point in the rectangle cannot be larger than the high point");
+                        "Rectangle arugment must be either (bottom left point, top right point) or (top right point, bottom left point)");
             }
-            aRectangle.setValue(aRectanglePoint1, aRectanglePoint2);
             rectangleSerde.serialize(aRectangle, out);
         } catch (HyracksDataException e) {
             throw new HyracksDataException(rectangle + " can not be an instance of rectangle");
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ARectangleConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ARectangleConstructorDescriptor.java
index 9d2385f..955d955 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ARectangleConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ARectangleConstructorDescriptor.java
@@ -88,11 +88,14 @@
                                 commaIndex = s.indexOf(',', spaceIndex + 1);
                                 aPoint[1].setValue(Double.parseDouble(s.substring(spaceIndex + 1, commaIndex)),
                                         Double.parseDouble(s.substring(commaIndex + 1, s.length())));
-                                if (aPoint[0].getX() > aPoint[1].getX() || aPoint[0].getY() > aPoint[1].getY()) {
+                                if (aPoint[0].getX() > aPoint[1].getX() && aPoint[0].getY() > aPoint[1].getY()) {
+                                    aRectangle.setValue(aPoint[1], aPoint[0]);
+                                } else if (aPoint[0].getX() < aPoint[1].getX() && aPoint[0].getY() < aPoint[1].getY()) {
+                                    aRectangle.setValue(aPoint[0], aPoint[1]);
+                                } else {
                                     throw new IllegalArgumentException(
-                                            "The low point in the rectangle cannot be larger than the high point");
+                                            "Rectangle arugment must be either (bottom left point, top right point) or (top right point, bottom left point)");
                                 }
-                                aRectangle.setValue(aPoint[0], aPoint[1]);
                                 rectangle2DSerde.serialize(aRectangle, out);
                             } else if (serString[0] == SER_NULL_TYPE_TAG)
                                 nullSerde.serialize(ANull.NULL, out);
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateRectangleDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateRectangleDescriptor.java
index 01c33df..a248a87 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateRectangleDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/functions/CreateRectangleDescriptor.java
@@ -71,11 +71,14 @@
                                     APointSerializerDeserializer.getCoordinateOffset(Coordinate.X)),
                                     ADoubleSerializerDeserializer.getDouble(outInput1.getByteArray(),
                                             APointSerializerDeserializer.getCoordinateOffset(Coordinate.Y)));
-                            if (aPoint[0].getX() > aPoint[1].getX() || aPoint[0].getY() > aPoint[1].getY()) {
+                            if (aPoint[0].getX() > aPoint[1].getX() && aPoint[0].getY() > aPoint[1].getY()) {
+                                aRectangle.setValue(aPoint[1], aPoint[0]);
+                            } else if (aPoint[0].getX() < aPoint[1].getX() && aPoint[0].getY() < aPoint[1].getY()) {
+                                aRectangle.setValue(aPoint[0], aPoint[1]);
+                            } else {
                                 throw new IllegalArgumentException(
-                                        "The low point in the rectangle cannot be larger than the high point");
+                                        "Rectangle arugment must be either (bottom left point, top right point) or (top right point, bottom left point)");
                             }
-                            aRectangle.setValue(aPoint[0], aPoint[1]);
                             rectangle2DSerde.serialize(aRectangle, out);
                         } catch (IOException e1) {
                             throw new AlgebricksException(e1);