jpountz commented on a change in pull request #927: LUCENE-8997: : Add type of 
triangle info to ShapeField encoding
URL: https://github.com/apache/lucene-solr/pull/927#discussion_r362770851
 
 

 ##########
 File path: lucene/sandbox/src/java/org/apache/lucene/document/ShapeField.java
 ##########
 @@ -260,111 +379,249 @@ public static void encodeTriangle(byte[] bytes, int 
aLat, int aLon, boolean abFr
   /** Decode a triangle encoded by {@link ShapeField#encodeTriangle(byte[], 
int, int, boolean, int, int, boolean, int, int, boolean)}.
    */
   public static void decodeTriangle(byte[] t, DecodedTriangle triangle) {
-    final int aX, aY, bX, bY, cX, cY;
-    final boolean ab, bc, ca;
-    int bits = NumericUtils.sortableBytesToInt(t, 6 * BYTES);
-    //extract the first three bits
+    final int bits = NumericUtils.sortableBytesToInt(t, 6 * BYTES);
+    final boolean bit6 = (bits & 1 << 6) == 1 << 6;
+    final boolean bit7 = (bits & 1 << 7) == 1 << 7;
+    if (bit6) {
+      if (bit7) {
+        triangle.type = DecodedTriangle.TYPE.TRIANGLE;
+        decodeTriangle(t, triangle, bits);
+      } else {
+        triangle.type = DecodedTriangle.TYPE.POINT;
+        decodePoint(t,  triangle);
+      }
+    } else if (bit7) {
+      triangle.type = DecodedTriangle.TYPE.LINE;
+      decodeLine(t, triangle, bits);
+    } else {
+      // for backwards compatibility
+      triangle.type = DecodedTriangle.TYPE.UNKNOWN;
+      decodeTriangle(t, triangle, bits);
+    }
 
 Review comment:
   Let's read the two bits at once? E.g.
   
   ```java
   final int typeBits = (bits >>> 6) & 0x03;
   switch (typeBits) {
     case 0:
       triangle.type = DecodedTriangle.TYPE.UNKNOWN;
       decodeTriangle(t, triangle, bits);
       break; 
     [...]
     case 3:
       triangle.type = DecodedTriangle.TYPE.TRIANGLE;
       decodeTriangle(t, triangle, bits);
       break;
   }
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to