Loading mechanics/src/com/android/mechanics/spec/Breakpoint.kt +30 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.mechanics.spec import androidx.compose.ui.util.fastIsFinite import com.android.mechanics.spring.SpringParameters /** Loading @@ -42,6 +43,11 @@ class BreakpointKey(val debugLabel: String? = null, val identity: Any = Object() return "BreakpointKey(${debugLabel ?: ""}" + "@${System.identityHashCode(identity).toString(16).padStart(8,'0')})" } internal companion object { val MinLimit = BreakpointKey("built-in::min") val MaxLimit = BreakpointKey("built-in::max") } } /** Loading @@ -66,11 +72,20 @@ data class Breakpoint( val spring: SpringParameters, val guarantee: Guarantee, ) : Comparable<Breakpoint> { init { when (key) { BreakpointKey.MinLimit -> require(position == Float.NEGATIVE_INFINITY) BreakpointKey.MaxLimit -> require(position == Float.POSITIVE_INFINITY) else -> require(position.fastIsFinite()) } } companion object { /** First breakpoint of each spec. */ val minLimit = Breakpoint( BreakpointKey("built-in::min"), BreakpointKey.MinLimit, Float.NEGATIVE_INFINITY, SpringParameters.Snap, Guarantee.None, Loading @@ -79,11 +94,24 @@ data class Breakpoint( /** Last breakpoint of each spec. */ val maxLimit = Breakpoint( BreakpointKey("built-in::max"), BreakpointKey.MaxLimit, Float.POSITIVE_INFINITY, SpringParameters.Snap, Guarantee.None, ) internal fun create( breakpointKey: BreakpointKey, breakpointPosition: Float, springSpec: SpringParameters, guarantee: Guarantee, ): Breakpoint { return when (breakpointKey) { BreakpointKey.MinLimit -> minLimit BreakpointKey.MaxLimit -> maxLimit else -> Breakpoint(breakpointKey, breakpointPosition, springSpec, guarantee) } } } override fun compareTo(other: Breakpoint): Int { Loading mechanics/src/com/android/mechanics/spec/builder/DirectionalBuilderImpl.kt +7 −31 Original line number Diff line number Diff line Loading @@ -87,7 +87,7 @@ internal class DirectionalBuilderImpl( check(mappings.size == breakpoints.size) } if (key == Breakpoint.maxLimit.key) { if (key == BreakpointKey.MaxLimit) { check(targetValue.isNaN()) { "cant specify target value for last segment" } check(semantics.isEmpty()) { "cant specify semantics for last breakpoint" } } else { Loading Loading @@ -330,13 +330,12 @@ internal class DirectionalBuilderImpl( guarantee: Guarantee, ): Breakpoint { val breakpoint = if (breakpointKey == Breakpoint.maxLimit.key) { check(breakpointPosition == Float.POSITIVE_INFINITY) Breakpoint.maxLimit } else { check(breakpointPosition.isFinite()) Breakpoint(checkNotNull(breakpointKey), breakpointPosition, springSpec, guarantee) } Breakpoint.create( checkNotNull(breakpointKey), breakpointPosition, springSpec, guarantee, ) breakpoints.add(breakpoint) breakpointPosition = Float.NaN Loading @@ -344,29 +343,6 @@ internal class DirectionalBuilderImpl( return breakpoint } private fun completeImpl() { if (breakpoints.last() == Breakpoint.maxLimit) { return } check(targetValue.isNaN()) { "cant specify target value for last segment" } if (!fractionalMapping.isNaN()) { check(!sourceValue.isNaN()) val sourcePosition = breakpoints.last().position mappings.add( Mapping.Linear( fractionalMapping, sourceValue - (sourcePosition * fractionalMapping), ) ) } breakpoints.add(Breakpoint.maxLimit) } } internal class SegmentSemanticValuesBuilder<T>(seed: SemanticValue<T>) { Loading Loading
mechanics/src/com/android/mechanics/spec/Breakpoint.kt +30 −2 Original line number Diff line number Diff line Loading @@ -16,6 +16,7 @@ package com.android.mechanics.spec import androidx.compose.ui.util.fastIsFinite import com.android.mechanics.spring.SpringParameters /** Loading @@ -42,6 +43,11 @@ class BreakpointKey(val debugLabel: String? = null, val identity: Any = Object() return "BreakpointKey(${debugLabel ?: ""}" + "@${System.identityHashCode(identity).toString(16).padStart(8,'0')})" } internal companion object { val MinLimit = BreakpointKey("built-in::min") val MaxLimit = BreakpointKey("built-in::max") } } /** Loading @@ -66,11 +72,20 @@ data class Breakpoint( val spring: SpringParameters, val guarantee: Guarantee, ) : Comparable<Breakpoint> { init { when (key) { BreakpointKey.MinLimit -> require(position == Float.NEGATIVE_INFINITY) BreakpointKey.MaxLimit -> require(position == Float.POSITIVE_INFINITY) else -> require(position.fastIsFinite()) } } companion object { /** First breakpoint of each spec. */ val minLimit = Breakpoint( BreakpointKey("built-in::min"), BreakpointKey.MinLimit, Float.NEGATIVE_INFINITY, SpringParameters.Snap, Guarantee.None, Loading @@ -79,11 +94,24 @@ data class Breakpoint( /** Last breakpoint of each spec. */ val maxLimit = Breakpoint( BreakpointKey("built-in::max"), BreakpointKey.MaxLimit, Float.POSITIVE_INFINITY, SpringParameters.Snap, Guarantee.None, ) internal fun create( breakpointKey: BreakpointKey, breakpointPosition: Float, springSpec: SpringParameters, guarantee: Guarantee, ): Breakpoint { return when (breakpointKey) { BreakpointKey.MinLimit -> minLimit BreakpointKey.MaxLimit -> maxLimit else -> Breakpoint(breakpointKey, breakpointPosition, springSpec, guarantee) } } } override fun compareTo(other: Breakpoint): Int { Loading
mechanics/src/com/android/mechanics/spec/builder/DirectionalBuilderImpl.kt +7 −31 Original line number Diff line number Diff line Loading @@ -87,7 +87,7 @@ internal class DirectionalBuilderImpl( check(mappings.size == breakpoints.size) } if (key == Breakpoint.maxLimit.key) { if (key == BreakpointKey.MaxLimit) { check(targetValue.isNaN()) { "cant specify target value for last segment" } check(semantics.isEmpty()) { "cant specify semantics for last breakpoint" } } else { Loading Loading @@ -330,13 +330,12 @@ internal class DirectionalBuilderImpl( guarantee: Guarantee, ): Breakpoint { val breakpoint = if (breakpointKey == Breakpoint.maxLimit.key) { check(breakpointPosition == Float.POSITIVE_INFINITY) Breakpoint.maxLimit } else { check(breakpointPosition.isFinite()) Breakpoint(checkNotNull(breakpointKey), breakpointPosition, springSpec, guarantee) } Breakpoint.create( checkNotNull(breakpointKey), breakpointPosition, springSpec, guarantee, ) breakpoints.add(breakpoint) breakpointPosition = Float.NaN Loading @@ -344,29 +343,6 @@ internal class DirectionalBuilderImpl( return breakpoint } private fun completeImpl() { if (breakpoints.last() == Breakpoint.maxLimit) { return } check(targetValue.isNaN()) { "cant specify target value for last segment" } if (!fractionalMapping.isNaN()) { check(!sourceValue.isNaN()) val sourcePosition = breakpoints.last().position mappings.add( Mapping.Linear( fractionalMapping, sourceValue - (sourcePosition * fractionalMapping), ) ) } breakpoints.add(Breakpoint.maxLimit) } } internal class SegmentSemanticValuesBuilder<T>(seed: SemanticValue<T>) { Loading