123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- define(['exports', './when-8d13db60', './Check-70bec281', './Cartographic-fe4be337', './Cartesian2-85064f09', './BoundingSphere-775c5788'], function (exports, when, Check, Cartographic, Cartesian2, BoundingSphere) { 'use strict';
-
- function BoundingRectangle(x, y, width, height) {
-
- this.x = when.defaultValue(x, 0.0);
-
- this.y = when.defaultValue(y, 0.0);
-
- this.width = when.defaultValue(width, 0.0);
-
- this.height = when.defaultValue(height, 0.0);
- }
-
- BoundingRectangle.packedLength = 4;
-
- BoundingRectangle.pack = function(value, array, startingIndex) {
-
- Check.Check.typeOf.object('value', value);
- Check.Check.defined('array', array);
-
- startingIndex = when.defaultValue(startingIndex, 0);
- array[startingIndex++] = value.x;
- array[startingIndex++] = value.y;
- array[startingIndex++] = value.width;
- array[startingIndex] = value.height;
- return array;
- };
-
- BoundingRectangle.unpack = function(array, startingIndex, result) {
-
- Check.Check.defined('array', array);
-
- startingIndex = when.defaultValue(startingIndex, 0);
- if (!when.defined(result)) {
- result = new BoundingRectangle();
- }
- result.x = array[startingIndex++];
- result.y = array[startingIndex++];
- result.width = array[startingIndex++];
- result.height = array[startingIndex];
- return result;
- };
-
- BoundingRectangle.fromPoints = function(positions, result) {
- if (!when.defined(result)) {
- result = new BoundingRectangle();
- }
- if (!when.defined(positions) || positions.length === 0) {
- result.x = 0;
- result.y = 0;
- result.width = 0;
- result.height = 0;
- return result;
- }
- var length = positions.length;
- var minimumX = positions[0].x;
- var minimumY = positions[0].y;
- var maximumX = positions[0].x;
- var maximumY = positions[0].y;
- for ( var i = 1; i < length; i++) {
- var p = positions[i];
- var x = p.x;
- var y = p.y;
- minimumX = Math.min(x, minimumX);
- maximumX = Math.max(x, maximumX);
- minimumY = Math.min(y, minimumY);
- maximumY = Math.max(y, maximumY);
- }
- result.x = minimumX;
- result.y = minimumY;
- result.width = maximumX - minimumX;
- result.height = maximumY - minimumY;
- return result;
- };
- var defaultProjection = new BoundingSphere.GeographicProjection();
- var fromRectangleLowerLeft = new Cartographic.Cartographic();
- var fromRectangleUpperRight = new Cartographic.Cartographic();
-
- BoundingRectangle.fromRectangle = function(rectangle, projection, result) {
- if (!when.defined(result)) {
- result = new BoundingRectangle();
- }
- if (!when.defined(rectangle)) {
- result.x = 0;
- result.y = 0;
- result.width = 0;
- result.height = 0;
- return result;
- }
- projection = when.defaultValue(projection, defaultProjection);
- var lowerLeft = projection.project(Cartesian2.Rectangle.southwest(rectangle, fromRectangleLowerLeft));
- var upperRight = projection.project(Cartesian2.Rectangle.northeast(rectangle, fromRectangleUpperRight));
- Cartesian2.Cartesian2.subtract(upperRight, lowerLeft, upperRight);
- result.x = lowerLeft.x;
- result.y = lowerLeft.y;
- result.width = upperRight.x;
- result.height = upperRight.y;
- return result;
- };
-
- BoundingRectangle.clone = function(rectangle, result) {
- if (!when.defined(rectangle)) {
- return undefined;
- }
- if (!when.defined(result)) {
- return new BoundingRectangle(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
- }
- result.x = rectangle.x;
- result.y = rectangle.y;
- result.width = rectangle.width;
- result.height = rectangle.height;
- return result;
- };
-
- BoundingRectangle.union = function(left, right, result) {
-
- Check.Check.typeOf.object('left', left);
- Check.Check.typeOf.object('right', right);
-
- if (!when.defined(result)) {
- result = new BoundingRectangle();
- }
- var lowerLeftX = Math.min(left.x, right.x);
- var lowerLeftY = Math.min(left.y, right.y);
- var upperRightX = Math.max(left.x + left.width, right.x + right.width);
- var upperRightY = Math.max(left.y + left.height, right.y + right.height);
- result.x = lowerLeftX;
- result.y = lowerLeftY;
- result.width = upperRightX - lowerLeftX;
- result.height = upperRightY - lowerLeftY;
- return result;
- };
-
- BoundingRectangle.expand = function(rectangle, point, result) {
-
- Check.Check.typeOf.object('rectangle', rectangle);
- Check.Check.typeOf.object('point', point);
-
- result = BoundingRectangle.clone(rectangle, result);
- var width = point.x - result.x;
- var height = point.y - result.y;
- if (width > result.width) {
- result.width = width;
- } else if (width < 0) {
- result.width -= width;
- result.x = point.x;
- }
- if (height > result.height) {
- result.height = height;
- } else if (height < 0) {
- result.height -= height;
- result.y = point.y;
- }
- return result;
- };
-
- BoundingRectangle.intersect = function(left, right) {
-
- Check.Check.typeOf.object('left', left);
- Check.Check.typeOf.object('right', right);
-
- var leftX = left.x;
- var leftY = left.y;
- var rightX = right.x;
- var rightY = right.y;
- if (!(leftX > rightX + right.width ||
- leftX + left.width < rightX ||
- leftY + left.height < rightY ||
- leftY > rightY + right.height)) {
- return BoundingSphere.Intersect.INTERSECTING;
- }
- return BoundingSphere.Intersect.OUTSIDE;
- };
-
- BoundingRectangle.equals = function(left, right) {
- return (left === right) ||
- ((when.defined(left)) &&
- (when.defined(right)) &&
- (left.x === right.x) &&
- (left.y === right.y) &&
- (left.width === right.width) &&
- (left.height === right.height));
- };
-
- BoundingRectangle.prototype.clone = function(result) {
- return BoundingRectangle.clone(this, result);
- };
-
- BoundingRectangle.prototype.intersect = function(right) {
- return BoundingRectangle.intersect(this, right);
- };
-
- BoundingRectangle.prototype.equals = function(right) {
- return BoundingRectangle.equals(this, right);
- };
- exports.BoundingRectangle = BoundingRectangle;
- });
|