Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid inserting grouping commas into large numbers #78

Merged
merged 5 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down Expand Up @@ -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()))
Expand Down Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class VectorDrawableCommandPrinter(private val decimalDigits: Int) : CommandPrin
DecimalFormat().apply {
maximumFractionDigits = decimalDigits
isDecimalSeparatorAlwaysShown = false
isGroupingUsed = false
roundingMode = RoundingMode.HALF_UP
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:viewportHeight="24.0" android:viewportWidth="24.0" android:width="24dp">
<group android:name="rotationGroup">
<path android:fillColor="#4d000000" android:name="vect" android:pathData="M17.03,5.672 15.417,5.24l0.518-1.932-3.864-1.035-0.518,1.932L9.94,3.772C9.235,3.583 8.5,4.008 8.311,4.713l-0.95,3.545 4.762,1.276 1.551-1.655-0.518,1.932 3.864,1.035 0.95-3.545c0.189-0.705-0.235-1.44-0.94-1.629"/>
<path android:fillColor="#000" android:name="draw" android:pathData="M12.251,13.191l1.932,0.518-5.805,6.209 1.424-5.313-1.932-0.518 4.254-4.554L7.361,8.258 4.341,19.53c-0.189,0.705 0.235,1.44 0.94,1.629l7.08,1.897c0.715,0.192 1.45-0.233 1.639-0.938l3.02-11.272-3.864-1.035-0.906,3.381"/>
<path android:fillColor="#4d000000" android:name="vect" android:pathData="M17.03,5.672 15.417,5.24l0.518-1.932-3.864-1.035-0.518,1.932L9.94,3.772a1.336,1.336,0,0,0,-1.629,0.94l-0.95,3.545 4.762,1.276 1.551-1.655-0.518,1.932 3.864,1.035 0.95-3.545a1.336,1.336,0,0,0,-0.94-1.629"/>
<path android:fillColor="#000" android:name="draw" android:pathData="M12.251,13.191l1.932,0.518-5.805,6.209 1.424-5.313-1.932-0.518 4.254-4.554L7.361,8.258 4.341,19.53a1.336,1.336,0,0,0,0.94,1.629l7.08,1.897A1.338,1.338,0,0,0,14,22.118l3.02-11.272-3.864-1.035-0.906,3.381"/>
</group>
</vector>
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="100dp" android:viewportHeight="100" android:viewportWidth="100" android:width="100dp">
<path android:fillColor="#444" android:fillType="evenOdd" android:pathData="M50,0C22.397,0 0,22.397 0,50c0,27.603 22.397,50 50,50 27.549,0 50-22.397 50-50 0-27.603-22.451-50-50-50Zm33.026,23.048c5.965,7.267 9.545,16.54 9.653,26.573-1.41-0.271-15.51-3.145-29.718-1.356-0.325-0.705-0.597-1.464-0.922-2.223-0.868-2.061-1.844-4.176-2.82-6.182 15.727-6.399 22.885-15.618 23.807-16.811ZM50,7.375c10.846,0 20.77,4.067 28.308,10.738-0.759,1.085-7.213,9.707-22.397,15.401-6.996-12.852-14.751-23.373-15.944-25 3.2-0.759 6.562-1.139 10.033-1.139Zm-18.167,4.013c1.139,1.518 8.731,12.093 15.835,24.675-19.957,5.314-37.581,5.206-39.479,5.206 2.766-13.232 11.714-24.241 23.644-29.881ZM7.267,50.054l0-1.301c1.844,0.054 22.56,0.325 43.872-6.074 1.247,2.386 2.386,4.826 3.471,7.267-0.542,0.163-1.139,0.325-1.681,0.488-22.017,7.104-33.731,26.519-34.707,28.145-6.779-7.538-10.954-17.57-10.954-28.525ZM50,92.733c-9.87,0-18.98-3.362-26.193-9.002 0.759-1.573 9.436-18.276 33.514-26.681 0.109-0.054 0.163-0.054 0.271-0.109 6.019,15.564 8.46,28.633 9.111,32.375C61.551,91.54 55.911,92.733 50,92.733Zm23.807-7.321c-0.434-2.603-2.712-15.076-8.297-30.423 13.395-2.115 25.108,1.356 26.573,1.844-1.844,11.876-8.677,22.126-18.275,28.579Z"/>
<path android:fillColor="#444" android:fillType="evenOdd" android:pathData="M50,0C22.397,0 0,22.397 0,50c0,27.603 22.397,50 50,50 27.549,0 50-22.397 50-50 0-27.603-22.451-50-50-50Zm33.026,23.048a42.512,42.512,0,0,1,9.653,26.573c-1.41-0.271-15.51-3.145-29.718-1.356-0.325-0.705-0.597-1.464-0.922-2.223a127.096,127.096,0,0,0,-2.82-6.182c15.727-6.399 22.885-15.618 23.807-16.811ZM50,7.375c10.846,0 20.77,4.067 28.308,10.738-0.759,1.085-7.213,9.707-22.397,15.401-6.996-12.852-14.751-23.373-15.944-25 3.2-0.759 6.562-1.139 10.033-1.139Zm-18.167,4.013c1.139,1.518 8.731,12.093 15.835,24.675-19.957,5.314-37.581,5.206-39.479,5.206 2.766-13.232 11.714-24.241 23.644-29.881ZM7.267,50.054l0-1.301c1.844,0.054 22.56,0.325 43.872-6.074 1.247,2.386 2.386,4.826 3.471,7.267-0.542,0.163-1.139,0.325-1.681,0.488-22.017,7.104-33.731,26.519-34.707,28.145-6.779-7.538-10.954-17.57-10.954-28.525ZM50,92.733c-9.87,0-18.98-3.362-26.193-9.002 0.759-1.573 9.436-18.276 33.514-26.681 0.109-0.054 0.163-0.054 0.271-0.109 6.019,15.564 8.46,28.633 9.111,32.375C61.551,91.54 55.911,92.733 50,92.733Zm23.807-7.321c-0.434-2.603-2.712-15.076-8.297-30.423 13.395-2.115 25.108,1.356 26.573,1.844-1.844,11.876-8.677,22.126-18.275,28.579Z"/>
</vector>

Large diffs are not rendered by default.

Loading