【发布时间】:2019-04-09 19:30:15
【问题描述】:
我知道,这是一个愚蠢的问题,但我需要检查两个时间段(epoch)是否重叠。我只是不知道这些检查是否足够。
TLPeriod.prototype.isOverlapping = function(period) {
if( period.toPoints().start.getEpoch() < this.toPoints().start.getEpoch()
&&
this.toPoints().start.getEpoch() < period.toPoints().end.getEpoch())
return true;
if(this.toPoints().end.getEpoch() > period.toPoints().start.getEpoch())
return true;
return false;
};
我知道,我应该写here,但是要花很多时间才能得到答复。
可以快速总结为:
同一轴上的两条带点的线:
|(this.start),(this.end)|
&
|(period.start),(period.end)|
如何检查它们是否重叠?
OVERLAP!
|-----------|-----------------|-------------|
this.start period.start this.end period.end
NO OVERLAP!
|-----------| |-------------|
this.start this.end period.start period.end
OVERLAP!
|-----------------|--------|-------------|
period.start this.start this.end period.end
【问题讨论】:
-
按开始对句点进行排序,使得
(a, b) < (c, d),然后它们重叠iffc < d,并且包含在iffd < b,并且不重叠如果b < c。
标签: javascript overlap