xtorcga
Version:
Xtor Compute Geometry Algorithm Libary 计算几何算法库
128 lines (127 loc) • 4.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Rectangle = void 0;
var Math_1 = require("../../src/math/Math");
var Cartographic_1 = require("./Cartographic");
/**
* A two dimensional region specified as longitude and latitude coordinates.
*
* @alias Rectangle
* @constructor
*
* @param {Number} [west=0.0] The westernmost longitude, in radians, in the range [-Pi, Pi].
* @param {Number} [south=0.0] The southernmost latitude, in radians, in the range [-Pi/2, Pi/2].
* @param {Number} [east=0.0] The easternmost longitude, in radians, in the range [-Pi, Pi].
* @param {Number} [north=0.0] The northernmost latitude, in radians, in the range [-Pi/2, Pi/2].
*
* @see Packable
*/
var Rectangle = /** @class */ (function () {
function Rectangle(west, south, east, north) {
if (west === void 0) { west = 0.0; }
if (south === void 0) { south = 0.0; }
if (east === void 0) { east = 0.0; }
if (north === void 0) { north = 0.0; }
this.west = west;
this.south = south;
this.east = east;
this.north = north;
}
Rectangle.fromDegrees = function (west, south, east, north, result) {
if (west === void 0) { west = 0.0; }
if (south === void 0) { south = 0.0; }
if (east === void 0) { east = 0.0; }
if (north === void 0) { north = 0.0; }
west = Math_1.toRadians(west);
south = Math_1.toRadians(south);
east = Math_1.toRadians(east);
north = Math_1.toRadians(north);
if (!result) {
return new Rectangle(west, south, east, north);
}
result.west = west;
result.south = south;
result.east = east;
result.north = north;
return result;
};
;
Rectangle.fromRadians = function (west, south, east, north, result) {
if (west === void 0) { west = 0.0; }
if (south === void 0) { south = 0.0; }
if (east === void 0) { east = 0.0; }
if (north === void 0) { north = 0.0; }
if (!result) {
return new Rectangle(west, south, east, north);
}
result.west = west;
result.south = south;
result.east = east;
result.north = north;
return result;
};
;
Object.defineProperty(Rectangle.prototype, "width", {
get: function () {
return Rectangle.computeWidth(this);
},
enumerable: false,
configurable: true
});
Object.defineProperty(Rectangle.prototype, "height", {
get: function () {
return Rectangle.computeHeight(this);
},
enumerable: false,
configurable: true
});
/**
* Computes the northeast corner of a rectangle.
*
* @param {Rectangle} rectangle The rectangle for which to find the corner
* @param {Cartographic} [result] The object onto which to store the result.
* @returns {Cartographic} The modified result parameter or a new Cartographic instance if none was provided.
*/
Rectangle.prototype.northeast = function (result) {
if (!result) {
return new Cartographic_1.Cartographic(this.east, this.north);
}
result.longitude = this.east;
result.latitude = this.north;
result.height = 0.0;
return result;
};
;
/**
* Computes the southeast corner of a rectangle.
*/
Rectangle.prototype.southeast = function (result) {
if (!result) {
return new Cartographic_1.Cartographic(this.east, this.south);
}
result.longitude = this.east;
result.latitude = this.south;
result.height = 0.0;
return result;
};
;
/**
* 计算宽度 单位弧度
*/
Rectangle.computeWidth = function (rectangle) {
var east = rectangle.east;
var west = rectangle.west;
if (east < west) {
east += Math_1.PI_TWO;
}
return east - west;
};
/**
* 计算高度弧度
*/
Rectangle.computeHeight = function (rectangle) {
return rectangle.north - rectangle.south;
};
return Rectangle;
}());
exports.Rectangle = Rectangle;