Move couple util funcs to Station, add comments
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import * as tinycolor from 'tinycolor2';
|
||||
|
||||
import { distance } from './utils';
|
||||
import { distance, randomPoint } from './utils';
|
||||
|
||||
let stationCount = 0;
|
||||
|
||||
@@ -27,6 +27,28 @@ export default class Station {
|
||||
);
|
||||
}
|
||||
|
||||
public static isPointDistant(point: PIXI.Point, stations: Station[],
|
||||
minDistance: number): boolean {
|
||||
for (const station of stations) {
|
||||
if (distance(point, station.location) < minDistance) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static randomDistantPoint(stations: Station[], minDistance: number): PIXI.Point | null {
|
||||
let tries = 100;
|
||||
while (tries > 0) {
|
||||
const point = randomPoint();
|
||||
if (Station.isPointDistant(point, stations, minDistance)) {
|
||||
return point;
|
||||
}
|
||||
tries -= 1;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public location: PIXI.Point;
|
||||
public population: number;
|
||||
public connections: Station[];
|
||||
|
||||
Reference in New Issue
Block a user