Skip to content

Commit

Permalink
fixed invalid coord
Browse files Browse the repository at this point in the history
  • Loading branch information
0xF6 committed Jun 25, 2018
1 parent 1f4c5b3 commit 3f848b1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ new GeoPosition(71.317941, 55.691416);
let xPoint = new GeoPosition(71.317941, 55.691416);
let yPoint = new GeoPosition(71.500873, 55.807184);

+x.Distance(y).toFixed(0) // -> 17304 meters
+x.Distance(y).toFixed(0) // -> 20844 meters
```

#### Zero check
Expand Down Expand Up @@ -98,5 +98,5 @@ GeoPosition.SectionCenterPosition(pos, pos2) // GeoPosition(71.454954, 55.562936
let start = new GeoPosition(71.436706, 55.268108);
let end = new GeoPosition(71.473202, 55.857764);
let point = new GeoPosition(71.504361, 55.511926);
GeoPosition.SectionCenterPosition(point, start, end) // 3331 meters
GeoPosition.SectionCenterPosition(point, start, end) // 5807 meters
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "geo-position.ts",
"version": "1.2.1",
"version": "1.3.1",
"description": "Library for working with GeoPosition fot TypeScript",
"main": "./lib/index.js",
"repository": "https://github.com/0xF6/geo-position.ts.git",
Expand Down
14 changes: 7 additions & 7 deletions src/geo-position.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export class GeoPosition {
*/
public Latitude: number;

public constructor(_longitude?: number, _latitude?: number) {
public constructor(_latitude?: number, _longitude?: number) {
this.Longitude = _longitude || 0;
this.Latitude = _latitude || 0;
}
Expand Down Expand Up @@ -71,7 +71,7 @@ export class GeoPosition {
* to string this object
*/
public toString(): string {
return `[${this.Longitude}(位), ${this.Latitude}(蠁)]`
return `[${this.Latitude}(蠁), ${this.Longitude}(位)]`
}
/**
* equals objects
Expand Down Expand Up @@ -131,7 +131,7 @@ export class GeoPosition {
max = Math.max(secStart.Latitude, secEnd.Latitude);
latitude = min + (max - min) / 2;

return new GeoPosition(longitude, latitude);
return new GeoPosition(latitude, longitude);
}
/**
* Calculates distance to section
Expand Down Expand Up @@ -174,8 +174,8 @@ export class GeoPosition {
+ (yy * (point.Latitude - secStart.Latitude)))
/ ((xx * xx) + (yy * yy));

var perp = new GeoPosition(secStart.Longitude + xx * shortestLength,
secStart.Latitude + yy * shortestLength);
var perp = new GeoPosition(
secStart.Latitude + yy * shortestLength, secStart.Longitude + xx * shortestLength);

if (perp.Longitude < secEnd.Longitude && perp.Longitude > secStart.Longitude &&
perp.Latitude < secEnd.Latitude && perp.Latitude > secStart.Latitude)
Expand Down Expand Up @@ -232,6 +232,6 @@ export class GeoPosition {
default:
throw new Error(`Invalid longitude specified: ${longitude}`);
}
return new GeoPosition(parseFloat(longitude.replace(',', '.')), parseFloat(latitude.replace(',', '.')));
return new GeoPosition(parseFloat(latitude.replace(',', '.')), parseFloat(longitude.replace(',', '.')));
}
}
}
10 changes: 5 additions & 5 deletions test/geo.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test("Calculate distance", (t) => {
let x = new GeoPosition(71.317941, 55.691416);
let y = new GeoPosition(71.500873, 55.807184);

t.deepEqual(+x.Distance(y).toFixed(1), 17304.4);
t.deepEqual(+x.Distance(y).toFixed(1), 20844.1);
})


Expand Down Expand Up @@ -54,11 +54,11 @@ test("Parse GPS", (t) => {
});

test("toString", (t) => {
t.deepEqual(new GeoPosition(71.317941, 55.691416).toString(), "[71.317941(), 55.691416()]");
t.deepEqual(new GeoPosition(71.317941, 55.691416).toString(), "[71.317941(), 55.691416()]");
});

test("hashCode", (t) => {
t.deepEqual(new GeoPosition(71.317941, 55.691416).hashCode(), 28334);
t.deepEqual(new GeoPosition(71.317941, 55.691416).hashCode(), 22042);
});


Expand Down Expand Up @@ -98,10 +98,10 @@ test("SectionCenterPosition", (t) => {
test("DistanceToSection", (t) => {
let pos = new GeoPosition(71.436706, 55.268108);
let pos2 = new GeoPosition(71.473202, 55.857764);
t.deepEqual(+GeoPosition.DistanceToSection(new GeoPosition(71.504361, 55.511926), pos, pos2).toFixed(2), 6497.15);
t.deepEqual(+GeoPosition.DistanceToSection(new GeoPosition(71.504361, 55.511926), pos, pos2).toFixed(2), 5807.64);
});
test("DistanceToSectionEx", (t) => {
let pos = new GeoPosition(71.436706, 55.268108);
let pos2 = new GeoPosition(71.473202, 55.857764);
t.deepEqual(+GeoPosition.DistanceToSectionEx(new GeoPosition(71.504361, 55.511926), pos, pos2).toFixed(2), 3331.33);
t.deepEqual(+GeoPosition.DistanceToSectionEx(new GeoPosition(71.504361, 55.511926), pos, pos2).toFixed(2), 5849.83);
});

0 comments on commit 3f848b1

Please sign in to comment.