Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/misikora/ruler
Library for distance measurements
https://github.com/misikora/ruler
android distance distance-calculation distance-measurements kotlin kotlin-android
Last synced: 6 days ago
JSON representation
Library for distance measurements
- Host: GitHub
- URL: https://github.com/misikora/ruler
- Owner: MiSikora
- License: apache-2.0
- Created: 2020-02-02T10:00:23.000Z (almost 5 years ago)
- Default Branch: trunk
- Last Pushed: 2023-03-01T23:56:39.000Z (over 1 year ago)
- Last Synced: 2023-07-16T20:49:43.703Z (over 1 year ago)
- Topics: android, distance, distance-calculation, distance-measurements, kotlin, kotlin-android
- Language: Kotlin
- Homepage: https://mehow.io/ruler/
- Size: 1.5 MB
- Stars: 9
- Watchers: 1
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# Ruler π
[](https://search.maven.org/search?q=g:io.mehow.ruler)
[](https://oss.sonatype.org/content/repositories/snapshots/io/mehow/ruler/)Distance measurements library for Kotlin and Android.
Please visit [project website](https://misikora.github.io/ruler/) for the full documentation and the [changelog](https://misikora.github.io/ruler/changelog/).
## TLDR
Add Ruler dependency to your project.
```groovy
repositories {
mavenCentral()
}dependencies {
implementation "io.mehow.ruler:ruler:2.0.2"
}
```Enable Java 8 support.
```groovy
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
}
}
```Define a distance and manipulate it.
```kotlin
// Distance is dimensionless.
val distanceFromMeters: Distance = Distance.ofMeters(100)
val distanceFromYards: Distance = Distance.ofYards(50)// Length has a unit attached to it.
val metersLength: Length = distanceFromMeters.toLength(SiLengthUnit.Meter)
val inchesLength: Length = distanceFromMeters.toLength(ImperialLengthUnit.Inch)// metersLength and inchesLength represent the same distance but with a different units attached to them.
check(metersLength - inchesLength == Length.ofMeters(0))
```Print distances and lengths in a human-readable way based on Locale.
```kotlin
fun main() {
val distance = Distance.ofMeters(100)
val length = distance.toLength(Meter)// Assumes en_US Locale on a device.
// Prints "109yd 1ft 1in".
val humanReadableDistance: String = distance.format()// Prints "100.00m".
val humanReadableLength: String = length.format()
}
```## License
Copyright 2020 MichaΕ Sikora
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.