jiayuasu commented on code in PR #2811:
URL: https://github.com/apache/sedona/pull/2811#discussion_r3020985925


##########
docs/api/sql/Geometry-Processing/ST_OffsetCurve.md:
##########
@@ -0,0 +1,54 @@
+<!--
+ 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.
+ -->
+
+# ST_OffsetCurve
+
+![ST_OffsetCurve](../../../image/ST_OffsetCurve/ST_OffsetCurve.svg 
"ST_OffsetCurve")
+
+Introduction: Returns a line at a given offset distance from a linear 
geometry. If the distance is positive, the offset is on the left side of the 
input line; if it is negative, it is on the right side. Returns null for empty 
geometries.
+
+The optional third parameter `quadrantSegments` controls the number of line 
segments used to approximate a quarter circle at round joins. The default value 
is 8.
+
+Format: `ST_OffsetCurve(geometry: Geometry, distance: Double, 
quadrantSegments: Integer)`
+
+Format: `ST_OffsetCurve(geometry: Geometry, distance: Double)`

Review Comment:
   Consolidated into a single optional-parameter format and switched to fenced 
output blocks.



##########
docs/api/flink/Geometry-Processing/ST_OffsetCurve.md:
##########
@@ -0,0 +1,52 @@
+<!--
+ 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.
+ -->
+
+# ST_OffsetCurve
+
+Introduction: Returns a line at a given offset distance from a linear 
geometry. If the distance is positive, the offset is on the left side of the 
input line; if it is negative, it is on the right side. Returns null for empty 
geometries.
+
+The optional third parameter `quadrantSegments` controls the number of line 
segments used to approximate a quarter circle at round joins. The default value 
is 8.
+
+Format: `ST_OffsetCurve(geometry: Geometry, distance: Double, 
quadrantSegments: Integer)`
+
+Format: `ST_OffsetCurve(geometry: Geometry, distance: Double)`
+
+Return type: `Geometry`

Review Comment:
   Same fix applied here.



##########
common/src/main/java/org/apache/sedona/common/Functions.java:
##########
@@ -424,6 +425,20 @@ else if 
(singleParam[0].equalsIgnoreCase(listBufferParameters[5])) {
     return bufferParameters;
   }
 
+  public static Geometry offsetCurve(Geometry geometry, double distance) {
+    return offsetCurve(geometry, distance, 
BufferParameters.DEFAULT_QUADRANT_SEGMENTS);
+  }
+
+  public static Geometry offsetCurve(Geometry geometry, double distance, int 
quadrantSegments) {
+    if (geometry.isEmpty()) {
+      return null;
+    }
+    BufferParameters bufferParameters = new BufferParameters();
+    bufferParameters.setQuadrantSegments(quadrantSegments);
+    OffsetCurve oc = new OffsetCurve(geometry, distance, bufferParameters);
+    return oc.getCurve();

Review Comment:
   Spark/Flink expressions null-short-circuit before reaching these Java 
functions. The existing codebase is inconsistent about this — some functions 
have the null guard, some don't. Not changing it here to stay consistent with 
the surrounding code.



##########
snowflake-tester/src/test/java/org/apache/sedona/snowflake/snowsql/TestFunctions.java:
##########
@@ -768,6 +768,19 @@ public void test_ST_NPoints() {
         "select sedona.ST_NPoints(sedona.ST_GeomFromText('LINESTRING(1 2, 3 4, 
5 6)'))", 3);
   }
 
+  @Test
+  public void test_ST_OffsetCurve() {
+    registerUDF("ST_OffsetCurve", byte[].class, double.class);
+    verifySqlSingleRes(
+        "select 
sedona.ST_AsText(sedona.ST_OffsetCurve(sedona.ST_GeomFromText('LINESTRING(0 0, 
10 0)'), 5.0))",
+        "LINESTRING (0 5, 10 5)");
+    registerUDF("ST_OffsetCurve", byte[].class, double.class, int.class);
+    registerUDF("ST_NPoints", byte[].class);
+    verifySqlSingleRes(
+        "select 
sedona.ST_NPoints(sedona.ST_OffsetCurve(sedona.ST_GeomFromText('LINESTRING(0 0, 
10 0, 10 10)'), -3.0, 16))",
+        19);

Review Comment:
   Changed to a relative comparison using Snowflake's `iff()` to assert qs=16 
produces more points than the default.



##########
snowflake-tester/src/test/java/org/apache/sedona/snowflake/snowsql/TestFunctionsV2.java:
##########
@@ -716,6 +716,19 @@ public void test_ST_NPoints() {
         "select sedona.ST_NPoints(ST_GeometryFromWKT('LINESTRING(1 2, 3 4, 5 
6)'))", 3);
   }
 
+  @Test
+  public void test_ST_OffsetCurve() {
+    registerUDFV2("ST_OffsetCurve", String.class, double.class);
+    verifySqlSingleRes(
+        "select 
sedona.ST_AsText(sedona.ST_OffsetCurve(ST_GeometryFromWKT('LINESTRING(0 0, 10 
0)'), 5.0))",
+        "LINESTRING (0 5, 10 5)");
+    registerUDFV2("ST_OffsetCurve", String.class, double.class, int.class);
+    registerUDFV2("ST_NPoints", String.class);
+    verifySqlSingleRes(
+        "select 
sedona.ST_NPoints(sedona.ST_OffsetCurve(ST_GeometryFromWKT('LINESTRING(0 0, 10 
0, 10 10)'), -3.0, 16))",
+        19);

Review Comment:
   Same fix applied here.



-- 
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]

Reply via email to