Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@
*/
public final class LineFloat implements Line {

private final double x1;
private final double y1;
private final double x2;
private final double y2;
private final float x1;
private final float y1;
private final float x2;
private final float y2;

private LineFloat(double x1, double y1, double x2, double y2) {
private LineFloat(float x1, float y1, float x2, float y2) {
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}

public static LineFloat create(double x1, double y1, double x2, double y2) {
public static LineFloat create(float x1, float y1, float x2, float y2) {
return new LineFloat(x1, y1, x2, y2);
}

Expand Down
20 changes: 20 additions & 0 deletions src/test/java/com/github/davidmoten/rtree/geometry/LineTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

import org.junit.Test;

import com.github.davidmoten.rtree.geometry.internal.LineDouble;
import com.github.davidmoten.rtree.geometry.internal.LineFloat;

public final class LineTest {

private static final double PRECISION = 0.00001;
Expand Down Expand Up @@ -222,4 +225,21 @@ public void testLineFloatIntersectsWithHorizontalLine() {
}
}

@Test
public void testLineFloatStoresCoordinatesAsFloatNotDouble() throws NoSuchFieldException {
// https://github.com/davidmoten/rtree/issues/89
for (String field : new String[] { "x1", "y1", "x2", "y2" }) {
assertEquals(float.class, LineFloat.class.getDeclaredField(field).getType());
}
for (String field : new String[] { "x1", "y1", "x2", "y2" }) {
assertEquals(double.class, LineDouble.class.getDeclaredField(field).getType());
}
}

@Test
public void testLineFloatIsNotDoublePrecision() {
assertFalse(Geometries.line(1f, 2f, 3f, 4f).isDoublePrecision());
assertTrue(Geometries.line(1d, 2d, 3d, 4d).isDoublePrecision());
}

}