提交 c7830320 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Use new methods in EWKBUtils

上级 b796adb9
...@@ -160,7 +160,7 @@ public final class EWKBUtils { ...@@ -160,7 +160,7 @@ public final class EWKBUtils {
private void writeDouble(double v) { private void writeDouble(double v) {
v = toCanonicalDouble(v); v = toCanonicalDouble(v);
Bits.writeLong(buf, 0, Double.doubleToRawLongBits(v)); Bits.writeDouble(buf, 0, v);
output.write(buf, 0, 8); output.write(buf, 0, 8);
} }
...@@ -204,9 +204,9 @@ public final class EWKBUtils { ...@@ -204,9 +204,9 @@ public final class EWKBUtils {
* @return next 32-bit integer * @return next 32-bit integer
*/ */
int readInt() { int readInt() {
int result = Bits.readInt(ewkb, offset); int result = bigEndian ? Bits.readInt(ewkb, offset) : Bits.readIntLE(ewkb, offset);
offset += 4; offset += 4;
return bigEndian ? result : Integer.reverseBytes(result); return result;
} }
/** /**
...@@ -215,12 +215,9 @@ public final class EWKBUtils { ...@@ -215,12 +215,9 @@ public final class EWKBUtils {
* @return next 64-bit floating point * @return next 64-bit floating point
*/ */
double readCoordinate() { double readCoordinate() {
long v = Bits.readLong(ewkb, offset); double v = bigEndian ? Bits.readDouble(ewkb, offset) : Bits.readDoubleLE(ewkb, offset);
offset += 8; offset += 8;
if (!bigEndian) { return toCanonicalDouble(v);
v = Long.reverseBytes(v);
}
return toCanonicalDouble(Double.longBitsToDouble(v));
} }
@Override @Override
...@@ -470,31 +467,31 @@ public final class EWKBUtils { ...@@ -470,31 +467,31 @@ public final class EWKBUtils {
if (minX == maxX && minY == maxY) { if (minX == maxX && minY == maxY) {
result = new byte[21]; result = new byte[21];
result[4] = POINT; result[4] = POINT;
Bits.writeLong(result, 5, Double.doubleToRawLongBits(minX)); Bits.writeDouble(result, 5, minX);
Bits.writeLong(result, 13, Double.doubleToRawLongBits(minY)); Bits.writeDouble(result, 13, minY);
} else if (minX == maxX || minY == maxY) { } else if (minX == maxX || minY == maxY) {
result = new byte[41]; result = new byte[41];
result[4] = LINE_STRING; result[4] = LINE_STRING;
result[8] = 2; result[8] = 2;
Bits.writeLong(result, 9, Double.doubleToRawLongBits(minX)); Bits.writeDouble(result, 9, minX);
Bits.writeLong(result, 17, Double.doubleToRawLongBits(minY)); Bits.writeDouble(result, 17, minY);
Bits.writeLong(result, 25, Double.doubleToRawLongBits(maxX)); Bits.writeDouble(result, 25, maxX);
Bits.writeLong(result, 33, Double.doubleToRawLongBits(maxY)); Bits.writeDouble(result, 33, maxY);
} else { } else {
result = new byte[93]; result = new byte[93];
result[4] = POLYGON; result[4] = POLYGON;
result[8] = 1; result[8] = 1;
result[12] = 5; result[12] = 5;
Bits.writeLong(result, 13, Double.doubleToRawLongBits(minX)); Bits.writeDouble(result, 13, minX);
Bits.writeLong(result, 21, Double.doubleToRawLongBits(minY)); Bits.writeDouble(result, 21, minY);
Bits.writeLong(result, 29, Double.doubleToRawLongBits(minX)); Bits.writeDouble(result, 29, minX);
Bits.writeLong(result, 37, Double.doubleToRawLongBits(maxY)); Bits.writeDouble(result, 37, maxY);
Bits.writeLong(result, 45, Double.doubleToRawLongBits(maxX)); Bits.writeDouble(result, 45, maxX);
Bits.writeLong(result, 53, Double.doubleToRawLongBits(maxY)); Bits.writeDouble(result, 53, maxY);
Bits.writeLong(result, 61, Double.doubleToRawLongBits(maxX)); Bits.writeDouble(result, 61, maxX);
Bits.writeLong(result, 69, Double.doubleToRawLongBits(minY)); Bits.writeDouble(result, 69, minY);
Bits.writeLong(result, 77, Double.doubleToRawLongBits(minX)); Bits.writeDouble(result, 77, minX);
Bits.writeLong(result, 85, Double.doubleToRawLongBits(minY)); Bits.writeDouble(result, 85, minY);
} }
return result; return result;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论