ayushtkn commented on code in PR #6581: URL: https://github.com/apache/hive/pull/6581#discussion_r3653185125
########## ql/src/test/org/apache/hadoop/hive/ql/udf/esri/TestEsriShapeConverter.java: ########## @@ -0,0 +1,366 @@ +/* + * 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.hadoop.hive.ql.udf.esri; + +import org.apache.hadoop.io.BytesWritable; +import org.junit.Test; +import org.locationtech.jts.algorithm.Orientation; +import org.locationtech.jts.geom.Geometry; +import org.locationtech.jts.geom.LineString; +import org.locationtech.jts.geom.MultiLineString; +import org.locationtech.jts.geom.MultiPoint; +import org.locationtech.jts.geom.MultiPolygon; +import org.locationtech.jts.geom.Point; +import org.locationtech.jts.geom.Polygon; +import org.locationtech.jts.io.ParseException; +import org.locationtech.jts.io.WKTReader; + +import java.nio.ByteBuffer; +import java.nio.ByteOrder; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThrows; +import static org.junit.Assert.assertTrue; + +public class TestEsriShapeConverter { + + private static final double EPSILON = 1e-9; + + private static final WKTReader WKT_READER = new WKTReader(GeometryUtils.GEOMETRY_FACTORY); + + private static Geometry wkt(String text) throws ParseException { + return WKT_READER.read(text); + } + + private static Geometry roundTrip(String text) throws ParseException { + Geometry geom = wkt(text); + byte[] shape = EsriShapeConverter.toEsriShape(geom); + Geometry back = EsriShapeConverter.fromEsriShapeBody(ByteBuffer.wrap(shape)); + assertNotNull("Round-trip of " + text + " must not be null!", back); + return back; + } + + /** + * Asserts coordinate-level equality after canonicalizing both geometries with + * {@link Geometry#normalize()}. Unlike {@code equalsTopo}, this catches ring reordering, + * ring/hole misassignment and orientation bugs (normalize fixes orientation and vertex + * order, so anything left is a real coordinate difference). + */ + private static void assertEqualsNormalized(Geometry expected, Geometry actual) { + Geometry e = expected.copy(); + Geometry a = actual.copy(); + e.normalize(); Review Comment: Dropped normalization. Round-trip checks now use equalsExact(expected, actual, EPSILON) directly, so coordinate order and ring orientation must be preserved. -- 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]
