github-advanced-security[bot] commented on code in PR #16029:
URL: https://github.com/apache/druid/pull/16029#discussion_r1520486780


##########
processing/src/test/java/org/apache/druid/collections/spatial/search/RectangularBoundTest.java:
##########
@@ -31,23 +33,84 @@
   public void testCacheKey()
   {
     Assert.assertArrayEquals(
-        new RectangularBound(new float[]{1F, 1F}, new float[]{2F, 2F}, 
1).getCacheKey(),
-        new RectangularBound(new float[]{1F, 1F}, new float[]{2F, 2F}, 
1).getCacheKey()
+        new RectangularBound(new double[]{1F, 1F}, new double[]{2F, 2F}, 
1).getCacheKey(),
+        new RectangularBound(new double[]{1F, 1F}, new double[]{2F, 2F}, 
1).getCacheKey()
     );
     Assert.assertFalse(Arrays.equals(
-        new RectangularBound(new float[]{1F, 1F}, new float[]{2F, 2F}, 
1).getCacheKey(),
-        new RectangularBound(new float[]{1F, 1F}, new float[]{2F, 3F}, 
1).getCacheKey()
+        new RectangularBound(new double[]{1F, 1F}, new double[]{2F, 2F}, 
1).getCacheKey(),
+        new RectangularBound(new double[]{1F, 1F}, new double[]{2F, 3F}, 
1).getCacheKey()
     ));
     Assert.assertFalse(Arrays.equals(
-        new RectangularBound(new float[]{1F, 1F}, new float[]{2F, 2F}, 
1).getCacheKey(),
-        new RectangularBound(new float[]{1F, 0F}, new float[]{2F, 2F}, 
1).getCacheKey()
+        new RectangularBound(new double[]{1F, 1F}, new double[]{2F, 2F}, 
1).getCacheKey(),
+        new RectangularBound(new double[]{1F, 0F}, new double[]{2F, 2F}, 
1).getCacheKey()
     ));
     Assert.assertFalse(Arrays.equals(
-        new RectangularBound(new float[]{1F, 1F}, new float[]{2F, 2F}, 
1).getCacheKey(),
-        new RectangularBound(new float[]{1F, 1F}, new float[]{2F, 2F}, 
2).getCacheKey()
+        new RectangularBound(new double[]{1F, 1F}, new double[]{2F, 2F}, 
1).getCacheKey(),
+        new RectangularBound(new double[]{1F, 1F}, new double[]{2F, 2F}, 
2).getCacheKey()
     ));
   }
 
+  @Test
+  public void testRectangularBound()
+  {
+    double[][] insidePoints = new double[][]{
+        {37.795717853074635, -122.40906979480418},
+        {37.79625791859653, -122.39638788940042},
+        {37.79685798676811, -122.39335030726777},
+        {37.7966179600844, -122.39798262002006}
+    };
+    double[][] outsidePoints = new double[][]{
+        {37.79805810848854, -122.39236309307468},
+        {37.78197485768925, -122.41886599718191},
+        {37.798298130492945, -122.39608413118715},
+        {37.783595343766216, -122.41932163450181}
+    };
+    RectangularBound rectangularBound = new RectangularBound(
+        new double[]{37.78185482027019, -122.41795472254213},
+        new double[]{37.797638168104185, -122.39228715352137},
+        10
+    );
+    for (double[] insidePoint : insidePoints) {
+      Assert.assertTrue(rectangularBound.containsDouble(insidePoint));
+      float[] floatPoint = new float[]{
+          Float.parseFloat(String.valueOf(insidePoint[0])),

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/6994)



##########
processing/src/test/java/org/apache/druid/collections/spatial/search/RadiusBoundTest.java:
##########
@@ -48,4 +95,137 @@
         new RadiusBound(coords0, 3.0F, 9).getCacheKey()
     ));
   }
+
+  @Test
+  public void testContains()
+  {
+    double circleCenterLat = 12.3456789;
+    double circleCenterLon = 45.6789012;
+    float circleRadius = 500.0f; // Radius in meters
+    int numberOfPoints = 1000;
+
+    double[] center = new double[]{circleCenterLat, circleCenterLon};
+    Bound bound = new RadiusBound(center, circleRadius, 
RadiusBound.RadiusUnit.meters, 100);
+
+    double[][] geoInsidePoints = generateGeoCoordinatesAroundCircle(
+        circleCenterLat,
+        circleCenterLon,
+        circleRadius,
+        numberOfPoints,
+        true
+    );
+
+    for (double[] geoPoint : geoInsidePoints) {
+      double distance = RTreeUtils.calculateHaversineDistance(geoPoint, 
center);
+      Assert.assertTrue(distance < circleRadius);
+      Assert.assertTrue(bound.containsDouble(geoPoint));
+      float[] floatPoint = new float[]{
+          Float.parseFloat(String.valueOf(geoPoint[0])),

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/6996)



##########
processing/src/test/java/org/apache/druid/collections/spatial/search/RadiusBoundTest.java:
##########
@@ -48,4 +95,137 @@
         new RadiusBound(coords0, 3.0F, 9).getCacheKey()
     ));
   }
