io.rtron.math.geometry.euclidean.twod.curve.SectionedCurve2D.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of rtron-math Show documentation
Show all versions of rtron-math Show documentation
Component 'rtron-math' of rtron.
The newest version!
/*
* Copyright 2019-2022 Chair of Geoinformatics, Technical University of Munich
*
* 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 at
*
* http://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.
*/
package io.rtron.math.geometry.euclidean.twod.curve
import com.github.kittinunf.result.Result
import io.rtron.math.geometry.curved.oned.point.CurveRelativeVector1D
import io.rtron.math.geometry.euclidean.twod.Rotation2D
import io.rtron.math.geometry.euclidean.twod.point.Vector2D
import io.rtron.math.range.Range
import io.rtron.math.range.fuzzyEncloses
import io.rtron.math.range.shiftLowerEndpointTo
import io.rtron.std.handleFailure
/**
* Cuts out a section from the [completeCurve].
* The resulting domain of the [SectionedCurve2D] starts at 0.0 and ends at the length of the section.
*
* @param completeCurve complete curve segment that is to be cut
* @param section the range that is cut out from the [completeCurve]'s domain
*/
class SectionedCurve2D(
private val completeCurve: AbstractCurve2D,
section: Range
) : AbstractCurve2D() {
// Properties and Initializers
init {
require(completeCurve.domain.fuzzyEncloses(section, tolerance)) { "The complete function must be defined everywhere where the section is also defined." }
}
override val domain: Range = section.shiftLowerEndpointTo(0.0)
override val tolerance: Double get() = completeCurve.tolerance
private val sectionStart = CurveRelativeVector1D(section.lowerEndpointResult().handleFailure { throw it.error })
// Methods
override fun calculatePointLocalCSUnbounded(curveRelativePoint: CurveRelativeVector1D):
Result {
val pointOnCompleteCurve = sectionStart + curveRelativePoint
return completeCurve.calculatePointGlobalCS(pointOnCompleteCurve)
}
override fun calculateRotationLocalCSUnbounded(curveRelativePoint: CurveRelativeVector1D):
Result {
val pointOnCompleteCurve = sectionStart + curveRelativePoint
return completeCurve.calculateRotationGlobalCS(pointOnCompleteCurve)
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy