Skip to content

Commit 3824590

Browse files
myluckagainpedja4
authored andcommitted
float to double (eugenp#5118)
1 parent 278cb53 commit 3824590

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

‎core-java/src/main/java/com/baeldung/linesintersection/LinesIntersectionService.java‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55

66
public class LinesIntersectionService {
77

8-
public Optional<Point> calculateIntersectionPoint(float m1, float b1, float m2, float b2) {
8+
public Optional<Point> calculateIntersectionPoint(double m1, double b1, double m2, double b2) {
99

1010
if (m1 == m2) {
1111
return Optional.empty();
1212
}
13-
14-
float x = (b2 - b1) / (m1 - m2);
15-
float y = m1 * x + b1;
1613

17-
Point point = new Point(Math.round(x), Math.round(y));
14+
double x = (b2 - b1) / (m1 - m2);
15+
double y = m1 * x + b1;
1816

17+
Point point = new Point();
18+
point.setLocation(x, y);
1919
return Optional.of(point);
2020
}
2121
}

‎core-java/src/test/java/com/baeldung/linesintersection/LinesIntersectionServiceUnitTest.java‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,24 @@ public class LinesIntersectionServiceUnitTest {
1414
@Test
1515
public void givenNotParallelLines_whenCalculatePoint_thenPresent() {
1616

17-
float m1 = 0;
18-
float b1 = 0;
19-
float m2 = 1;
20-
float b2 = -1;
17+
double m1 = 0;
18+
double b1 = 0;
19+
double m2 = 1;
20+
double b2 = -1;
2121

2222
Optional<Point> point = service.calculateIntersectionPoint(m1, b1, m2, b2);
2323

2424
assertTrue(point.isPresent());
25-
assertEquals(point.get().x, 1);
26-
assertEquals(point.get().y, 0);
25+
assertEquals(point.get().getX(), 1, 0.001);
26+
assertEquals(point.get().getX(), 1, 0.001);
2727
}
2828

2929
@Test
3030
public void givenParallelLines_whenCalculatePoint_thenEmpty() {
31-
float m1 = 1;
32-
float b1 = 0;
33-
float m2 = 1;
34-
float b2 = -1;
31+
double m1 = 1;
32+
double b1 = 0;
33+
double m2 = 1;
34+
double b2 = -1;
3535

3636
Optional<Point> point = service.calculateIntersectionPoint(m1, b1, m2, b2);
3737

0 commit comments

Comments
 (0)