Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parse arc flags without digit separator
Browse files Browse the repository at this point in the history
jzbrooks committed Jan 18, 2025
1 parent c5d5275 commit a97c0c8
Showing 2 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -109,10 +109,16 @@ value class CommandString(
number
.findAll(command)
.map(MatchResult::value)
.map(String::toFloat)
.chunked(7)
.map {
if (it.size == 6) {
it.take(3).map { it.toFloat() } + it[3].map { it.toString().toFloat() } +
it.drop(4).map { it.toFloat() }
} else {
it.map { it.toFloat() }
}
}.toList()
.map(::mapEllipticalArcCurveParameter)
.toList()

EllipticalArcCurve(variant, parameters)
}
Original file line number Diff line number Diff line change
@@ -5,12 +5,14 @@ import assertk.assertFailure
import assertk.assertThat
import assertk.assertions.containsExactly
import assertk.assertions.containsOnly
import assertk.assertions.first
import assertk.assertions.hasClass
import assertk.assertions.index
import assertk.assertions.isEqualTo
import assertk.assertions.isInstanceOf
import assertk.assertions.prop
import com.jzbrooks.vgo.core.util.math.Point
import jdk.javadoc.internal.doclets.formats.html.markup.HtmlStyle.parameters
import org.junit.jupiter.api.Test

class ParserTests {
@@ -200,6 +202,30 @@ class ParserTests {
)
}

@Test
fun testArcParameterWithoutCommaBetweenFlags() {
val pathCommandString = "M1,1 A 1,1,0,01,3,3"

val commands = CommandString(pathCommandString).toCommandList()

assertThat(commands).containsExactly(
moveToSingle,
EllipticalArcCurve(
CommandVariant.ABSOLUTE,
listOf(
EllipticalArcCurve.Parameter(
1f,
1f,
0f,
EllipticalArcCurve.ArcFlag.SMALL,
EllipticalArcCurve.SweepFlag.CLOCKWISE,
Point(3f, 3f),
),
),
),
)
}

@Test
fun testParseRelativeCommandString() {
val pathCommandString = "l2 5"
@@ -220,7 +246,7 @@ class ParserTests {

val lineCommand = commands[0] as LineTo

assertThat(lineCommand.parameters[0]).isEqualTo(Point(2.1f, 5f))
assertThat(lineCommand::parameters).first().isEqualTo(Point(2.1f, 5f))
}

@Test
@@ -231,7 +257,7 @@ class ParserTests {

val lineCommand = commands[0] as LineTo

assertThat(lineCommand.parameters[0]).isEqualTo(Point(200f, 5f))
assertThat(lineCommand::parameters).first().isEqualTo(Point(200f, 5f))
}

@Test

0 comments on commit a97c0c8

Please sign in to comment.