Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Nonononoki committed Jun 6, 2021
1 parent 35a4fc3 commit 1b4dbba
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
9 changes: 4 additions & 5 deletions src/main/java/com/nonononoki/alovoa/Tools.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,15 @@ public static boolean binaryStringToBoolean(String b) {

public static int getDistanceToUser(User user, User currUser) {
try {
return calcDistance(user.getLocationLatitude(), user.getLocationLongitude(),
return calcDistanceKm(user.getLocationLatitude(), user.getLocationLongitude(),
currUser.getLocationLatitude(), currUser.getLocationLongitude());
} catch (Exception e) {
return 99999;
}
}

// https://stackoverflow.com/a/45732035
// CC BY-SA 3.0, Pedro Silva
public static Double getBase64Size(String base64String) {
Double result = -1.0;
if (!base64String.isEmpty()) {
Expand All @@ -135,19 +136,17 @@ public static Double getBase64Size(String base64String) {
}

// https://stackoverflow.com/questions/3694380/calculating-distance-between-two-points-using-latitude-longitude/20410612#20410612
// to km
public static int calcDistance(double lat1, double lng1, double lat2, double lng2) {
// CC BY-SA 4.0 Arman Ebrahimpour, CC BY-SA 3.0 zahmde
public static int calcDistanceKm(double lat1, double lng1, double lat2, double lng2) {
double a = (lat1 - lat2) * distPerLat(lat1);
double b = (lng1 - lng2) * distPerLng(lat1);
double dist = Math.sqrt(a * a + b * b);
return (int) dist / THOUSAND;
}

private static double distPerLng(double lat) {
return 0.0003121092 * Math.pow(lat, 4) + 0.0101182384 * Math.pow(lat, 3) - 17.2385140059 * lat * lat
+ 5.5485277537 * lat + 111301.967182595;
}

private static double distPerLat(double lat) {
return -0.000000487305676 * Math.pow(lat, 4) - 0.0033668574 * Math.pow(lat, 3) + 0.4601181791 * lat * lat
- 1.4558127346 * lat + 110579.25662316;
Expand Down
5 changes: 2 additions & 3 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,10 @@ bucket4j.filters[14].rate-limits[0].bandwidths[0].time=120
bucket4j.filters[14].rate-limits[0].bandwidths[0].unit=seconds



# custom values
app.company.name=Alovoa
app.privacy.update-date=2000-01-01
app.tos.update-date=2000-01-01
app.privacy.update-date=2021-06-05
app.tos.update-date=2021-06-05
app.name=Alovoa
app.domain=https://localhost:8443

Expand Down
6 changes: 3 additions & 3 deletions src/main/resources/templates/imprint.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
<div class="box">
<p th:text="${companyName}"></p>
<p>Nho Quy Dinh</p>
<p>Impressumsstraße 7, 22222 Impressumsstadt</p>
<p>[email protected]</p>
<p>DE 12345678901</p>
<p>Neulanderweg 18, 21423 Winsen Luhe</p>
<p>Tel: 015678593504</p>
<p>[email protected]</p>
</div>
<div class="box">
<p th:text="#{contact}" style="margin-bottom: 16px;"></p>
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/com/nonononoki/alovoa/ToolsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ class ToolsTest {

@Test
void test() throws Exception {
int dist = (int)Math.round(Tools.calcDistance(0, 0, 0, 0));
int dist = (int)Math.round(Tools.calcDistanceKm(0, 0, 0, 0));
Assert.assertEquals(0, dist);

int dist2 = (int)Math.round(Tools.calcDistance(0.45, 0, 0, 0));
int dist2 = (int)Math.round(Tools.calcDistanceKm(0.45, 0, 0, 0));
Assert.assertEquals(49, dist2);

int dist3 = (int)Math.round(Tools.calcDistance(0.46, 0, 0, 0));
int dist3 = (int)Math.round(Tools.calcDistanceKm(0.46, 0, 0, 0));
Assert.assertEquals(50, dist3);
}
}

0 comments on commit 1b4dbba

Please sign in to comment.