public IntervalRelations compare(final ContinuousRealInterval other) { return compare(this, other); }
public IntervalRelations compare(final ContinuousRealInterval other) { return compare(this, other); }
public boolean canUnionWith(final ContinuousRealInterval other) { return EnumSet.complementOf(EnumSet.of(IntervalRelations.PRECEDES, IntervalRelations.PRECEDED_BY)).contains(compare(other)); }
public boolean canUnionWith(final ContinuousRealInterval other) { return EnumSet.complementOf(EnumSet.of(IntervalRelations.PRECEDES, IntervalRelations.PRECEDED_BY)).contains(compare(other)); }
public List<ContinuousRealInterval> union(final ContinuousRealInterval other) { switch (compare(other)) { case CONTAINS: case EQUALS: case FINISHED_BY: case STARTED_BY: return Collections.singletonList(this); case DURING: case FINISHES: case STARTS: return Collections.singletonList(other); case MEETS: return Collections.singletonList(new ContinuousRealInterval(getLower(), other.getUpper(), inclusiveLower(), other.inclusiveUpper())); case MET_BY: return Collections.singletonList(new ContinuousRealInterval(other.getLower(), getUpper(), other.inclusiveLower(), inclusiveUpper())); case OVERLAPPED_BY: return Collections.singletonList(new ContinuousRealInterval(other.getLower(), getUpper(), other.inclusiveLower(), inclusiveUpper())); case OVERLAPS: return Collections.singletonList(new ContinuousRealInterval(getLower(), other.getUpper(), inclusiveLower(), other.inclusiveUpper())); case PRECEDED_BY: case PRECEDES: return Arrays.asList(this, other); default: throw new IllegalStateException(); } }
public List<ContinuousRealInterval> union(final ContinuousRealInterval other) { switch (compare(other)) { case CONTAINS: case EQUALS: case FINISHED_BY: case STARTED_BY: return Collections.singletonList(this); case DURING: case FINISHES: case STARTS: return Collections.singletonList(other); case MEETS: return Collections.singletonList(new ContinuousRealInterval(getLower(), other.getUpper(), inclusiveLower(), other.inclusiveUpper())); case MET_BY: return Collections.singletonList(new ContinuousRealInterval(other.getLower(), getUpper(), other.inclusiveLower(), inclusiveUpper())); case OVERLAPPED_BY: return Collections.singletonList(new ContinuousRealInterval(other.getLower(), getUpper(), other.inclusiveLower(), inclusiveUpper())); case OVERLAPS: return Collections.singletonList(new ContinuousRealInterval(getLower(), other.getUpper(), inclusiveLower(), other.inclusiveUpper())); case PRECEDED_BY: case PRECEDES: return Arrays.asList(this, other); default: throw new IllegalStateException(); } }
/** * Verify that the intersection of a interval with a interval which it starts and which share an inclusive endpoint is correct. */ @Test public void intersectionStarts1() { final ContinuousRealInterval a = interval(2.1, 3.1, true, true); final ContinuousRealInterval b = interval(2.1, null, true, false); assertEquals(a, a.intersection(b)); assertEquals(a, b.intersection(a)); assertEquals(IntervalRelations.STARTS, a.compare(b)); assertEquals(IntervalRelations.STARTED_BY, b.compare(a)); }
/** * Verify that if two intervals meet (i.e., one's upper is the other's lower and the (in|ex)clusiveness differs), then they do not intersect. */ @Test public void intersectionMeets() { final ContinuousRealInterval a = interval(null, 2.1, false, false); final ContinuousRealInterval b = interval(2.1, null, true, false); assertNull(a.intersection(b)); assertNull(b.intersection(a)); assertEquals(IntervalRelations.MEETS, a.compare(b)); assertEquals(IntervalRelations.MET_BY, b.compare(a)); }
/** * Verify that if no overlap exists between the bounds an empty intersection is identified */ @Test public void intersectionEmpty() { final ContinuousRealInterval a = interval(null, 0d, false, true); final ContinuousRealInterval b = interval(1d, null, true, false); assertNull(a.intersection(b)); assertNull(b.intersection(a)); assertEquals(IntervalRelations.PRECEDES, a.compare(b)); assertEquals(IntervalRelations.PRECEDED_BY, b.compare(a)); }
/** * Verify that the intersection of a interval with a interval which it starts and which share an exclusive endpoint is correct. */ @Test public void intersectionStarts2() { final ContinuousRealInterval a = interval(2.1, 3.1, false, true); final ContinuousRealInterval b = interval(2.1, null, false, false); assertEquals(a, a.intersection(b)); assertEquals(a, b.intersection(a)); assertEquals(IntervalRelations.STARTS, a.compare(b)); assertEquals(IntervalRelations.STARTED_BY, b.compare(a)); }
/** * Verify that the intersection of a interval with a interval which it starts but for which the endpoint type is different it correct (i.e., it isn't a * start relation). */ @Test public void intersectionStarts3() { final ContinuousRealInterval a = interval(2.1, 3.1, false, true); final ContinuousRealInterval b = interval(2.1, null, true, false); assertEquals(a, a.intersection(b)); assertEquals(a, b.intersection(a)); assertEquals(IntervalRelations.DURING, a.compare(b)); assertEquals(IntervalRelations.CONTAINS, b.compare(a)); }
switch (compare(other))
switch (compare(other))
/** * Verify that the overlap of two intervals with exclusive bounds intersect correctly. */ @Test public void intersectionOverlap1() { final ContinuousRealInterval a = interval(null, 0.51, false, false); final ContinuousRealInterval b = interval(0.49, null, false, false); final ContinuousRealInterval expected = interval(0.49, 0.51, false, false); assertEquals(expected, a.intersection(b)); assertEquals(expected, b.intersection(a)); assertTrue(a.intersection(b).contains(BigDecimal.valueOf(0.50))); assertTrue(b.intersection(a).contains(BigDecimal.valueOf(0.50))); assertFalse(a.intersection(b).contains(BigDecimal.valueOf(0.49))); assertFalse(b.intersection(a).contains(BigDecimal.valueOf(0.49))); assertFalse(a.intersection(b).contains(BigDecimal.valueOf(0.51))); assertFalse(b.intersection(a).contains(BigDecimal.valueOf(0.51))); assertEquals(IntervalRelations.OVERLAPS, a.compare(b)); assertEquals(IntervalRelations.OVERLAPPED_BY, b.compare(a)); }
/** * Verify that the overlap of two intervals with inclusive bounds intersect correctly. */ @Test public void intersectionOverlap2() { final ContinuousRealInterval a = interval(null, 0.51, false, true); final ContinuousRealInterval b = interval(0.49, null, true, false); final ContinuousRealInterval expected = interval(0.49, 0.51, true, true); assertEquals(expected, a.intersection(b)); assertEquals(expected, b.intersection(a)); assertTrue(a.intersection(b).contains(BigDecimal.valueOf(0.50))); assertTrue(b.intersection(a).contains(BigDecimal.valueOf(0.50))); assertTrue(a.intersection(b).contains(BigDecimal.valueOf(0.49))); assertTrue(b.intersection(a).contains(BigDecimal.valueOf(0.49))); assertTrue(a.intersection(b).contains(BigDecimal.valueOf(0.51))); assertTrue(b.intersection(a).contains(BigDecimal.valueOf(0.51))); assertEquals(IntervalRelations.OVERLAPS, a.compare(b)); assertEquals(IntervalRelations.OVERLAPPED_BY, b.compare(a)); }
/** * Verify that two intervals overlapping just on an inclusive bound intersect to a point. */ @Test public void intersectionPoint() { final ContinuousRealInterval a = interval(null, 2.1, false, true); final ContinuousRealInterval b = interval(2.1, null, true, false); final ContinuousRealInterval expected = new ContinuousRealInterval(BigDecimal.valueOf(2.1d)); assertEquals(expected, a.intersection(b)); assertEquals(expected, b.intersection(a)); assertTrue(a.intersection(b).isPoint()); assertTrue(b.intersection(a).isPoint()); assertTrue(a.intersection(b).contains(BigDecimal.valueOf(2.1d))); assertTrue(b.intersection(a).contains(BigDecimal.valueOf(2.1d))); assertEquals(IntervalRelations.OVERLAPS, a.compare(b)); assertEquals(IntervalRelations.OVERLAPPED_BY, b.compare(a)); }
boolean inclusiveUpper, inclusiveLower; switch (compare(that))
boolean inclusiveUpper, inclusiveLower; switch (compare(that))