LorenzBuehmann commented on issue #2219:
URL: https://github.com/apache/jena/issues/2219#issuecomment-1914140416

   I don't see any negative implications, for me this is just fixing a bug - 
indeed I might be wrong.
   
   The crucial part in JTS is in class 
   
   Here they do
   
   ``` java
   private void checkIntersectionWithSegments(LineString testLine)
     {
       CoordinateSequence seq1 = testLine.getCoordinateSequence();
       Coordinate p0 = seq1.createCoordinate();
       Coordinate p1 = seq1.createCoordinate();
       for (int j = 1; j < seq1.size(); j++) {
         seq1.getCoordinate(j - 1, p0);
         seq1.getCoordinate(j,     p1);
   
         if (rectIntersector.intersects(p0, p1)) {
           hasIntersection = true;
           return;
         }
       }
     }
   ```
   the creation of new `Coordinates` comes from the default method in the 
`CoordinateSequence` interface and does nothing more than taking into account 
the dimensions of coordinate and the measure:
   
   ``` java
   default Coordinate createCoordinate() {
       return Coordinates.create(getDimension(), getMeasures());
     }
   ```
   
   Both are implemented in `CustomCoordinateSequence` correctly, i.e. the 
dimension is 2 and measures is 0. 
   I'm sure it was simply forgotten to do a sanity check in the `getCoordinate` 
method
   
   ``` java
   @Override
       public void getCoordinate(int index, Coordinate coord) {
           coord.setX(x[index]);
           coord.setY(y[index]);
           coord.setZ(z[index]);
       }
   ``` 
   and by the way for some reason `setM` was not called - maybe also forgotten.
   In any case checking for either the class type or just the dimension should 
be the correct way in my opinion.
   So either explicitly check for the Java type or for combination of 
dimension/measure should at least fix the error. In JTS they do it by
   
   ``` java
   public static Coordinate create(int dimension, int measures)
     {
       if (dimension == 2) {
         return new CoordinateXY();
       } else if (dimension == 3 && measures == 0) {
         return new Coordinate();
       } else if (dimension == 3 && measures == 1) {
         return new CoordinateXYM();
       } else if (dimension == 4 && measures == 1) {
         return new CoordinateXYZM();
       }
       return new Coordinate();
     }
   ```
   It's confusing how JTS does handle the case `dim=3` and `measure=1` as Z 
seems to be ignored: 
   > This data object is suitable for use with coordinate sequences with 
dimension = 3 and measures = 1.
   The Coordinate.z field is visible, but intended to be ignored
   
   
   Long story short, we could adapt this with
   ``` java
   @Override
       public void getCoordinate(int index, Coordinate coord) {
           coord.setX(x[index]);
           coord.setY(y[index]);
   
           if (coordinateDimension == 3 && measuresDimension == 0) {
               coord.setZ(z[index]);
           } else if (coordinateDimension == 3 && measuresDimension == 1) {
               coord.setM(m[index]);
           } else if (coordinateDimension == 4 && measuresDimension == 1) {
               coord.setZ(z[index]);
               coord.setM(m[index]);
           }
       }
   
   ```
   
   
   Opinions?
   
   


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

Reply via email to