philiprehberger-interval 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +14 -0
- data/lib/philiprehberger/interval/version.rb +1 -1
- data/lib/philiprehberger/interval.rb +14 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2614076496fada8f6202df687ec993c5438e3a47945824e05e6bb4d00cc1c046
|
|
4
|
+
data.tar.gz: 2557c885218f82fe7de28ea6e91e660b9b901ab2995ca8d68e3a1ef9cf9b2d21
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ed05a860c2d28ce9cfdf00787585e117c41ee03bd1a4f917f4c06d4c461313a7fcdfe0fa7ce9f6073804c4c67c1169e84a7988a2070d8f54f42a725a0caef36b
|
|
7
|
+
data.tar.gz: 8451b55300a3d8d489cc895792256f4e7a1077d9be2a0df25aee1e7f9ef42d9defa2de2fe7eabe3b3d3c58c6c959037f65f89a06eaa8e96d61025ff91a09e285
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.3.0] - 2026-04-15
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Interval.intersection(intervals)` — compute the common overlap of a collection of intervals
|
|
14
|
+
|
|
10
15
|
## [0.2.0] - 2026-04-03
|
|
11
16
|
|
|
12
17
|
### Added
|
data/README.md
CHANGED
|
@@ -83,6 +83,19 @@ Philiprehberger::Interval.gaps(intervals)
|
|
|
83
83
|
# => [[7, 10]]
|
|
84
84
|
```
|
|
85
85
|
|
|
86
|
+
### Finding a Common Intersection
|
|
87
|
+
|
|
88
|
+
Compute the overlap shared by every interval, or `nil` if any pair is disjoint:
|
|
89
|
+
|
|
90
|
+
```ruby
|
|
91
|
+
Philiprehberger::Interval.intersection([
|
|
92
|
+
Philiprehberger::Interval.new(1, 10),
|
|
93
|
+
Philiprehberger::Interval.new(3, 8),
|
|
94
|
+
Philiprehberger::Interval.new(5, 12)
|
|
95
|
+
])
|
|
96
|
+
# => [5, 8]
|
|
97
|
+
```
|
|
98
|
+
|
|
86
99
|
### With Time Values
|
|
87
100
|
|
|
88
101
|
```ruby
|
|
@@ -110,6 +123,7 @@ shift.include?(Time.new(2026, 1, 1, 12)) # => true
|
|
|
110
123
|
| `#clamp(value)` | Clamp value to interval bounds |
|
|
111
124
|
| `.merge(intervals)` | Merge overlapping intervals into non-overlapping set |
|
|
112
125
|
| `.gaps(intervals)` | Find gaps between a set of intervals |
|
|
126
|
+
| `.intersection(intervals)` | Common overlap of a collection of intervals, or `nil` |
|
|
113
127
|
|
|
114
128
|
## Development
|
|
115
129
|
|
|
@@ -39,6 +39,20 @@ module Philiprehberger
|
|
|
39
39
|
merged
|
|
40
40
|
end
|
|
41
41
|
|
|
42
|
+
# Compute the common overlap across a collection of intervals.
|
|
43
|
+
#
|
|
44
|
+
# @param intervals [Array<Range>] the intervals to intersect
|
|
45
|
+
# @return [Range, nil] the common intersection, or nil if any pair is disjoint
|
|
46
|
+
def self.intersection(intervals)
|
|
47
|
+
return nil if intervals.empty?
|
|
48
|
+
|
|
49
|
+
intervals[1..].reduce(intervals.first) do |acc, current|
|
|
50
|
+
return nil if acc.nil?
|
|
51
|
+
|
|
52
|
+
acc.intersect(current)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
42
56
|
# Find gaps between a collection of intervals.
|
|
43
57
|
#
|
|
44
58
|
# @param intervals [Array<Range>] the intervals to analyze
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: philiprehberger-interval
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Philip Rehberger
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-04-
|
|
11
|
+
date: 2026-04-15 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: Interval data type supporting closed, open, and half-open boundaries
|
|
14
14
|
with overlap detection, containment, intersection, union, subtraction, shift, scale,
|