forked from androidx/androidx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rework MainActivitiy App to generic Shape Editor
Relnote: Rework MainActivitiy App to generic Shape Editor Test: None, only UI changes Bug: 374043103, 374043103 Change-Id: I1ac13e43844a89d4fd9c3f59d8ce93fd3c8c45d2
- Loading branch information
bergsiek
committed
Nov 21, 2024
1 parent
ce68ec7
commit 652bf0c
Showing
16 changed files
with
2,494 additions
and
946 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...ests/testapp-compose/src/main/java/androidx/graphics/shapes/testcompose/LengthMeasurer.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Copyright 2024 The Android Open Source Project | ||
* | ||
* 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 androidx.graphics.shapes.testcompose | ||
|
||
import androidx.compose.ui.geometry.Offset | ||
import androidx.graphics.shapes.Cubic | ||
import androidx.graphics.shapes.Feature | ||
|
||
/** | ||
* Copied code from internal Measurer to measure cubics. Reason for copy: We split cubics depending | ||
* on length threshold, therefore we need a way to know their lengths. | ||
*/ | ||
internal class LengthMeasurer() { | ||
fun measureCubic(cubic: Cubic): Float { | ||
var total = 0f | ||
var prev = Offset(cubic.anchor0X, cubic.anchor0Y) | ||
|
||
for (i in 1..3) { | ||
val progress = i.toFloat() / 3 | ||
val point = cubic.pointOnCurve(progress) | ||
val segment = (point - prev).getDistance() | ||
|
||
total += segment | ||
prev = point | ||
} | ||
|
||
return total | ||
} | ||
|
||
fun measureFeature(feature: Feature): Float = feature.cubics.map { measureCubic(it) }.sum() | ||
} |
Oops, something went wrong.