MCPcopy Create free account
hub / github.com/SuperMap/iClient-JavaScript / intersectsBounds

Method intersectsBounds

src/common/commontypes/Bounds.js:467–527  ·  view source on GitHub ↗

* @function Bounds.prototype.intersectsBounds * @description 判断目标边界范围是否与当前边界范围相交。如果两个边界范围中的任意边缘相交或者一个边界包含了另外一个就认为这两个边界相交。 * @example * var bounds = new Bounds(-180,-90,100,80); * var isIntersects = bounds.intersectsBounds( * new Bounds(-170,-90,120,80) * ); *

(bounds, options)

Source from the content-addressed store, hash-verified

465 * @returns {boolean} 传入的 bounds 对象与当前 bounds 相交。
466 */
467 intersectsBounds(bounds, options) {
468 if (typeof options === "boolean") {
469 options = {inclusive: options};
470 }
471 options = options || {};
472 if (options.worldBounds) {
473 var self = this.wrapDateLine(options.worldBounds);
474 bounds = bounds.wrapDateLine(options.worldBounds);
475 } else {
476 self = this;
477 }
478 if (options.inclusive == null) {
479 options.inclusive = true;
480 }
481 var intersects = false;
482 var mightTouch = (
483 self.left === bounds.right ||
484 self.right === bounds.left ||
485 self.top === bounds.bottom ||
486 self.bottom === bounds.top
487 );
488
489 // if the two bounds only touch at an edge, and inclusive is false,
490 // then the bounds don't *really* intersect.
491 if (options.inclusive || !mightTouch) {
492 // otherwise, if one of the boundaries even partially contains another,
493 // inclusive of the edges, then they do intersect.
494 var inBottom = (
495 ((bounds.bottom >= self.bottom) && (bounds.bottom <= self.top)) ||
496 ((self.bottom >= bounds.bottom) && (self.bottom <= bounds.top))
497 );
498 var inTop = (
499 ((bounds.top >= self.bottom) && (bounds.top <= self.top)) ||
500 ((self.top > bounds.bottom) && (self.top < bounds.top))
501 );
502 var inLeft = (
503 ((bounds.left >= self.left) && (bounds.left <= self.right)) ||
504 ((self.left >= bounds.left) && (self.left <= bounds.right))
505 );
506 var inRight = (
507 ((bounds.right >= self.left) && (bounds.right <= self.right)) ||
508 ((self.right >= bounds.left) && (self.right <= bounds.right))
509 );
510 intersects = ((inBottom || inTop) && (inLeft || inRight));
511 }
512 // document me
513 if (options.worldBounds && !intersects) {
514 var world = options.worldBounds;
515 var width = world.getWidth();
516 var selfCrosses = !world.containsBounds(self);
517 var boundsCrosses = !world.containsBounds(bounds);
518 if (selfCrosses && !boundsCrosses) {
519 bounds = bounds.add(-width, 0);
520 intersects = self.intersectsBounds(bounds, {inclusive: options.inclusive});
521 } else if (boundsCrosses && !selfCrosses) {
522 self = self.add(-width, 0);
523 intersects = bounds.intersectsBounds(self, {inclusive: options.inclusive});
524 }

Callers 6

BoundsSpec.jsFile · 0.80
subscribeFunction · 0.80
GraphThemeLayer.jsFile · 0.80

Calls 4

wrapDateLineMethod · 0.95
containsBoundsMethod · 0.80
getWidthMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected