Kontinuation commented on code in PR #12667: URL: https://github.com/apache/iceberg/pull/12667#discussion_r2454316884
########## api/src/main/java/org/apache/iceberg/geospatial/GeospatialPredicateEvaluators.java: ########## @@ -0,0 +1,214 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.iceberg.geospatial; + +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; +import org.apache.iceberg.types.Type; +import org.apache.iceberg.types.Types; + +public class GeospatialPredicateEvaluators { + private GeospatialPredicateEvaluators() {} + + public interface GeospatialPredicateEvaluator { + /** + * Determines whether the two bounding boxes intersect. + * + * @param bbox1 the first bounding box + * @param bbox2 the second bounding box + * @return true if this box intersects the other box + */ + boolean intersects(BoundingBox bbox1, BoundingBox bbox2); + } + + /** + * Create an evaluator for evaluating bounding box relationship for the given geospatial type. + * + * @param type the geospatial type, should be one of Type.TypeID.GEOMETRY or Type.TypeID.GEOGRAPHY + * @return the evaluator + */ + public static GeospatialPredicateEvaluator create(Type type) { + switch (type.typeId()) { + case GEOMETRY: + return create((Types.GeometryType) type); + case GEOGRAPHY: + return create((Types.GeographyType) type); + default: + throw new UnsupportedOperationException("Unsupported type for BoundingBox: " + type); + } + } + + /** + * Create an evaluator for evaluating bounding box relationship for planar geometries + * + * @return the evaluator + */ + public static GeometryEvaluator create(Types.GeometryType type) { + return new GeometryEvaluator(); + } + + /** + * Create an evaluator for evaluating bounding box relationship for geographies + * + * @return the evaluator + */ + public static GeographyEvaluator create(Types.GeographyType type) { + return new GeographyEvaluator(); + } + + public static class GeometryEvaluator implements GeospatialPredicateEvaluator { + + /** + * Check if two bounding boxes intersect + * + * @param bbox1 the first bounding box + * @param bbox2 the second bounding box + * @return true if the bounding boxes intersect + */ + @Override + public boolean intersects(BoundingBox bbox1, BoundingBox bbox2) { + if (!intersectsYZM(bbox1, bbox2)) { + return false; + } + + // Check X dimension (longitude/easting) - no wrap-around + return rangeIntersects(bbox1.min().x(), bbox1.max().x(), bbox2.min().x(), bbox2.max().x()); + } + + static boolean intersectsYZM(BoundingBox bbox1, BoundingBox bbox2) { Review Comment: Good idea. Now it looks much better. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
