philiprehberger-interval 0.3.0 → 0.4.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 +2 -0
- data/lib/philiprehberger/interval/range.rb +17 -0
- data/lib/philiprehberger/interval/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ecb8d7c68d3603d44c8df9a87a224c52300377809ad98ab1d19fe1a89ec13449
|
|
4
|
+
data.tar.gz: 75b3438103596f8a4de7f358a9f1cc25cd39fe5e80a47dfb6f25d38852e26964
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 78198caa2a0cf621b3545997e8fdfb58ad7424d7304e7d4367873dd69eaa02db2c91f1ed5a95cd365074be886063fb91941dea72180b2ce4e099c6e1982fddcf
|
|
7
|
+
data.tar.gz: 2dbb700fce8cd9cf5d973ab0baabece8e8b94e8d79f71939a805418f7fdfdbf626ca183ae9ab0fc18c2c036f21a2c0de9ddd28d90e1978da02139ac8eb3d1178
|
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.4.0] - 2026-04-15
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
- `Range#overlap_ratio(other)` — fraction of self covered by another interval (Float in 0.0–1.0)
|
|
14
|
+
|
|
10
15
|
## [0.3.0] - 2026-04-15
|
|
11
16
|
|
|
12
17
|
### Added
|
data/README.md
CHANGED
|
@@ -36,6 +36,7 @@ a.overlaps?(b) # => true
|
|
|
36
36
|
a.intersect(b) # => [3, 5]
|
|
37
37
|
a.union(b) # => [1, 8]
|
|
38
38
|
a.include?(4) # => true
|
|
39
|
+
a.overlap_ratio(b) # => 0.5
|
|
39
40
|
```
|
|
40
41
|
|
|
41
42
|
### Interval Types
|
|
@@ -113,6 +114,7 @@ shift.include?(Time.new(2026, 1, 1, 12)) # => true
|
|
|
113
114
|
| `#contains?(other)` | Check if interval fully contains another |
|
|
114
115
|
| `#adjacent?(other)` | Check if intervals are touching but not overlapping |
|
|
115
116
|
| `#intersect(other)` | Return the overlap between two intervals |
|
|
117
|
+
| `#overlap_ratio(other)` | Fraction of self covered by other (0.0–1.0) |
|
|
116
118
|
| `#union(other)` | Return the combined interval |
|
|
117
119
|
| `#subtract(other)` | Remove another interval, returning remaining parts |
|
|
118
120
|
| `#size` | Length of the interval |
|
|
@@ -113,6 +113,23 @@ module Philiprehberger
|
|
|
113
113
|
@finish - @start
|
|
114
114
|
end
|
|
115
115
|
|
|
116
|
+
# Return the fraction of self that is covered by another interval.
|
|
117
|
+
#
|
|
118
|
+
# Returns a Float in 0.0..1.0. Returns 0.0 if disjoint, 1.0 if self is
|
|
119
|
+
# fully contained in other. If self has zero length (a point), returns
|
|
120
|
+
# 1.0 when the point is within other, else 0.0.
|
|
121
|
+
#
|
|
122
|
+
# @param other [Range] the other interval
|
|
123
|
+
# @return [Float] the fraction of self covered by other
|
|
124
|
+
def overlap_ratio(other)
|
|
125
|
+
return other.include?(@start) ? 1.0 : 0.0 if size.zero?
|
|
126
|
+
|
|
127
|
+
overlap = intersect(other)
|
|
128
|
+
return 0.0 if overlap.nil?
|
|
129
|
+
|
|
130
|
+
overlap.size.to_f / size
|
|
131
|
+
end
|
|
132
|
+
|
|
116
133
|
# Check if a point is within the interval.
|
|
117
134
|
#
|
|
118
135
|
# @param point [Comparable] the point to check
|