+
+  @Test
+  public void testContains()
+  {
+    double circleCenterLat = 12.3456789;
+    double circleCenterLon = 45.6789012;
+    float circleRadius = 500.0f; // Radius in meters
+    int numberOfPoints = 1000;
+
+    double[] center = new double[]{circleCenterLat, circleCenterLon};
+    Bound bound = new RadiusBound(center, circleRadius, 
RadiusBound.RadiusUnit.meters, 100);
+
+    double[][] geoInsidePoints = generateGeoCoordinatesAroundCircle(
+        circleCenterLat,
+        circleCenterLon,
+        circleRadius,
+        numberOfPoints,
+        true
+    );
+
+    for (double[] geoPoint : geoInsidePoints) {
+      double distance = RTreeUtils.calculateHaversineDistance(geoPoint, 
center);
+      Assert.assertTrue(distance < circleRadius);
+      Assert.assertTrue(bound.containsDouble(geoPoint));
+      float[] floatPoint = new float[]{
+          Float.parseFloat(String.valueOf(geoPoint[0])),
+          Float.parseFloat(String.valueOf(geoPoint[1]))
+      };
+      Assert.assertTrue(bound.contains(floatPoint));
+    }
+
+    Iterable<ImmutableDoublePoint> points = Arrays.stream(geoInsidePoints)
+                                                  
.map(TestHPImmutablePoint::new)
+                                                  
.collect(Collectors.toList());
+    Iterable<ImmutableDoublePoint> result = bound.highPrecisionfilter(points);
+    Assert.assertEquals(Lists.newArrayList(result), points);
+
+    double[][] geoOutsidePoints = generateGeoCoordinatesAroundCircle(
+        circleCenterLat,
+        circleCenterLon,
+        circleRadius,
+        numberOfPoints,
+        false
+    );
+
+    for (double[] geoPoint : geoOutsidePoints) {
+      System.out.println(Arrays.toString(geoPoint));
+      double haversineDistance = calculateHaversineDistance(geoPoint, center);
+      Assert.assertTrue(haversineDistance > circleRadius); // asserts that 
point is outside
+      Assert.assertFalse(bound.containsDouble(geoPoint));
+      float[] floatPoint = new float[]{
+          Float.parseFloat(String.valueOf(geoPoint[0])),

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/6997)



##########
processing/src/test/java/org/apache/druid/collections/spatial/search/RectangularBoundTest.java:
##########
@@ -31,23 +33,84 @@
   public void testCacheKey()
   {
     Assert.assertArrayEquals(
-        new RectangularBound(new float[]{1F, 1F}, new float[]{2F, 2F}, 
1).getCacheKey(),
-        new RectangularBound(new float[]{1F, 1F}, new float[]{2F, 2F}, 
1).getCacheKey()
+        new RectangularBound(new double[]{1F, 1F}, new double[]{2F, 2F}, 
1).getCacheKey(),
+        new RectangularBound(new double[]{1F, 1F}, new double[]{2F, 2F}, 
1).getCacheKey()
     );
     Assert.assertFalse(Arrays.equals(
-        new RectangularBound(new float[]{1F, 1F}, new float[]{2F, 2F}, 
1).getCacheKey(),
-        new RectangularBound(new float[]{1F, 1F}, new float[]{2F, 3F}, 
1).getCacheKey()
+        new RectangularBound(new double[]{1F, 1F}, new double[]{2F, 2F}, 
1).getCacheKey(),
+        new RectangularBound(new double[]{1F, 1F}, new double[]{2F, 3F}, 
1).getCacheKey()
     ));
     Assert.assertFalse(Arrays.equals(
-        new RectangularBound(new float[]{1F, 1F}, new float[]{2F, 2F}, 
1).getCacheKey(),
-        new RectangularBound(new float[]{1F, 0F}, new float[]{2F, 2F}, 
1).getCacheKey()
+        new RectangularBound(new double[]{1F, 1F}, new double[]{2F, 2F}, 
1).getCacheKey(),
+        new RectangularBound(new double[]{1F, 0F}, new double[]{2F, 2F}, 
1).getCacheKey()
     ));
     Assert.assertFalse(Arrays.equals(
-        new RectangularBound(new float[]{1F, 1F}, new float[]{2F, 2F}, 
1).getCacheKey(),
-        new RectangularBound(new float[]{1F, 1F}, new float[]{2F, 2F}, 
2).getCacheKey()
+        new RectangularBound(new double[]{1F, 1F}, new double[]{2F, 2F}, 
1).getCacheKey(),
+        new RectangularBound(new double[]{1F, 1F}, new double[]{2F, 2F}, 
2).getCacheKey()
     ));
   }
 
+  @Test
+  public void testRectangularBound()
+  {
+    double[][] insidePoints = new double[][]{
+        {37.795717853074635, -122.40906979480418},
+        {37.79625791859653, -122.39638788940042},
+        {37.79685798676811, -122.39335030726777},
+        {37.7966179600844, -122.39798262002006}
+    };
+    double[][] outsidePoints = new double[][]{
+        {37.79805810848854, -122.39236309307468},
+        {37.78197485768925, -122.41886599718191},
+        {37.798298130492945, -122.39608413118715},
+        {37.783595343766216, -122.41932163450181}
+    };
+    RectangularBound rectangularBound = new RectangularBound(
+        new double[]{37.78185482027019, -122.41795472254213},
+        new double[]{37.797638168104185, -122.39228715352137},
+        10
+    );
+    for (double[] insidePoint : insidePoints) {
+      Assert.assertTrue(rectangularBound.containsDouble(insidePoint));
+      float[] floatPoint = new float[]{
+          Float.parseFloat(String.valueOf(insidePoint[0])),
+          Float.parseFloat(String.valueOf(insidePoint[1]))
+      };
+      Assert.assertTrue(rectangularBound.contains(floatPoint));
+    }
+    for (double[] outsidePoint : outsidePoints) {
+      float[] floatPoint = new float[]{
+          Float.parseFloat(String.valueOf(outsidePoint[0])),

Review Comment:
   ## Missing catch of NumberFormatException
   
   Potential uncaught 'java.lang.NumberFormatException'.
   
   [Show more 
details](https://github.com/apache/druid/security/code-scanning/6995)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org
For additional commands, e-mail: commits-h...@druid.apache.org

Reply via email to