Skip to content

Commit

Permalink
migrated to arrow 1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
benediktschwab committed Sep 11, 2023
1 parent c212f4c commit f1e708b
Show file tree
Hide file tree
Showing 74 changed files with 1,565 additions and 591 deletions.
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Dependencies.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ object DependencyVersions {
// standard libraries
const val kotlin = "1.9.10"
const val coroutines = "1.7.3"
const val arrow = "1.1.5"
const val arrow = "1.2.1"

// testing libraries
const val junit = "5.10.0"
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Plugins.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ object PluginVersions {
const val ktlint = "11.5.1"
const val xjc = "1.6"
const val versionChecker = "0.47.0"
const val dokka = "1.8.20"
const val dokka = "1.9.0"
const val serialization = "1.9.10"
const val ksp = "1.9.10-1.0.13"
}
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fun Project.kotlinProject() {
}

fun isNonStable(version: String): Boolean {
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.toUpperCase().contains(it) }
val stableKeyword = listOf("RELEASE", "FINAL", "GA").any { version.uppercase().contains(it) }
val regex = """^[0-9,.v-]+(-r)?$""".toRegex()
return !stableKeyword && !(regex.containsMatchIn(version))
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package io.rtron.math.analysis.function.bivariate.pure

import arrow.core.Either
import arrow.core.continuations.either
import arrow.core.getOrElse
import arrow.core.raise.either
import io.rtron.math.analysis.function.bivariate.BivariateFunction
import io.rtron.math.analysis.function.univariate.UnivariateFunction
import io.rtron.math.analysis.function.univariate.pure.LinearFunction
Expand Down Expand Up @@ -89,7 +89,7 @@ class ShapeFunction(
.firstKey()
.let { Either.Right(it) }

private fun calculateZ(key: Double, y: Double): Either<Exception, Double> = either.eager {
private fun calculateZ(key: Double, y: Double): Either<Exception, Double> = either {
val selectedFunction = functions.getValueEither(key).mapLeft { it.toIllegalArgumentException() }.bind()

val yAdjusted = if (!extrapolateY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package io.rtron.math.analysis.function.univariate

import arrow.core.Either
import arrow.core.continuations.either
import arrow.core.raise.either
import io.rtron.math.analysis.function.univariate.combination.StackedFunction
import io.rtron.math.range.DefinableDomain
import io.rtron.math.range.fuzzyContains
Expand Down Expand Up @@ -59,7 +59,7 @@ abstract class UnivariateFunction : DefinableDomain<Double> {
* @param x parameter [x] of function
* @return returns Result.Success(z) = f(x), if [x] is strictly contained in [domain] and evaluation was successful
*/
fun value(x: Double): Either<Exception, Double> = either.eager {
fun value(x: Double): Either<Exception, Double> = either {
domain.containsResult(x).bind()
valueUnbounded(x).bind()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package io.rtron.math.analysis.function.univariate.combination

import arrow.core.Either
import arrow.core.NonEmptyList
import arrow.core.continuations.either
import arrow.core.getOrElse
import arrow.core.raise.either
import io.rtron.math.analysis.function.univariate.UnivariateFunction
import io.rtron.math.analysis.function.univariate.pure.ConstantFunction
import io.rtron.math.analysis.function.univariate.pure.LinearFunction
Expand Down Expand Up @@ -47,17 +47,17 @@ class ConcatenatedFunction(
override val domain: Range<Double> get() = container.domain

// Methods
override fun valueUnbounded(x: Double): Either<Exception, Double> = either.eager {
override fun valueUnbounded(x: Double): Either<Exception, Double> = either {
val localMember = container.strictSelectMember(x).bind()
localMember.member.valueUnbounded(localMember.localParameter).bind()
}

override fun slopeUnbounded(x: Double): Either<Exception, Double> = either.eager {
override fun slopeUnbounded(x: Double): Either<Exception, Double> = either {
val localMember = container.strictSelectMember(x).bind()
localMember.member.slopeUnbounded(localMember.localParameter).bind()
}

override fun valueInFuzzy(x: Double, tolerance: Double): Either<Exception, Double> = either.eager {
override fun valueInFuzzy(x: Double, tolerance: Double): Either<Exception, Double> = either {
val localMember = container.fuzzySelectMember(x, tolerance).bind()
localMember.member.valueUnbounded(localMember.localParameter).bind()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ data class LinearFunction(
* @param pointY linear function stopping at ([pointX], [pointY])
*/
fun ofInclusiveInterceptAndPoint(intercept: Option<Double>, pointX: Double, pointY: Option<Double>): LinearFunction {
require(intercept.exists { it.isFinite() }) { "Intercept must be finite, if defined." }
require(intercept.isSome { it.isFinite() }) { "Intercept must be finite, if defined." }
require(pointX.isFinite()) { "PointX must be finite." }
require(pointY.exists { it.isFinite() }) { "PointY must be finite, if defined." }
require(intercept.isDefined() || pointY.isDefined()) { "Either intercept or pointY must be finite." }
require(pointY.isSome { it.isFinite() }) { "PointY must be finite, if defined." }
require(intercept.isSome() || pointY.isSome()) { "Either intercept or pointY must be finite." }

val adjustedIntercept = intercept.getOrElse {
pointY.toEither { IllegalStateException("PointY must be set.") }.getOrElse { throw it }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package io.rtron.math.geometry.euclidean.threed.curve

import arrow.core.Either
import arrow.core.NonEmptyList
import arrow.core.continuations.either
import arrow.core.left
import arrow.core.raise.either
import arrow.core.right
import arrow.core.toNonEmptyListOrNull
import io.rtron.math.geometry.GeometryException
Expand Down Expand Up @@ -118,7 +118,7 @@ abstract class AbstractCurve3D : AbstractGeometry3D(), DefinableDomain<Double>,
* @return list of points on this curve
*/
fun calculatePointListGlobalCS(step: Double, includeEndPoint: Boolean = true):
Either<GeometryException.ValueNotContainedInDomain, NonEmptyList<Vector3D>> = either.eager {
Either<GeometryException.ValueNotContainedInDomain, NonEmptyList<Vector3D>> = either {
domain.arrange(step, includeEndPoint, tolerance)
.map(::CurveRelativeVector1D)
.map { calculatePointGlobalCS(it).bind() }
Expand All @@ -130,7 +130,7 @@ abstract class AbstractCurve3D : AbstractGeometry3D(), DefinableDomain<Double>,
*
* @param step step size between the points
*/
fun calculateLineStringGlobalCS(step: Double): Either<GeometryException, LineString3D> = either.eager {
fun calculateLineStringGlobalCS(step: Double): Either<GeometryException, LineString3D> = either {
val point = calculatePointListGlobalCS(step, true).bind()
LineString3D.of(point, tolerance).bind()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package io.rtron.math.geometry.euclidean.threed.curve

import arrow.core.Either
import arrow.core.continuations.either
import arrow.core.getOrElse
import arrow.core.raise.either
import io.rtron.math.analysis.function.univariate.UnivariateFunction
import io.rtron.math.analysis.function.univariate.pure.LinearFunction
import io.rtron.math.geometry.curved.oned.point.CurveRelativeVector1D
Expand Down Expand Up @@ -111,7 +111,7 @@ data class Curve3D(
* @param curveRelativeLineSegment line segment in curve relative coordinates
* @return line segment in cartesian coordinates
*/
fun transform(curveRelativeLineSegment: CurveRelativeLineSegment3D): Either<Exception, LineSegment3D> = either.eager {
fun transform(curveRelativeLineSegment: CurveRelativeLineSegment3D): Either<Exception, LineSegment3D> = either {
val start = transform(curveRelativeLineSegment.start)
val end = transform(curveRelativeLineSegment.end)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package io.rtron.math.geometry.euclidean.threed.curve

import arrow.core.Either
import arrow.core.NonEmptyList
import arrow.core.continuations.either
import arrow.core.getOrElse
import arrow.core.left
import arrow.core.raise.either
import arrow.core.toNonEmptyListOrNone
import io.rtron.math.container.ConcatenationContainer
import io.rtron.math.geometry.GeometryException
Expand Down Expand Up @@ -69,7 +69,7 @@ class LineString3D(

companion object {

fun of(vertices: NonEmptyList<Vector3D>, tolerance: Double): Either<GeometryException, LineString3D> = either.eager {
fun of(vertices: NonEmptyList<Vector3D>, tolerance: Double): Either<GeometryException, LineString3D> = either {
val adjustedVertices = vertices
.filterWithNext { a, b -> a.fuzzyUnequals(b, tolerance) }
.toNonEmptyListOrNone()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@ data class Cuboid3D(
val UNIT = Cuboid3D(1.0, 1.0, 1.0, DEFAULT_TOLERANCE)

fun of(length: Option<Double>, width: Option<Double>, height: Option<Double>, tolerance: Double, affineSequence: AffineSequence3D = AffineSequence3D.EMPTY): Cuboid3D {
require(length.isDefined()) { "Length must be defined." }
require(width.isDefined()) { "Width must be defined." }
require(height.isDefined()) { "Height must be defined." }
require(length.isSome()) { "Length must be defined." }
require(width.isSome()) { "Width must be defined." }
require(height.isSome()) { "Height must be defined." }

return Cuboid3D(length.orNull()!!, width.orNull()!!, height.orNull()!!, tolerance, affineSequence)
return Cuboid3D(length.getOrNull()!!, width.getOrNull()!!, height.getOrNull()!!, tolerance, affineSequence)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ data class Cylinder3D(
const val DEFAULT_NUMBER_SLICES: Int = 16 // used for tesselation

fun of(radius: Option<Double>, height: Option<Double>, tolerance: Double, affineSequence: AffineSequence3D = AffineSequence3D.EMPTY, numberSlices: Int = DEFAULT_NUMBER_SLICES): Cylinder3D {
require(radius.isDefined()) { "Radius must be defined." }
require(height.isDefined()) { "Height must be defined." }
return Cylinder3D(radius.orNull()!!, height.orNull()!!, tolerance, affineSequence, numberSlices)
require(radius.isSome()) { "Radius must be defined." }
require(height.isSome()) { "Height must be defined." }
return Cylinder3D(radius.getOrNull()!!, height.getOrNull()!!, tolerance, affineSequence, numberSlices)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package io.rtron.math.geometry.euclidean.threed.solid

import arrow.core.Either
import arrow.core.NonEmptyList
import arrow.core.continuations.either
import arrow.core.getOrElse
import arrow.core.nonEmptyListOf
import arrow.core.raise.either
import arrow.core.toNonEmptyListOrNull
import io.rtron.math.analysis.function.univariate.UnivariateFunction
import io.rtron.math.analysis.function.univariate.combination.StackedFunction
Expand Down Expand Up @@ -180,7 +180,7 @@ data class ParametricSweep3D(
}

private fun createPolygons(leftVertices: NonEmptyList<Vector3D>, rightVertices: NonEmptyList<Vector3D>):
Either<GeometryException, List<Polygon3D>> = either.eager {
Either<GeometryException, List<Polygon3D>> = either {
LinearRing3D.ofWithDuplicatesRemoval(leftVertices, rightVertices, tolerance)
.bind()
.map { it.calculatePolygonsGlobalCS().bind() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ data class Circle3D(
private const val DEFAULT_NUMBER_SLICES: Int = 16 // used for tesselation

fun of(radius: Option<Double>, tolerance: Double, affineSequence: AffineSequence3D = AffineSequence3D.EMPTY): Circle3D {
require(radius.isDefined()) { "Radius must be defined." }
require(radius.isSome()) { "Radius must be defined." }

return Circle3D(radius.orNull()!!, tolerance, affineSequence)
return Circle3D(radius.getOrNull()!!, tolerance, affineSequence)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package io.rtron.math.geometry.euclidean.threed.surface

import arrow.core.Either
import arrow.core.NonEmptyList
import arrow.core.continuations.either
import arrow.core.nonEmptyListOf
import arrow.core.raise.either
import arrow.core.toNonEmptyListOrNull
import io.rtron.math.geometry.GeometryException

Expand All @@ -44,7 +44,7 @@ class CompositeSurface3D(
constructor(surfaceMember: AbstractSurface3D) : this(nonEmptyListOf(surfaceMember))

// Methods
override fun calculatePolygonsLocalCS(): Either<GeometryException.BoundaryRepresentationGenerationError, NonEmptyList<Polygon3D>> = either.eager {
override fun calculatePolygonsLocalCS(): Either<GeometryException.BoundaryRepresentationGenerationError, NonEmptyList<Polygon3D>> = either {
val polygons: List<Polygon3D> = surfaceMembers.map { it.calculatePolygonsGlobalCS().bind() }.flatten()
polygons.let { it.toNonEmptyListOrNull()!! }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ package io.rtron.math.geometry.euclidean.threed.surface

import arrow.core.Either
import arrow.core.NonEmptyList
import arrow.core.continuations.either
import arrow.core.left
import arrow.core.nonEmptyListOf
import arrow.core.raise.either
import arrow.core.right
import arrow.core.toNonEmptyListOrNone
import arrow.core.toNonEmptyListOrNull
Expand Down Expand Up @@ -120,7 +120,7 @@ data class LinearRing3D(
* @param rightVertices right vertices for the linear rings construction
*/
fun ofWithDuplicatesRemoval(leftVertices: NonEmptyList<Vector3D>, rightVertices: NonEmptyList<Vector3D>, tolerance: Double):
Either<GeometryException.NotEnoughValidLinearRings, NonEmptyList<LinearRing3D>> = either.eager {
Either<GeometryException.NotEnoughValidLinearRings, NonEmptyList<LinearRing3D>> = either {
require(leftVertices.size >= 2) { "At least two left vertices required." }
require(rightVertices.size >= 2) { "At least two right vertices required." }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package io.rtron.math.geometry.euclidean.threed.surface

import arrow.core.Either
import arrow.core.NonEmptyList
import arrow.core.continuations.either
import arrow.core.getOrElse
import arrow.core.raise.either
import arrow.core.toNonEmptyListOrNull
import io.rtron.math.geometry.GeometryException
import io.rtron.math.geometry.euclidean.threed.curve.Curve3D
Expand Down Expand Up @@ -63,7 +63,7 @@ data class ParametricBoundedSurface3D(

// Methods

override fun calculatePolygonsLocalCS(): Either<GeometryException.BoundaryRepresentationGenerationError, NonEmptyList<Polygon3D>> = either.eager {
override fun calculatePolygonsLocalCS(): Either<GeometryException.BoundaryRepresentationGenerationError, NonEmptyList<Polygon3D>> = either {
LinearRing3D.ofWithDuplicatesRemoval(leftVertices, rightVertices, tolerance)
.mapLeft { GeometryException.BoundaryRepresentationGenerationError(it.message) }
.bind()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ data class Rectangle3D(
companion object {

fun of(length: Option<Double>, width: Option<Double>, tolerance: Double, affineSequence: AffineSequence3D = AffineSequence3D.EMPTY): Rectangle3D {
require(length.isDefined()) { "Length must be defined." }
require(width.isDefined()) { "Width must be defined." }
require(length.isSome()) { "Length must be defined." }
require(width.isSome()) { "Width must be defined." }

return Rectangle3D(length.orNull()!!, width.orNull()!!, tolerance, affineSequence)
return Rectangle3D(length.getOrNull()!!, width.getOrNull()!!, tolerance, affineSequence)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package io.rtron.math.geometry.euclidean.twod.curve

import arrow.core.Either
import arrow.core.continuations.either
import arrow.core.getOrElse
import arrow.core.raise.either
import io.rtron.math.analysis.function.univariate.UnivariateFunction
import io.rtron.math.analysis.function.univariate.combination.StackedFunction
import io.rtron.math.geometry.curved.oned.point.CurveRelativeVector1D
Expand Down Expand Up @@ -89,7 +89,7 @@ data class LateralTranslatedCurve2D(
* Returns the lateral translation at the [curveRelativePoint].
*/
private fun calculateTranslation(curveRelativePoint: CurveRelativeVector1D):
Either<Exception, CurveRelativeVector2D> = either.eager {
Either<Exception, CurveRelativeVector2D> = either {
val translation = lateralTranslationFunction
.valueInFuzzy(curveRelativePoint.curvePosition, tolerance)
.bind()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package io.rtron.math.processing.triangulation

import arrow.core.Either
import arrow.core.NonEmptyList
import arrow.core.continuations.either
import arrow.core.left
import arrow.core.raise.either
import arrow.core.right
import arrow.core.toNonEmptyListOrNull
import io.rtron.math.geometry.euclidean.threed.point.Vector3D
Expand All @@ -37,7 +37,7 @@ import org.poly2tri.geometry.polygon.PolygonPoint as P2TPolygonPoint
*/
class Poly2TriTriangulationAlgorithm : TriangulationAlgorithm() {

override fun triangulate(vertices: NonEmptyList<Vector3D>, tolerance: Double): Either<TriangulatorException, List<Polygon3D>> = either.eager {
override fun triangulate(vertices: NonEmptyList<Vector3D>, tolerance: Double): Either<TriangulatorException, List<Polygon3D>> = either {
val polygon = P2TPolygon(vertices.toList().map { P2TPolygonPoint(it.x, it.y, it.z) })

poly2TriTriangulation(polygon).bind()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package io.rtron.math.processing.triangulation

import arrow.core.Either
import arrow.core.NonEmptyList
import arrow.core.continuations.either
import arrow.core.left
import arrow.core.raise.either
import io.rtron.math.geometry.euclidean.threed.point.Vector3D
import io.rtron.math.geometry.euclidean.threed.surface.Polygon3D
import io.rtron.math.processing.calculateBestFittingPlane
Expand All @@ -37,7 +37,7 @@ class ProjectedTriangulationAlgorithm(
private val triangulationAlgorithm: TriangulationAlgorithm
) : TriangulationAlgorithm() {

override fun triangulate(vertices: NonEmptyList<Vector3D>, tolerance: Double): Either<TriangulatorException, List<Polygon3D>> = either.eager {
override fun triangulate(vertices: NonEmptyList<Vector3D>, tolerance: Double): Either<TriangulatorException, List<Polygon3D>> = either {
val projectedVertices = projectVertices(vertices, tolerance)
val projectedPolygonsTriangulated = triangulationAlgorithm
.triangulate(projectedVertices, tolerance).bind()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package io.rtron.math.processing.triangulation

import arrow.core.Either
import arrow.core.NonEmptyList
import arrow.core.continuations.either
import arrow.core.left
import arrow.core.raise.either
import io.rtron.math.geometry.euclidean.threed.point.Vector3D
import io.rtron.math.geometry.euclidean.threed.surface.Polygon3D

Expand All @@ -36,7 +36,7 @@ abstract class TriangulationAlgorithm {
* @param vertices list of vertices representing the outline to be triangulated
* @return list of triangulated [Polygon3D]
*/
fun triangulateChecked(vertices: NonEmptyList<Vector3D>, tolerance: Double): Either<TriangulatorException, List<Polygon3D>> = either.eager {
fun triangulateChecked(vertices: NonEmptyList<Vector3D>, tolerance: Double): Either<TriangulatorException, List<Polygon3D>> = either {
val triangles = triangulate(vertices, tolerance).bind()

val newVertices = triangles.flatMap { it.vertices }
Expand Down
Loading

0 comments on commit f1e708b

Please sign in to comment.