Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

Commit

Permalink
in travel history, calculate jump distance directly if both systems h…
Browse files Browse the repository at this point in the history
…ave known coords
  • Loading branch information
noberasco committed May 26, 2016
1 parent 34a2fc6 commit eac2b27
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions EDDiscovery/Jump.m
Original file line number Diff line number Diff line change
Expand Up @@ -203,25 +203,31 @@ - (NSNumber *)distanceFromPreviousJump {
NSAssert1(array.count <= 2, @"this query should return at maximum 2 elements: got %lu instead", (unsigned long)array.count);

if (array.count == 2) {
Jump *jump = array.lastObject;
NSString *name = jump.system.name;
Jump *jump = array.lastObject;

for (Distance *aDistance in self.system.distances) {
if (ABS(aDistance.distance.doubleValue - aDistance.calculatedDistance.doubleValue) <= 0.01 && [aDistance.name isEqualToString:name]) {
distance = aDistance.distance;

break;
}
if (self.system.hasCoordinates == YES && jump.system.hasCoordinates == YES) {
distance = @(sqrt(pow((self.system.x-jump.system.x), 2) + pow((self.system.y-jump.system.y), 2) + pow((self.system.z-jump.system.z), 2)));
}
else {
NSString *name = jump.system.name;

if (distance == nil) {
for (Distance *aDistance in jump.system.distances) {
for (Distance *aDistance in self.system.distances) {
if (ABS(aDistance.distance.doubleValue - aDistance.calculatedDistance.doubleValue) <= 0.01 && [aDistance.name isEqualToString:name]) {
distance = aDistance.distance;

break;
}
}

if (distance == nil) {
for (Distance *aDistance in jump.system.distances) {
if (ABS(aDistance.distance.doubleValue - aDistance.calculatedDistance.doubleValue) <= 0.01 && [aDistance.name isEqualToString:name]) {
distance = aDistance.distance;

break;
}
}
}
}
}
}
Expand Down

0 comments on commit eac2b27

Please sign in to comment.