From 610e94f7dd0b072b611cd42e8657685720c88054 Mon Sep 17 00:00:00 2001 From: Justin Brooks Date: Sun, 15 Sep 2024 21:56:02 -0400 Subject: [PATCH 1/5] Avoid inserting grouping commas into large numbers --- .../jzbrooks/vgo/svg/ScalableVectorGraphicCommandPrinter.kt | 1 + .../kotlin/com/jzbrooks/vgo/vd/VectorDrawableCommandPrinter.kt | 1 + .../com/jzbrooks/vgo/vd/VectorDrawableOptimizationRegistry.kt | 3 ++- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/vgo/src/main/kotlin/com/jzbrooks/vgo/svg/ScalableVectorGraphicCommandPrinter.kt b/vgo/src/main/kotlin/com/jzbrooks/vgo/svg/ScalableVectorGraphicCommandPrinter.kt index 85328062..0367dc00 100644 --- a/vgo/src/main/kotlin/com/jzbrooks/vgo/svg/ScalableVectorGraphicCommandPrinter.kt +++ b/vgo/src/main/kotlin/com/jzbrooks/vgo/svg/ScalableVectorGraphicCommandPrinter.kt @@ -23,6 +23,7 @@ class ScalableVectorGraphicCommandPrinter(private val decimalDigits: Int) : Comm DecimalFormat().apply { maximumFractionDigits = decimalDigits isDecimalSeparatorAlwaysShown = false + isGroupingUsed = false roundingMode = RoundingMode.HALF_UP minimumIntegerDigits = 0 } diff --git a/vgo/src/main/kotlin/com/jzbrooks/vgo/vd/VectorDrawableCommandPrinter.kt b/vgo/src/main/kotlin/com/jzbrooks/vgo/vd/VectorDrawableCommandPrinter.kt index 61642a39..b79925ed 100644 --- a/vgo/src/main/kotlin/com/jzbrooks/vgo/vd/VectorDrawableCommandPrinter.kt +++ b/vgo/src/main/kotlin/com/jzbrooks/vgo/vd/VectorDrawableCommandPrinter.kt @@ -23,6 +23,7 @@ class VectorDrawableCommandPrinter(private val decimalDigits: Int) : CommandPrin DecimalFormat().apply { maximumFractionDigits = decimalDigits isDecimalSeparatorAlwaysShown = false + isGroupingUsed = false roundingMode = RoundingMode.HALF_UP } diff --git a/vgo/src/main/kotlin/com/jzbrooks/vgo/vd/VectorDrawableOptimizationRegistry.kt b/vgo/src/main/kotlin/com/jzbrooks/vgo/vd/VectorDrawableOptimizationRegistry.kt index a05320ba..f716e4c1 100644 --- a/vgo/src/main/kotlin/com/jzbrooks/vgo/vd/VectorDrawableOptimizationRegistry.kt +++ b/vgo/src/main/kotlin/com/jzbrooks/vgo/vd/VectorDrawableOptimizationRegistry.kt @@ -4,6 +4,7 @@ import com.jzbrooks.vgo.core.optimization.BakeTransformations import com.jzbrooks.vgo.core.optimization.BreakoutImplicitCommands import com.jzbrooks.vgo.core.optimization.CollapseGroups import com.jzbrooks.vgo.core.optimization.CommandVariant +import com.jzbrooks.vgo.core.optimization.ConvertCurvesToArcs import com.jzbrooks.vgo.core.optimization.MergePaths import com.jzbrooks.vgo.core.optimization.OptimizationRegistry import com.jzbrooks.vgo.core.optimization.Polycommands @@ -29,7 +30,7 @@ class VectorDrawableOptimizationRegistry : OptimizationRegistry(BOTTOM_UP, TOP_D BreakoutImplicitCommands(), CommandVariant(CommandVariant.Mode.Relative), SimplifyLineCommands(1e-3f), -// ConvertCurvesToArcs(VectorDrawableCommandPrinter(3)), + ConvertCurvesToArcs(VectorDrawableCommandPrinter(3)), SimplifyBezierCurveCommands(1e-3f), RemoveRedundantCommands(), CommandVariant(CommandVariant.Mode.Compact(VectorDrawableCommandPrinter(3))), From 95eda3d0e386f6ba3c7bdcc193d3220755c69144 Mon Sep 17 00:00:00 2001 From: Justin Brooks Date: Sun, 15 Sep 2024 22:09:16 -0400 Subject: [PATCH 2/5] Update baselines afer re-enabling convert curves to arc --- .../baseline/charging_battery_optimized.xml | 4 +-- .../baseline/dribbble_ball_mark_optimized.xml | 2 +- .../eleven_below_single_optimized.xml | 34 +++++++++---------- .../resources/baseline/nasa_optimized.xml | 6 ++-- .../baseline/regression_31_optimized.xml | 2 +- .../baseline/regression_33_optimized.xml | 2 +- .../baseline/simple_heart_optimized.xml | 2 +- .../resources/baseline/tiger_optimized.xml | 26 +++++++------- 8 files changed, 39 insertions(+), 39 deletions(-) diff --git a/vgo/src/test/resources/baseline/charging_battery_optimized.xml b/vgo/src/test/resources/baseline/charging_battery_optimized.xml index d7c44cea..ce5ebde8 100644 --- a/vgo/src/test/resources/baseline/charging_battery_optimized.xml +++ b/vgo/src/test/resources/baseline/charging_battery_optimized.xml @@ -1,6 +1,6 @@ - - + + diff --git a/vgo/src/test/resources/baseline/dribbble_ball_mark_optimized.xml b/vgo/src/test/resources/baseline/dribbble_ball_mark_optimized.xml index a7b31116..842a1e60 100644 --- a/vgo/src/test/resources/baseline/dribbble_ball_mark_optimized.xml +++ b/vgo/src/test/resources/baseline/dribbble_ball_mark_optimized.xml @@ -1,3 +1,3 @@ - + diff --git a/vgo/src/test/resources/baseline/eleven_below_single_optimized.xml b/vgo/src/test/resources/baseline/eleven_below_single_optimized.xml index 2b8ba72c..5c1ed8de 100644 --- a/vgo/src/test/resources/baseline/eleven_below_single_optimized.xml +++ b/vgo/src/test/resources/baseline/eleven_below_single_optimized.xml @@ -8,8 +8,8 @@ - - + + @@ -39,7 +39,7 @@ - + @@ -64,24 +64,24 @@ - + - - - + + + - - + + - - - + + + - + - + @@ -89,14 +89,14 @@ - + - + - + diff --git a/vgo/src/test/resources/baseline/nasa_optimized.xml b/vgo/src/test/resources/baseline/nasa_optimized.xml index 49e2a7fe..b18f70ec 100644 --- a/vgo/src/test/resources/baseline/nasa_optimized.xml +++ b/vgo/src/test/resources/baseline/nasa_optimized.xml @@ -1,6 +1,6 @@ - - - + + + diff --git a/vgo/src/test/resources/baseline/regression_31_optimized.xml b/vgo/src/test/resources/baseline/regression_31_optimized.xml index 442d4188..adf34053 100644 --- a/vgo/src/test/resources/baseline/regression_31_optimized.xml +++ b/vgo/src/test/resources/baseline/regression_31_optimized.xml @@ -1,3 +1,3 @@ - + diff --git a/vgo/src/test/resources/baseline/regression_33_optimized.xml b/vgo/src/test/resources/baseline/regression_33_optimized.xml index c3eec54e..ccc271e8 100644 --- a/vgo/src/test/resources/baseline/regression_33_optimized.xml +++ b/vgo/src/test/resources/baseline/regression_33_optimized.xml @@ -1,3 +1,3 @@ - + diff --git a/vgo/src/test/resources/baseline/simple_heart_optimized.xml b/vgo/src/test/resources/baseline/simple_heart_optimized.xml index c1ca9b04..ca3d67c5 100644 --- a/vgo/src/test/resources/baseline/simple_heart_optimized.xml +++ b/vgo/src/test/resources/baseline/simple_heart_optimized.xml @@ -1,3 +1,3 @@ - + diff --git a/vgo/src/test/resources/baseline/tiger_optimized.xml b/vgo/src/test/resources/baseline/tiger_optimized.xml index 8931d88e..ee8e851f 100644 --- a/vgo/src/test/resources/baseline/tiger_optimized.xml +++ b/vgo/src/test/resources/baseline/tiger_optimized.xml @@ -60,7 +60,7 @@ - + @@ -81,34 +81,34 @@ - - + + - + - - + + - - - - - + + + + + - + @@ -136,7 +136,7 @@ - + From a8af5b787ce69bda3603627b84e2371110ebd769 Mon Sep 17 00:00:00 2001 From: Justin Brooks Date: Sun, 15 Sep 2024 22:14:03 -0400 Subject: [PATCH 3/5] Add a regression case --- .../resources/baseline/regression_60_optimized.xml | 3 +++ vgo/src/test/resources/regression_60.xml | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 vgo/src/test/resources/baseline/regression_60_optimized.xml create mode 100644 vgo/src/test/resources/regression_60.xml diff --git a/vgo/src/test/resources/baseline/regression_60_optimized.xml b/vgo/src/test/resources/baseline/regression_60_optimized.xml new file mode 100644 index 00000000..c5d09ade --- /dev/null +++ b/vgo/src/test/resources/baseline/regression_60_optimized.xml @@ -0,0 +1,3 @@ + + + diff --git a/vgo/src/test/resources/regression_60.xml b/vgo/src/test/resources/regression_60.xml new file mode 100644 index 00000000..b53e2fbb --- /dev/null +++ b/vgo/src/test/resources/regression_60.xml @@ -0,0 +1,13 @@ + + + \ No newline at end of file From 01c584097c3d1343d8c01b79463f5582623cdccd Mon Sep 17 00:00:00 2001 From: Justin Brooks Date: Sun, 15 Sep 2024 22:23:49 -0400 Subject: [PATCH 4/5] Use consistent tolerences for circle fits --- .../core/optimization/ConvertCurvesToArcs.kt | 6 ++-- .../baseline/dribbble_ball_mark_optimized.xml | 2 +- .../eleven_below_single_optimized.xml | 34 +++++++++---------- .../resources/baseline/nasa_optimized.xml | 4 +-- .../baseline/regression_33_optimized.xml | 2 +- .../baseline/regression_60_optimized.xml | 2 +- .../resources/baseline/tiger_optimized.xml | 26 +++++++------- 7 files changed, 38 insertions(+), 38 deletions(-) diff --git a/vgo-core/src/main/kotlin/com/jzbrooks/vgo/core/optimization/ConvertCurvesToArcs.kt b/vgo-core/src/main/kotlin/com/jzbrooks/vgo/core/optimization/ConvertCurvesToArcs.kt index 510da821..351a8da1 100644 --- a/vgo-core/src/main/kotlin/com/jzbrooks/vgo/core/optimization/ConvertCurvesToArcs.kt +++ b/vgo-core/src/main/kotlin/com/jzbrooks/vgo/core/optimization/ConvertCurvesToArcs.kt @@ -20,7 +20,7 @@ import com.jzbrooks.vgo.core.util.math.liesOnCircle import com.jzbrooks.vgo.core.util.math.toCubicBezierCurve /** - * Converts cubic bezier curves to arcs, when they are shorter. + * Converts cubic Bézier curves to arcs, when they are shorter. */ class ConvertCurvesToArcs(private val printer: CommandPrinter) : TopDownOptimization { override fun visit(graphic: Graphic) {} @@ -148,7 +148,7 @@ class ConvertCurvesToArcs(private val printer: CommandPrinter) : TopDownOptimiza } // If the next curve is a shorthand, it must be converted - // to longhand if it the previous curve is replaced with an + // to longhand if it is the previous curve is replaced with an // elliptical arc. if (nextCommand is SmoothCubicBezierCurve) { ellipticalArcs.add(nextCommand.toCubicBezierCurve(pendingCurves.last())) @@ -191,7 +191,7 @@ class ConvertCurvesToArcs(private val printer: CommandPrinter) : TopDownOptimiza assert(command.parameters.size == 1) val currentParameter = command.parameters[0] - val circle = command.fitCircle(1e-2f) + val circle = command.fitCircle() if (circle != null && command.isConvex()) { val radius = circle.radius val sweep = diff --git a/vgo/src/test/resources/baseline/dribbble_ball_mark_optimized.xml b/vgo/src/test/resources/baseline/dribbble_ball_mark_optimized.xml index 842a1e60..431451df 100644 --- a/vgo/src/test/resources/baseline/dribbble_ball_mark_optimized.xml +++ b/vgo/src/test/resources/baseline/dribbble_ball_mark_optimized.xml @@ -1,3 +1,3 @@ - + diff --git a/vgo/src/test/resources/baseline/eleven_below_single_optimized.xml b/vgo/src/test/resources/baseline/eleven_below_single_optimized.xml index 5c1ed8de..5856851e 100644 --- a/vgo/src/test/resources/baseline/eleven_below_single_optimized.xml +++ b/vgo/src/test/resources/baseline/eleven_below_single_optimized.xml @@ -8,8 +8,8 @@ - - + + @@ -39,7 +39,7 @@ - + @@ -64,24 +64,24 @@ - + - - - + + + - - + + - - - + + + - + - + @@ -89,14 +89,14 @@ - + - + - + diff --git a/vgo/src/test/resources/baseline/nasa_optimized.xml b/vgo/src/test/resources/baseline/nasa_optimized.xml index b18f70ec..6ccb97ed 100644 --- a/vgo/src/test/resources/baseline/nasa_optimized.xml +++ b/vgo/src/test/resources/baseline/nasa_optimized.xml @@ -1,6 +1,6 @@ - - + + diff --git a/vgo/src/test/resources/baseline/regression_33_optimized.xml b/vgo/src/test/resources/baseline/regression_33_optimized.xml index ccc271e8..db9fe912 100644 --- a/vgo/src/test/resources/baseline/regression_33_optimized.xml +++ b/vgo/src/test/resources/baseline/regression_33_optimized.xml @@ -1,3 +1,3 @@ - + diff --git a/vgo/src/test/resources/baseline/regression_60_optimized.xml b/vgo/src/test/resources/baseline/regression_60_optimized.xml index c5d09ade..3b63bfa3 100644 --- a/vgo/src/test/resources/baseline/regression_60_optimized.xml +++ b/vgo/src/test/resources/baseline/regression_60_optimized.xml @@ -1,3 +1,3 @@ - + diff --git a/vgo/src/test/resources/baseline/tiger_optimized.xml b/vgo/src/test/resources/baseline/tiger_optimized.xml index ee8e851f..99a0a71b 100644 --- a/vgo/src/test/resources/baseline/tiger_optimized.xml +++ b/vgo/src/test/resources/baseline/tiger_optimized.xml @@ -60,7 +60,7 @@ - + @@ -81,34 +81,34 @@ - - + + - + - - + + - - - - - + + + + + - + @@ -136,7 +136,7 @@ - + From cca07e5f42926ed372c6a78ab822b2b77daade6a Mon Sep 17 00:00:00 2001 From: Justin Brooks Date: Sun, 15 Sep 2024 22:31:56 -0400 Subject: [PATCH 5/5] Add a changelog entry --- changelog.md | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/changelog.md b/changelog.md index ba4e3d55..98c81c2d 100644 --- a/changelog.md +++ b/changelog.md @@ -2,17 +2,9 @@ ## Unreleased -### Added - -### Changed - -### Deprecated - -### Removed - ### Fixed -### Security +- A bug that would sometimes introduce a grouping comma into a large number, breaking path data. This most often occurred in the convert curves to arcs optimization when an arc with a large radius was more compact than the corresponding Bézier curve. ## 2.2.2 - 2024-08-30