diff --git a/pom.xml b/pom.xml index eec05faa..40676df4 100755 --- a/pom.xml +++ b/pom.xml @@ -129,6 +129,12 @@ ${jol.version} test + + net.sourceforge.cobertura + cobertura + 2.1.1 + test + diff --git a/src/main/java/com/esri/core/geometry/GeoDist.java b/src/main/java/com/esri/core/geometry/GeoDist.java index b7845151..779ded59 100644 --- a/src/main/java/com/esri/core/geometry/GeoDist.java +++ b/src/main/java/com/esri/core/geometry/GeoDist.java @@ -159,80 +159,29 @@ static public void geodesic_distance_ngs(double a, double e2, double lam1, if (PE_EQ(phi1, phi2) && (PE_ZERO(dlam) || PE_EQ(PE_ABS(phi1), PE_PI2))) { /* Check that the points are not the same */ - if (p_dist != null) - p_dist.val = 0.0; - if (p_az12 != null) - p_az12.val = 0.0; - if (p_az21 != null) - p_az21.val = 0.0; + assignValues(p_dist, p_az12, p_az21, 0.0, 0.0, 0.0); return; } else if (PE_EQ(phi1, -phi2)) { /* Check if they are perfectly antipodal */ if (PE_EQ(PE_ABS(phi1), PE_PI2)) { /* Check if they are at opposite poles */ - if (p_dist != null) - p_dist.val = 2.0 * q90(a, e2); - - if (p_az12 != null) - p_az12.val = phi1 > 0.0 ? lam_delta(PE_PI - lam_delta(lam2)) - : lam_delta(lam2); - - if (p_az21 != null) - p_az21.val = phi1 > 0.0 ? lam_delta(lam2) : lam_delta(PE_PI - - lam_delta(lam2)); - + assignValues(p_dist, p_az12, p_az21, 2.0 * q90(a, e2), + phi1 > 0.0 ? lam_delta(PE_PI - lam_delta(lam2)) + : lam_delta(lam2), + phi1 > 0.0 ? lam_delta(lam2) : lam_delta(PE_PI + - lam_delta(lam2))); return; } else if (PE_EQ(PE_ABS(dlam), PE_PI)) { /* Other antipodal */ - if (p_dist != null) - p_dist.val = 2.0 * q90(a, e2); - if (p_az12 != null) - p_az12.val = 0.0; - if (p_az21 != null) - p_az21.val = 0.0; + assignValues(p_dist, p_az12, p_az21, 2.0 * q90(a, e2), 0.0, 0.0); return; } } if (PE_ZERO(e2)) /* Sphere */ { - double cos_phi1, cos_phi2; - double sin_phi1, sin_phi2; - - cos_phi1 = Math.cos(phi1); - cos_phi2 = Math.cos(phi2); - sin_phi1 = Math.sin(phi1); - sin_phi2 = Math.sin(phi2); - - if (p_dist != null) { - tem1 = Math.sin((phi2 - phi1) / 2.0); - tem2 = Math.sin(dlam / 2.0); - sigma = 2.0 * Math.asin(Math.sqrt(tem1 * tem1 + cos_phi1 - * cos_phi2 * tem2 * tem2)); - p_dist.val = sigma * a; - } - - if (p_az12 != null) { - if (PE_EQ(PE_ABS(phi1), PE_PI2)) /* Origin at N or S Pole */ - { - p_az12.val = phi1 < 0.0 ? lam2 : lam_delta(PE_PI - lam2); - } else { - p_az12.val = Math.atan2(cos_phi2 * Math.sin(dlam), cos_phi1 - * sin_phi2 - sin_phi1 * cos_phi2 * Math.cos(dlam)); - } - } - - if (p_az21 != null) { - if (PE_EQ(PE_ABS(phi2), PE_PI2)) /* Destination at N or S Pole */ - { - p_az21.val = phi2 < 0.0 ? lam1 : lam_delta(PE_PI - lam1); - } else { - p_az21.val = Math.atan2(cos_phi1 * Math.sin(dlam), sin_phi2 - * cos_phi1 * Math.cos(dlam) - cos_phi2 * sin_phi1); - p_az21.val = lam_delta(p_az21.val + PE_PI); - } - } + sigma = sphereDistance(a, lam1, phi1, lam2, phi2, p_dist, p_az12, p_az21, dlam, sigma); return; } @@ -290,14 +239,7 @@ static public void geodesic_distance_ngs(double a, double e2, double lam1, cos2_azeq = 1.0 - sin_azeq * sin_azeq; - if (PE_ABS(cos2_azeq) < eps) /* avoid division by 0 */ - { - costm = cos_sigma - 2.0 - * (sin_eta1 * sin_eta2 / PE_SGN(eps, cos2_azeq)); - } else { - costm = cos_sigma - 2.0 * (sin_eta1 * sin_eta2 / cos2_azeq); - /* v18 (Rapp 1.91) */ - } + costm = checkCos2AzeqNotNull(eps, sin_eta1, sin_eta2, cos_sigma, cos2_azeq); costm2 = costm * costm; c = ((-3.0 * cos2_azeq + 4.0) * f + 4.0) * cos2_azeq * f / 16.0; /* * v10 @@ -345,16 +287,7 @@ static public void geodesic_distance_ngs(double a, double e2, double lam1, q_continue_looping = false; continue; } - if (PE_ABS(cos2_azeq) < eps) /* avoid division by 0 */ - { - costm = cos_sigma - - 2.0 - * (sin_eta1 * sin_eta2 / PE_SGN(eps, cos2_azeq)); - } else { - costm = cos_sigma - 2.0 - * (sin_eta1 * sin_eta2 / cos2_azeq); - /* v18 (Rapp 1.91) */ - } + costm = checkCos2AzeqNotNull(eps, sin_eta1, sin_eta2, cos_sigma, cos2_azeq); costm2 = costm * costm; continue; } @@ -397,14 +330,7 @@ static public void geodesic_distance_ngs(double a, double e2, double lam1, q_continue_looping = false; continue; } - if (PE_ABS(cos2_azeq) < eps) /* avoid division by 0 */ - { - costm = cos_sigma - 2.0 - * (sin_eta1 * sin_eta2 / PE_SGN(eps, cos2_azeq)); - } else { - costm = cos_sigma - 2.0 * (sin_eta1 * sin_eta2 / cos2_azeq); - /* v18 (Rapp 1.91) */ - } + costm = checkCos2AzeqNotNull(eps, sin_eta1, sin_eta2, cos_sigma, cos2_azeq); costm2 = costm * costm; continue; } @@ -455,13 +381,75 @@ static public void geodesic_distance_ngs(double a, double e2, double lam1, tem2 = sin_eta1 * cos_eta2 - cos_eta1 * sin_eta2 * cos_lam_sph; az21 = Math.atan2(tem1, tem2); } + assignValues(null, p_az12, p_az21, 0.0, lam_delta(az12), lam_delta(az21)); + } + } + + private static void assignValues(PeDouble p_dist, PeDouble p_az12, PeDouble p_az21, double dist, double az12, double az21) { + if (p_dist != null) + p_dist.val = dist; + if (p_az12 != null) + p_az12.val = az12; + if (p_az21 != null) + p_az21.val = az21; + } + + private static double checkCos2AzeqNotNull(double eps, double sin_eta1, double sin_eta2, double cos_sigma, + double cos2_azeq) { + double costm; + if (PE_ABS(cos2_azeq) < eps) /* avoid division by 0 */ + { + costm = cos_sigma - 2.0 + * (sin_eta1 * sin_eta2 / PE_SGN(eps, cos2_azeq)); + } else { + costm = cos_sigma - 2.0 * (sin_eta1 * sin_eta2 / cos2_azeq); + /* v18 (Rapp 1.91) */ + } + return costm; + } + + private static double sphereDistance(double a, double lam1, double phi1, double lam2, double phi2, PeDouble p_dist, + PeDouble p_az12, PeDouble p_az21, double dlam, double sigma) { + double tem1; + double tem2; + double cos_phi1, cos_phi2; + double sin_phi1, sin_phi2; - if (p_az12 != null) { - p_az12.val = lam_delta(az12); + cos_phi1 = Math.cos(phi1); + cos_phi2 = Math.cos(phi2); + sin_phi1 = Math.sin(phi1); + sin_phi2 = Math.sin(phi2); + + if (p_dist != null) { + tem1 = Math.sin((phi2 - phi1) / 2.0); + tem2 = Math.sin(dlam / 2.0); + sigma = 2.0 * Math.asin(Math.sqrt(tem1 * tem1 + cos_phi1 + * cos_phi2 * tem2 * tem2)); + p_dist.val = sigma * a; + } + + if (p_az12 != null) { + if (PE_EQ(PE_ABS(phi1), PE_PI2)) /* Origin at N or S Pole */ + { + p_az12.val = phi1 < 0.0 ? lam2 : lam_delta(PE_PI - lam2); + } else { + p_az12.val = Math.atan2(cos_phi2 * Math.sin(dlam), cos_phi1 + * sin_phi2 - sin_phi1 * cos_phi2 * Math.cos(dlam)); } - if (p_az21 != null) { - p_az21.val = lam_delta(az21); + } + + if (p_az21 != null) { + if (PE_EQ(PE_ABS(phi2), PE_PI2)) /* Destination at N or S Pole */ + { + p_az21.val = phi2 < 0.0 ? lam1 : lam_delta(PE_PI - lam1); + } else { + p_az21.val = Math.atan2(cos_phi1 * Math.sin(dlam), sin_phi2 + * cos_phi1 * Math.cos(dlam) - cos_phi2 * sin_phi1); + p_az21.val = lam_delta(p_az21.val + PE_PI); } } + return sigma; } } + + diff --git a/src/main/java/com/esri/core/geometry/RelationalOperations.java b/src/main/java/com/esri/core/geometry/RelationalOperations.java index 0b73561a..6ec47059 100644 --- a/src/main/java/com/esri/core/geometry/RelationalOperations.java +++ b/src/main/java/com/esri/core/geometry/RelationalOperations.java @@ -156,174 +156,215 @@ else if (relation == Relation.contains) } } - switch (type_a) { - case Geometry.GeometryType.Polygon: - switch (type_b) { - case Geometry.GeometryType.Polygon: - bRelation = polygonRelatePolygon_((Polygon) (_geometry_a), - (Polygon) (_geometry_b), tolerance, relation, - progress_tracker); - break; + bRelation = switchGeometryTypes(relation, progress_tracker, type_a, type_b, tolerance, bRelation, _geometry_a, + _geometry_b); - case Geometry.GeometryType.Polyline: - bRelation = polygonRelatePolyline_((Polygon) (_geometry_a), - (Polyline) (_geometry_b), tolerance, relation, - progress_tracker); - break; - - case Geometry.GeometryType.Point: - bRelation = polygonRelatePoint_((Polygon) (_geometry_a), - (Point) (_geometry_b), tolerance, relation, - progress_tracker); - break; - - case Geometry.GeometryType.MultiPoint: - bRelation = polygonRelateMultiPoint_((Polygon) (_geometry_a), - (MultiPoint) (_geometry_b), tolerance, relation, - progress_tracker); - break; - - case Geometry.GeometryType.Envelope: - bRelation = polygonRelateEnvelope_((Polygon) (_geometry_a), - (Envelope) (_geometry_b), tolerance, relation, - progress_tracker); - break; + return bRelation; + } - default: - break; // warning fix - } + private static boolean switchGeometryTypes(int relation, ProgressTracker progress_tracker, int type_a, int type_b, + double tolerance, boolean bRelation, Geometry _geometry_a, Geometry _geometry_b) { + switch (type_a) { + case Geometry.GeometryType.Polygon: + bRelation = typeAPolygon(relation, progress_tracker, type_b, tolerance, bRelation, _geometry_a, + _geometry_b); break; case Geometry.GeometryType.Polyline: - switch (type_b) { - case Geometry.GeometryType.Polygon: - bRelation = polygonRelatePolyline_((Polygon) (_geometry_b), - (Polyline) (_geometry_a), tolerance, relation, - progress_tracker); - break; - - case Geometry.GeometryType.Polyline: - bRelation = polylineRelatePolyline_((Polyline) (_geometry_a), - (Polyline) (_geometry_b), tolerance, relation, - progress_tracker); - break; - - case Geometry.GeometryType.Point: - bRelation = polylineRelatePoint_((Polyline) (_geometry_a), - (Point) (_geometry_b), tolerance, relation, - progress_tracker); - break; - - case Geometry.GeometryType.MultiPoint: - bRelation = polylineRelateMultiPoint_((Polyline) (_geometry_a), - (MultiPoint) (_geometry_b), tolerance, relation, - progress_tracker); - break; - - case Geometry.GeometryType.Envelope: - bRelation = polylineRelateEnvelope_((Polyline) (_geometry_a), - (Envelope) (_geometry_b), tolerance, relation, - progress_tracker); - break; - - default: - break; // warning fix - } + bRelation = typeAPolyline(relation, progress_tracker, type_b, tolerance, bRelation, _geometry_a, + _geometry_b); break; case Geometry.GeometryType.Point: - switch (type_b) { - case Geometry.GeometryType.Polygon: - bRelation = polygonRelatePoint_((Polygon) (_geometry_b), - (Point) (_geometry_a), tolerance, relation, - progress_tracker); - break; - - case Geometry.GeometryType.Polyline: - bRelation = polylineRelatePoint_((Polyline) (_geometry_b), - (Point) (_geometry_a), tolerance, relation, - progress_tracker); - break; - - case Geometry.GeometryType.MultiPoint: - bRelation = multiPointRelatePoint_((MultiPoint) (_geometry_b), - (Point) (_geometry_a), tolerance, relation, - progress_tracker); - break; - - default: - break; // warning fix - } + bRelation = typeAPoint(relation, progress_tracker, type_b, tolerance, bRelation, _geometry_a, _geometry_b); break; case Geometry.GeometryType.MultiPoint: - switch (type_b) { - case Geometry.GeometryType.Polygon: - bRelation = polygonRelateMultiPoint_((Polygon) (_geometry_b), - (MultiPoint) (_geometry_a), tolerance, relation, - progress_tracker); - break; - - case Geometry.GeometryType.Polyline: - bRelation = polylineRelateMultiPoint_((Polyline) (_geometry_b), - (MultiPoint) (_geometry_a), tolerance, relation, - progress_tracker); - break; - - case Geometry.GeometryType.MultiPoint: - bRelation = multiPointRelateMultiPoint_( - (MultiPoint) (_geometry_a), (MultiPoint) (_geometry_b), - tolerance, relation, progress_tracker); - break; - - case Geometry.GeometryType.Point: - bRelation = multiPointRelatePoint_((MultiPoint) (_geometry_a), - (Point) (_geometry_b), tolerance, relation, - progress_tracker); - break; - - case Geometry.GeometryType.Envelope: - bRelation = multiPointRelateEnvelope_( - (MultiPoint) (_geometry_a), (Envelope) (_geometry_b), - tolerance, relation, progress_tracker); - break; - - default: - break; // warning fix - } + bRelation = typeAMultiPoint(relation, progress_tracker, type_b, tolerance, bRelation, _geometry_a, + _geometry_b); break; case Geometry.GeometryType.Envelope: - switch (type_b) { - case Geometry.GeometryType.Polygon: - bRelation = polygonRelateEnvelope_((Polygon) (_geometry_b), - (Envelope) (_geometry_a), tolerance, relation, - progress_tracker); - break; - - case Geometry.GeometryType.Polyline: - bRelation = polylineRelateEnvelope_((Polyline) (_geometry_b), - (Envelope) (_geometry_a), tolerance, relation, - progress_tracker); - break; - - case Geometry.GeometryType.MultiPoint: - bRelation = multiPointRelateEnvelope_( - (MultiPoint) (_geometry_b), (Envelope) (_geometry_a), - tolerance, relation, progress_tracker); - break; - - default: - break; // warning fix - } + bRelation = typeAEnvelope(relation, progress_tracker, type_b, tolerance, bRelation, _geometry_a, + _geometry_b); break; default: break; // warning fix } + return bRelation; + } - return bRelation; - } + private static boolean typeAEnvelope(int relation, ProgressTracker progress_tracker, int type_b, double tolerance, + boolean bRelation, Geometry _geometry_a, Geometry _geometry_b) { + switch (type_b) { + case Geometry.GeometryType.Polygon: + bRelation = polygonRelateEnvelope_((Polygon) (_geometry_b), + (Envelope) (_geometry_a), tolerance, relation, + progress_tracker); + break; + + case Geometry.GeometryType.Polyline: + bRelation = polylineRelateEnvelope_((Polyline) (_geometry_b), + (Envelope) (_geometry_a), tolerance, relation, + progress_tracker); + break; + + case Geometry.GeometryType.MultiPoint: + bRelation = multiPointRelateEnvelope_( + (MultiPoint) (_geometry_b), (Envelope) (_geometry_a), + tolerance, relation, progress_tracker); + break; + + default: + break; // warning fix + } + return bRelation; + } + + private static boolean typeAMultiPoint(int relation, ProgressTracker progress_tracker, int type_b, double tolerance, + boolean bRelation, Geometry _geometry_a, Geometry _geometry_b) { + switch (type_b) { + case Geometry.GeometryType.Polygon: + bRelation = polygonRelateMultiPoint_((Polygon) (_geometry_b), + (MultiPoint) (_geometry_a), tolerance, relation, + progress_tracker); + break; + + case Geometry.GeometryType.Polyline: + bRelation = polylineRelateMultiPoint_((Polyline) (_geometry_b), + (MultiPoint) (_geometry_a), tolerance, relation, + progress_tracker); + break; + + case Geometry.GeometryType.MultiPoint: + bRelation = multiPointRelateMultiPoint_( + (MultiPoint) (_geometry_a), (MultiPoint) (_geometry_b), + tolerance, relation, progress_tracker); + break; + + case Geometry.GeometryType.Point: + bRelation = multiPointRelatePoint_((MultiPoint) (_geometry_a), + (Point) (_geometry_b), tolerance, relation, + progress_tracker); + break; + + case Geometry.GeometryType.Envelope: + bRelation = multiPointRelateEnvelope_( + (MultiPoint) (_geometry_a), (Envelope) (_geometry_b), + tolerance, relation, progress_tracker); + break; + + default: + break; // warning fix + } + return bRelation; + } + + private static boolean typeAPoint(int relation, ProgressTracker progress_tracker, int type_b, double tolerance, + boolean bRelation, Geometry _geometry_a, Geometry _geometry_b) { + switch (type_b) { + case Geometry.GeometryType.Polygon: + bRelation = polygonRelatePoint_((Polygon) (_geometry_b), + (Point) (_geometry_a), tolerance, relation, + progress_tracker); + break; + + case Geometry.GeometryType.Polyline: + bRelation = polylineRelatePoint_((Polyline) (_geometry_b), + (Point) (_geometry_a), tolerance, relation, + progress_tracker); + break; + + case Geometry.GeometryType.MultiPoint: + bRelation = multiPointRelatePoint_((MultiPoint) (_geometry_b), + (Point) (_geometry_a), tolerance, relation, + progress_tracker); + break; + + default: + break; // warning fix + } + return bRelation; + } + + private static boolean typeAPolyline(int relation, ProgressTracker progress_tracker, int type_b, double tolerance, + boolean bRelation, Geometry _geometry_a, Geometry _geometry_b) { + switch (type_b) { + case Geometry.GeometryType.Polygon: + bRelation = polygonRelatePolyline_((Polygon) (_geometry_b), + (Polyline) (_geometry_a), tolerance, relation, + progress_tracker); + break; + + case Geometry.GeometryType.Polyline: + bRelation = polylineRelatePolyline_((Polyline) (_geometry_a), + (Polyline) (_geometry_b), tolerance, relation, + progress_tracker); + break; + + case Geometry.GeometryType.Point: + bRelation = polylineRelatePoint_((Polyline) (_geometry_a), + (Point) (_geometry_b), tolerance, relation, + progress_tracker); + break; + + case Geometry.GeometryType.MultiPoint: + bRelation = polylineRelateMultiPoint_((Polyline) (_geometry_a), + (MultiPoint) (_geometry_b), tolerance, relation, + progress_tracker); + break; + + case Geometry.GeometryType.Envelope: + bRelation = polylineRelateEnvelope_((Polyline) (_geometry_a), + (Envelope) (_geometry_b), tolerance, relation, + progress_tracker); + break; + + default: + break; // warning fix + } + return bRelation; + } + + private static boolean typeAPolygon(int relation, ProgressTracker progress_tracker, int type_b, double tolerance, + boolean bRelation, Geometry _geometry_a, Geometry _geometry_b) { + switch (type_b) { + case Geometry.GeometryType.Polygon: + bRelation = polygonRelatePolygon_((Polygon) (_geometry_a), + (Polygon) (_geometry_b), tolerance, relation, + progress_tracker); + break; + + case Geometry.GeometryType.Polyline: + bRelation = polygonRelatePolyline_((Polygon) (_geometry_a), + (Polyline) (_geometry_b), tolerance, relation, + progress_tracker); + break; + + case Geometry.GeometryType.Point: + bRelation = polygonRelatePoint_((Polygon) (_geometry_a), + (Point) (_geometry_b), tolerance, relation, + progress_tracker); + break; + + case Geometry.GeometryType.MultiPoint: + bRelation = polygonRelateMultiPoint_((Polygon) (_geometry_a), + (MultiPoint) (_geometry_b), tolerance, relation, + progress_tracker); + break; + + case Geometry.GeometryType.Envelope: + bRelation = polygonRelateEnvelope_((Polygon) (_geometry_a), + (Envelope) (_geometry_b), tolerance, relation, + progress_tracker); + break; + + default: + break; // warning fix + } + return bRelation; + } // Computes the necessary 9 intersection relationships of boundary, // interior, and exterior of envelope_a vs envelope_b for the given diff --git a/src/test/java/com/esri/core/geometry/TestAttributeStreamOfDbl.java b/src/test/java/com/esri/core/geometry/TestAttributeStreamOfDbl.java new file mode 100644 index 00000000..efc039a5 --- /dev/null +++ b/src/test/java/com/esri/core/geometry/TestAttributeStreamOfDbl.java @@ -0,0 +1,88 @@ +package com.esri.core.geometry; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class TestAttributeStreamOfDbl { + + @Test + public void testWriteRangeForward() { + AttributeStreamOfDbl a = new AttributeStreamOfDbl(10); + a.write(0, -2); + a.write(1, -1); + a.write(2, 0); + a.write(3, 1); + a.write(4, 2); + a.write(5, 3); + a.write(6, 4); + a.write(7, 5); + a.write(8, 6); + a.write(9, 7); + + AttributeStreamOfDbl b = new AttributeStreamOfDbl(6, (short) 0); + + b.writeRange(0, 6, a, 3, true, 0); + for (int i = 0; i < 6; ++i) { + assertTrue(b.read(i) == i + 1); + + } + } + + @Test(expected = IllegalArgumentException.class) + public void testWithIllegalArgument() { + AttributeStreamOfDbl a = new AttributeStreamOfDbl(10); + AttributeStreamOfDbl b = new AttributeStreamOfDbl(10, (short) 0); + + b.writeRange(0, 5, a, 7, true, 0); + + } + + @Test + public void testWriteRangeBackWardStride1() { + AttributeStreamOfDbl a = new AttributeStreamOfDbl(10); + a.write(0, -2); + a.write(1, -1); + a.write(2, 0); + a.write(3, 1); + a.write(4, 2); + a.write(5, 3); + a.write(6, 4); + a.write(7, 5); + a.write(8, 6); + a.write(9, 7); + AttributeStreamOfDbl b = new AttributeStreamOfDbl(4, (short) 0); + + b.writeRange(0, 4, a, 6, false, 1); + for (int i = 0; i < 4; ++i) { + assertTrue(b.read(i) == 7 - i); + } + } + + @Test + public void testWriteRangeBackWardStride4() { + AttributeStreamOfDbl a = new AttributeStreamOfDbl(10); + a.write(0, -2); + a.write(1, -1); + a.write(2, 0); + a.write(3, 1); + a.write(4, 2); + a.write(5, 3); + a.write(6, 4); + a.write(7, 5); + a.write(8, 6); + a.write(9, 7); + AttributeStreamOfDbl b = new AttributeStreamOfDbl(10, (short) 0); + + b.writeRange(0, 6, a, 0, false, 3); + + assertTrue(b.read(0) == 1); + assertTrue(b.read(1) == 2); + assertTrue(b.read(2) == 3); + assertTrue(b.read(3) == -2); + assertTrue(b.read(4) == -1); + assertTrue(b.read(5) == 0); + + } + +} diff --git a/src/test/java/com/esri/core/geometry/TestAttributeStreamOfFloat_writeRange.java b/src/test/java/com/esri/core/geometry/TestAttributeStreamOfFloat_writeRange.java new file mode 100644 index 00000000..854aca69 --- /dev/null +++ b/src/test/java/com/esri/core/geometry/TestAttributeStreamOfFloat_writeRange.java @@ -0,0 +1,67 @@ +package com.esri.core.geometry; + +import static org.junit.Assert.*; + +import org.junit.Before; +import org.junit.Test; +/** + * WriteRange has complexity of 17 + * @author joele + */ +public class TestAttributeStreamOfFloat_writeRange { + + AttributeStreamOfFloat lc; + @Before + public void setUp() throws Exception { + lc = new AttributeStreamOfFloat(5,1); + } + + private float[] readBuffer(int size, int offset){ + float[] f = new float[size-offset]; + for(int i = offset,j=0; i < size; i++,j++){ + f[j] = lc.read(i); + } + return f; + } + + @Test(expected = IllegalArgumentException.class) + public void testIllegalArgs1(){ + lc.writeRange(-2, 1, null, 0, true, 0); //startelement < 0 should throw illegalargumentexception + } + + @Test(expected = IllegalArgumentException.class) + public void testIllegalArgs2(){ + lc.writeRange(5, 3, null, 0, false, 2); // !bForward and count%stride != 0, so should throw illegalargumentexception + } + + /** + * Write forwards + */ + @Test + public void testWrite1(){ + AttributeStreamOfFloat tmp = new AttributeStreamOfFloat(3,2); + float[] fl = {(float) 1.0,(float) 1.0,(float) 1.0,(float) 1.0,(float) 1.0}; + assertArrayEquals(readBuffer(5,0), fl, (float)0.1); + lc.writeRange(2, 2, tmp, 0, true, 1); //should change index 3 and 4 to 2 instead of 1 + float[] fl2 = {(float) 1.0,(float) 1.0,(float) 2.0,(float) 2.0,(float) 1.0}; + assertArrayEquals(readBuffer(5,0), fl2, (float)0.01); + } + + /** + * Write backwards + */ + @Test + public void testWrite2(){ + AttributeStreamOfFloat tmp = new AttributeStreamOfFloat(3,1); + tmp.write(0, (float)0); + tmp.write(1, (float)1); + tmp.write(2, (float)2); + float[] fl = {(float)2,(float)1,(float)0}; + lc = new AttributeStreamOfFloat(3); + lc.writeRange(0, 3, tmp, 0, false, 1); + assertArrayEquals(fl, readBuffer(3, 0), (float)0.01); + } + + + +} diff --git a/src/test/java/com/esri/core/geometry/TestAttributeStreamOfInt16.java b/src/test/java/com/esri/core/geometry/TestAttributeStreamOfInt16.java new file mode 100644 index 00000000..1b5648ff --- /dev/null +++ b/src/test/java/com/esri/core/geometry/TestAttributeStreamOfInt16.java @@ -0,0 +1,98 @@ +package com.esri.core.geometry; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class TestAttributeStreamOfInt16 { + + // HELPERS: + + private void checkEquality(AttributeStreamOfInt16 actual, short[] expected) { + assertEquals(actual.size(), expected.length); + for (int i = 0; i < actual.size(); i++) { + assertEquals(expected[i], actual.read(i)); + } + } + + private void writeValues(AttributeStreamOfInt16 actual, short[] values) { + assertEquals(actual.size(), values.length); + for (int i = 0; i < actual.size(); i++) { + actual.write(i, values[i]); + } + } + + // TESTS: + + /** + * Going forward, writing part of _src into different part of target. + */ + @Test + public void testWriteRange_forward() { + AttributeStreamOfInt16 target = new AttributeStreamOfInt16(8, (short)-1); + int startElement = 2; + int count = 5; + AttributeStreamOfInt16 _src = new AttributeStreamOfInt16(10); + int srcStart = 5; + boolean bForward = true; + int stride = 1; + writeValues(_src, new short[]{10, 11, 12, 13, 14, 15, 16, 17, 18, 19}); + + target.writeRange(startElement, count, _src, srcStart, bForward, stride); + checkEquality(target, new short[]{-1, -1, 15, 16, 17, 18, 19, -1}); + } + + /** + * Going backwards, writing part of _src into different part of target. + */ + @Test + public void testWriteRange_backward() { + AttributeStreamOfInt16 target = new AttributeStreamOfInt16(8, (short)-1); + int startElement = 2; + int count = 5; + AttributeStreamOfInt16 _src = new AttributeStreamOfInt16(10); + int srcStart = 5; + boolean bForward = false; + int stride = 1; + writeValues(_src, new short[]{10, 11, 12, 13, 14, 15, 16, 17, 18, 19}); + + target.writeRange(startElement, count, _src, srcStart, bForward, stride); + checkEquality(target, new short[]{-1, -1, 19, 18, 17, 16, 15, -1}); + } + + /** + * Going backwards, writing part of _src into different part of target, with a stride over 1. + */ + @Test + public void testWriteRange_backward_stride() { + AttributeStreamOfInt16 target = new AttributeStreamOfInt16(10, (short)-1); + int startElement = 1; + int count = 9; + AttributeStreamOfInt16 _src = new AttributeStreamOfInt16(10); + int srcStart = 0; + boolean bForward = false; + int stride = 3; + writeValues(_src, new short[]{10, 11, 12, 13, 14, 15, 16, 17, 18, 19}); + + target.writeRange(startElement, count, _src, srcStart, bForward, stride); + checkEquality(target, new short[]{-1, 16, 17, 18, 13, 14, 15, 10, 11, 12}); + } + + /** + * Writing into self. + */ + @Test + public void testWriteRange_self() { + AttributeStreamOfInt16 target = new AttributeStreamOfInt16(10); + int startElement = 1; + int count = 5; + int srcStart = 3; + boolean bForward = true; + int stride = 1; + writeValues(target, new short[]{10, 11, 12, 13, 14, 15, 16, 17, 18, 19}); + + target.writeRange(startElement, count, target, srcStart, bForward, stride); + checkEquality(target, new short[]{10, 13, 14, 15, 16, 17, 16, 17, 18, 19}); + } + +} \ No newline at end of file diff --git a/src/test/java/com/esri/core/geometry/TestGeodetic.java b/src/test/java/com/esri/core/geometry/TestGeodetic.java index 93185af9..03bf54e3 100644 --- a/src/test/java/com/esri/core/geometry/TestGeodetic.java +++ b/src/test/java/com/esri/core/geometry/TestGeodetic.java @@ -29,6 +29,8 @@ import org.junit.Test; public class TestGeodetic extends TestCase { + private static final double PE_PI2 = 1.57079632679489661923132*180/Math.PI; + @Override protected void setUp() throws Exception { super.setUp(); @@ -74,6 +76,45 @@ public void testRotationInvariance() { } } + @Test + public void testSamePoints() { + Point p1 = new Point(119.13731666666666, PE_PI2); + Point p2 = new Point(119.13731666666666, PE_PI2); + double d = GeometryEngine.geodesicDistanceOnWGS84(p1, p2); + assertTrue(d == 0); + } + + @Test + public void testOppositeLatitude() { + + Point p1 = new Point(119.13731666666666, PE_PI2); + Point p2 = new Point(119.13731666666666, -PE_PI2); + double d = GeometryEngine.geodesicDistanceOnWGS84(p1, p2); + assertTrue(d == 2.0003931458625443E7); + } + @Test + public void testOppositeLongitude() { + + Point p1 = new Point(PE_PI2, -30); + Point p2 = new Point(-PE_PI2, 30); + double d = GeometryEngine.geodesicDistanceOnWGS84(p1, p2); + assertTrue(d == 2.0003931458625443E7); + } + + @Test + public void testDistanceOnSphere() { + double a = 60.0; // radius of spheroid for WGS_1984 + double e2 = 0.0; // ellipticity for WGS_1984 + double rpu = Math.PI / 180.0; + PeDouble answer = new PeDouble(); + Point p1 = new Point(60, 30); + Point p2 = new Point(30, 60); + GeoDist.geodesic_distance_ngs(a, e2, p1.getX() * rpu, + p1.getY() * rpu, p2.getX() * rpu, p2.getY() + * rpu, answer, null, null); + assertTrue(answer.val == 37.80150789746255); + } + @Test public void testDistanceFailure() { { @@ -104,7 +145,7 @@ public void testDistanceFailure() { assertTrue(Math.abs(d - 19964450.206594173) < 1e-12 * 19964450.206594173); } } - + @Test public void testLengthAccurateCR191313() { /* @@ -117,7 +158,7 @@ public void testLengthAccurateCR191313() { * //[6097817.59407673 * ,17463475.2931517],[-1168053.34617516,11199801.3734424 * ]]],"spatialReference":{"wkid":102631} - * + * * Polyline polyline = new Polyline(); * polyline.startPath(6097817.59407673, 17463475.2931517); * polyline.lineTo(-1168053.34617516, 11199801.3734424); double length = @@ -125,5 +166,5 @@ public void testLengthAccurateCR191313() { * assertTrue(Math.abs(length - 2738362.3249366437) < 2e-9 * length); */ } - + }