master Update README file.
master
Update README file.
This Swift module aims to provide a solution to easily create mathematical intervals.
You can import this module using:
import DLInterval
Interval has constructors to create intervals using the notations we’re used to from mathmatics:
Interval
[1, 2] and (1, 2)
[1, 2]
(1, 2)
let closedClosed = Interval([1..2]) // [1, 2] let openOpen = Interval((1..2)) // (1, 2)
For convenience, range operators may be used:
let closedClosed = Interval(1...2) // [1, 2] let closedOpen = Interval(1..<2) // [1, 2)
For half open intervals there are some new operators:
.>.
.<.
.><.
let closedOpen: Interval = 1.<.2 // [1, 2) let openClosed: Interval = 1.>.2 // (1, 2] let openOpen: Interval = 1.><.2 // (1, 2)
To create intervals with infinity as boundaries:
let negativeInfinity: Interval = -Double.infinity.>.0 // (-inf, 0] let positiveInfinity: Interval = 0.><.Double.Infinity // (0, +inf)
Note: Creating an interval with a closed boundary using infinity is ill-formed.
You may check if an interval contains a double value:
let closedOpen: Interval = 1.<.2 closedOpen.contains(1) // true closedOpen.contains(2) // false closedOpen.contains(1.1) // true
Checking infinity values:
let closedOpen: Interval = 1.<.2 closedOpen.contains(Double.infinity) // false closedOpen.contains(-Double.infinity) // false let positiveInfinity: Interval = 0.><.Double.Infinity positiveInfinity.contains(Double.infinity) // true positiveInfinity.contains(-Double.infinity) // false
Creating a union from 2 intervals:
let firstInterval: Interval = -Double.infinity.>.0 // (-inf, 0] let secondInterval: Interval = 0.><.1 // (0, 1) let union = firstInterval.formUnion(secondInterval) // (-inf, 1)
Note: union is a new data type called UnionInterval.
union
UnionInterval
Find intersection of 2 intervals:
let firstInterval: Interval = -Double.infinity.><.1 // (-inf, 1) let secondInterval: Interval = -1.><.5.0 // (-1, 5) let intersection = firstInterval.intersection(with: secondInterval) // (-1, 1)
Note: Interval‘s intersection returns an Interval? and UnionInterval‘s returns UnionInterval.
Interval?
Available from v1.1.1.
v1.1.1
An interval can clip a value within its boundaries:
let interval = Interval([0..1]) let newValue = interval.clipValue(-0.5) // 0.0
Note: Open boundaries returns the closest value to boundary:
let interval = Interval((-1..1)) let newValue = interval.clipValue(2.0) // 0.99999999
Module requires Swift 4.0.
OS requirements:
Choose your preferred dependency manager:
Add the dependency in your Cartfile.
Cartfile
github "davidlivadaru/DLInterval"
If you need the framework only for a single OS, then I propose to use --platform [iOS|macOS|watchOS|tvOS] specifier when your perform carthage update.
--platform [iOS|macOS|watchOS|tvOS]
carthage update
Add the dependency in your Podfile.
Podfile
pod 'DLInterval'
Add the the following dependecy in your Package.swift:
Package.swift
dependencies: [ .package(url: "https://github.com/davidlivadaru/DLInterval.git", .upToNextMajor(from: "1.0.0")) ]
and update your target’s dependencies:
targets: [ .target( name: "YourTargetName", dependencies: ["DLInterval"])), ]
Module is covered by unit tests, however, bugs always slip through. If you find a bug in the module create an issue.
If you want to contribute on fixing bugs or implementing new features then create a pull request.
DLInterval is released under MIT license. See LICENSE for details.
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
This Swift module aims to provide a solution to easily create mathematical intervals.
Table of contents
Usage
Importing the module
You can import this module using:
Creation
Interval
has constructors to create intervals using the notations we’re used to from mathmatics:[1, 2]
and(1, 2)
For convenience, range operators may be used:
For half open intervals there are some new operators:
.>.
- first boundary is open.<.
- second boundary is open.><.
- both boundaries are openTo create intervals with infinity as boundaries:
Note: Creating an interval with a closed boundary using infinity is ill-formed.
Check
You may check if an interval contains a double value:
Checking infinity values:
Unions
Creating a union from 2 intervals:
Note:
union
is a new data type calledUnionInterval
.Intersections
Find intersection of 2 intervals:
Note:
Interval
‘s intersection returns anInterval?
andUnionInterval
‘s returnsUnionInterval
.Clipping values
Available from
v1.1.1
.An interval can clip a value within its boundaries:
Note: Open boundaries returns the closest value to boundary:
Installation
Module requires Swift 4.0.
OS requirements:
Choose your preferred dependency manager:
1. Carthage
Add the dependency in your
Cartfile
.If you need the framework only for a single OS, then I propose to use
--platform [iOS|macOS|watchOS|tvOS]
specifier when your performcarthage update
.2. CocoaPods
Add the dependency in your
Podfile
.3. Swift Package Manager
Add the the following dependecy in your
Package.swift
:and update your target’s dependencies:
Contribution
Module is covered by unit tests, however, bugs always slip through. If you find a bug in the module create an issue.
If you want to contribute on fixing bugs or implementing new features then create a pull request.
License
DLInterval is released under MIT license. See LICENSE for details.