"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/geometry/Bounds.js" between
Leaflet-1.8.0.tar.gz and Leaflet-1.9.0.tar.gz

About: Leaflet is a JavaScript library for mobile-friendly interactive maps.

Bounds.js  (Leaflet-1.8.0):Bounds.js  (Leaflet-1.9.0)
skipping to change at line 41 skipping to change at line 41
var points = b ? [a, b] : a; var points = b ? [a, b] : a;
for (var i = 0, len = points.length; i < len; i++) { for (var i = 0, len = points.length; i < len; i++) {
this.extend(points[i]); this.extend(points[i]);
} }
} }
Bounds.prototype = { Bounds.prototype = {
// @method extend(point: Point): this // @method extend(point: Point): this
// Extends the bounds to contain the given point. // Extends the bounds to contain the given point.
extend: function (point) { // (Point)
point = toPoint(point); // @alternative
// @method extend(otherBounds: Bounds): this
// Extend the bounds to contain the given bounds
extend: function (obj) {
var min2, max2;
if (!obj) { return this; }
if (obj instanceof Point || typeof obj[0] === 'number' || 'x' in
obj) {
min2 = max2 = toPoint(obj);
} else {
obj = toBounds(obj);
min2 = obj.min;
max2 = obj.max;
if (!min2 || !max2) { return this; }
}
// @property min: Point // @property min: Point
// The top left corner of the rectangle. // The top left corner of the rectangle.
// @property max: Point // @property max: Point
// The bottom right corner of the rectangle. // The bottom right corner of the rectangle.
if (!this.min && !this.max) { if (!this.min && !this.max) {
this.min = point.clone(); this.min = min2.clone();
this.max = point.clone(); this.max = max2.clone();
} else { } else {
this.min.x = Math.min(point.x, this.min.x); this.min.x = Math.min(min2.x, this.min.x);
this.max.x = Math.max(point.x, this.max.x); this.max.x = Math.max(max2.x, this.max.x);
this.min.y = Math.min(point.y, this.min.y); this.min.y = Math.min(min2.y, this.min.y);
this.max.y = Math.max(point.y, this.max.y); this.max.y = Math.max(max2.y, this.max.y);
} }
return this; return this;
}, },
// @method getCenter(round?: Boolean): Point // @method getCenter(round?: Boolean): Point
// Returns the center point of the bounds. // Returns the center point of the bounds.
getCenter: function (round) { getCenter: function (round) {
return new Point( return toPoint(
(this.min.x + this.max.x) / 2, (this.min.x + this.max.x) / 2,
(this.min.y + this.max.y) / 2, round); (this.min.y + this.max.y) / 2, round);
}, },
// @method getBottomLeft(): Point // @method getBottomLeft(): Point
// Returns the bottom-left point of the bounds. // Returns the bottom-left point of the bounds.
getBottomLeft: function () { getBottomLeft: function () {
return new Point(this.min.x, this.max.y); return toPoint(this.min.x, this.max.y);
}, },
// @method getTopRight(): Point // @method getTopRight(): Point
// Returns the top-right point of the bounds. // Returns the top-right point of the bounds.
getTopRight: function () { // -> Point getTopRight: function () { // -> Point
return new Point(this.max.x, this.min.y); return toPoint(this.max.x, this.min.y);
}, },
// @method getTopLeft(): Point // @method getTopLeft(): Point
// Returns the top-left point of the bounds (i.e. [`this.min`](#bounds-mi n)). // Returns the top-left point of the bounds (i.e. [`this.min`](#bounds-mi n)).
getTopLeft: function () { getTopLeft: function () {
return this.min; // left, top return this.min; // left, top
}, },
// @method getBottomRight(): Point // @method getBottomRight(): Point
// Returns the bottom-right point of the bounds (i.e. [`this.max`](#bound s-max)). // Returns the bottom-right point of the bounds (i.e. [`this.max`](#bound s-max)).
skipping to change at line 157 skipping to change at line 172
var min = this.min, var min = this.min,
max = this.max, max = this.max,
min2 = bounds.min, min2 = bounds.min,
max2 = bounds.max, max2 = bounds.max,
xOverlaps = (max2.x > min.x) && (min2.x < max.x), xOverlaps = (max2.x > min.x) && (min2.x < max.x),
yOverlaps = (max2.y > min.y) && (min2.y < max.y); yOverlaps = (max2.y > min.y) && (min2.y < max.y);
return xOverlaps && yOverlaps; return xOverlaps && yOverlaps;
}, },
// @method isValid(): Boolean
// Returns `true` if the bounds are properly initialized.
isValid: function () { isValid: function () {
return !!(this.min && this.max); return !!(this.min && this.max);
} },
// @method pad(bufferRatio: Number): Bounds
// Returns bounds created by extending or retracting the current bounds b
y a given ratio in each direction.
// For example, a ratio of 0.5 extends the bounds by 50% in each directio
n.
// Negative values will retract the bounds.
pad: function (bufferRatio) {
var min = this.min,
max = this.max,
heightBuffer = Math.abs(min.x - max.x) * bufferRatio,
widthBuffer = Math.abs(min.y - max.y) * bufferRatio;
return toBounds(
toPoint(min.x - heightBuffer, min.y - widthBuffer),
toPoint(max.x + heightBuffer, max.y + widthBuffer));
},
// @method equals(otherBounds: Bounds, maxMargin?: Number): Boolean
// Returns `true` if the rectangle is equivalent (within a small margin o
f error) to the given bounds. The margin of error can be overridden by setting `
maxMargin` to a small number.
equals: function (bounds) {
if (!bounds) { return false; }
bounds = toBounds(bounds);
return this.min.equals(bounds.getTopLeft()) &&
this.max.equals(bounds.getBottomRight());
},
}; };
// @factory L.bounds(corner1: Point, corner2: Point) // @factory L.bounds(corner1: Point, corner2: Point)
// Creates a Bounds object from two corners coordinate pairs. // Creates a Bounds object from two corners coordinate pairs.
// @alternative // @alternative
// @factory L.bounds(points: Point[]) // @factory L.bounds(points: Point[])
// Creates a Bounds object from the given array of points. // Creates a Bounds object from the given array of points.
export function toBounds(a, b) { export function toBounds(a, b) {
if (!a || a instanceof Bounds) { if (!a || a instanceof Bounds) {
return a; return a;
 End of changes. 8 change blocks. 
12 lines changed or deleted 60 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)