salat-first
Version:
Islamic prayer times calculation with special support for Moroccan methods and Maliki madhab
48 lines (47 loc) • 1.56 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Coordinates = void 0;
/**
* Represents geographic coordinates (latitude and longitude)
*/
class Coordinates {
/**
* Creates a new coordinates object
* @param latitude Latitude in decimal degrees
* @param longitude Longitude in decimal degrees
*/
constructor(latitude, longitude) {
this.latitude = latitude;
this.longitude = longitude;
this.validate();
}
/**
* Validates the coordinates
* @throws Error if coordinates are invalid
*/
validate() {
if (Math.abs(this.latitude) > 90) {
throw new Error("Latitude must be between -90 and 90 degrees");
}
if (Math.abs(this.longitude) > 180) {
throw new Error("Longitude must be between -180 and 180 degrees");
}
}
/**
* Returns a string representation of the coordinates
*/
toString() {
return `(${this.latitude.toFixed(4)}°, ${this.longitude.toFixed(4)}°)`;
}
/**
* Checks if two coordinates are approximately equal
* @param other The other coordinates to compare with
* @param precision The precision in degrees (default: 0.0001)
* @returns Whether the coordinates are approximately equal
*/
isApproximatelyEqual(other, precision = 0.0001) {
return (Math.abs(this.latitude - other.latitude) < precision &&
Math.abs(this.longitude - other.longitude) < precision);
}
}
exports.Coordinates = Coordinates;