Skip to content

Commit

Permalink
track the offset of the BytesRef passed to the tree reader (#52704)
Browse files Browse the repository at this point in the history
  • Loading branch information
iverase authored and talevy committed Feb 24, 2020
1 parent 52ad35a commit 15e3b70
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class TriangleTreeReader {
private final Tile2D tile2D;
private final Extent extent;
private int treeOffset;
private int docValueOffset;

public TriangleTreeReader(CoordinateEncoder coordinateEncoder) {
this.coordinateEncoder = coordinateEncoder;
Expand All @@ -66,6 +67,7 @@ public TriangleTreeReader(CoordinateEncoder coordinateEncoder) {

public void reset(BytesRef bytesRef) throws IOException {
this.input.reset(bytesRef.bytes, bytesRef.offset, bytesRef.length);
docValueOffset = bytesRef.offset;
treeOffset = 0;
}

Expand All @@ -87,25 +89,25 @@ public Extent getExtent() {
* returns the X coordinate of the centroid.
*/
public double getCentroidX() {
input.setPosition(0);
input.setPosition(docValueOffset + 0);
return coordinateEncoder.decodeX(input.readInt());
}

/**
* returns the Y coordinate of the centroid.
*/
public double getCentroidY() {
input.setPosition(4);
input.setPosition(docValueOffset + 4);
return coordinateEncoder.decodeY(input.readInt());
}

public DimensionalShapeType getDimensionalShapeType() {
input.setPosition(8);
input.setPosition(docValueOffset + 8);
return DimensionalShapeType.readFrom(input);
}

public double getSumCentroidWeight() {
input.setPosition(9);
input.setPosition(docValueOffset + 9);
return Double.longBitsToDouble(input.readVLong());
}

Expand Down

0 comments on commit 15e3b70

Please sign in to comment.