All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.rtron.math.range.RangeSetExtensions.kt Maven / Gradle / Ivy

The newest version!
package io.rtron.math.range

import io.rtron.std.powerSet

/**
 * Unions a set of [RangeSet] to a single [RangeSet].
 */
fun > Set>.unionRangeSets(): RangeSet =
    reduce { acc, element -> acc.union(element) }

/**
 * Returns the intersecting [RangeSet].
 *
 * @receiver provided set of [RangeSet] for which the intersecting [RangeSet] is evaluated
 * @return minimum intersecting range set
 */
fun > Set>.intersectionRangeSets(): RangeSet =
    reduce { acc, element -> acc.intersection(element) }

/**
 * Returns true, if set of [RangeSet] contains intersecting [RangeSet] pairs.
 */
fun > Set>.containsIntersectingRangeSets(): Boolean {
    val rangeSetPairCombinations =
        powerSet().filter { it.size == 2 }.map { Pair(it.first(), it.last()) }
    return rangeSetPairCombinations.any { it.first.intersects(it.second) }
}

/**
 * Conversion to [RangeSet].
 *
 * @receiver [Range] to be converted
 */
fun > Range.toRangeSet(): RangeSet = RangeSet.of(this)




© 2015 - 2025 Weber Informatics LLC | Privacy Policy