fix crash on: STORE STORE

Co-authored-by: @tonino
This commit is contained in:
Mylloon 2024-05-06 18:26:50 +02:00
parent 916ffc8281
commit d536a37f86
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -13,6 +13,14 @@
<xsl:variable name="initial-angle" select="0"
as="xs:double" />
<!-- Séquences pour stocker les états -->
<xsl:variable name="x-values" select="()"
as="xs:double*" />
<xsl:variable name="y-values" select="()"
as="xs:double*" />
<xsl:variable name="angle-values"
as="xs:double*" select="()" />
<xsl:template match="/tortue">
<xsl:processing-instruction name="xml-model">href="traceur.xsd"</xsl:processing-instruction>
@ -28,8 +36,12 @@
select="$initial-y" />
<xsl:with-param name="angle"
select="$initial-angle" />
<xsl:with-param name="states"
select="()" />
<xsl:with-param name="x-values"
select="$x-values" />
<xsl:with-param name="y-values"
select="$y-values" />
<xsl:with-param name="angle-values"
select="$angle-values" />
</xsl:call-template>
</traceur>
</xsl:template>
@ -46,7 +58,11 @@
<xsl:param
name="angle" />
<xsl:param
name="states" />
name="x-values" />
<xsl:param
name="y-values" />
<xsl:param
name="angle-values" />
<!-- Si il reste des commandes à traiter -->
<xsl:if test="$commands">
@ -86,7 +102,11 @@
<xsl:with-param
name="angle" select="$angle" />
<xsl:with-param
name="states" select="$states" />
name="x-values" select="$x-values" />
<xsl:with-param
name="y-values" select="$y-values" />
<xsl:with-param
name="angle-values" select="$angle-values" />
</xsl:call-template>
</xsl:when>
@ -101,16 +121,20 @@
position mais en mettant à jour l'angle -->
<xsl:call-template
name="process-commands">
<xsl:with-param
name="commands" select="$commands[position() > 1]" />
<xsl:with-param
name="x" select="$x" />
<xsl:with-param
name="y" select="$y" />
<xsl:with-param
name="angle" select="$new-angle" />
<xsl:with-param name="states"
select="$states" />
<xsl:with-param name="commands"
select="$commands[position() > 1]" />
<xsl:with-param name="x"
select="$x" />
<xsl:with-param name="y"
select="$y" />
<xsl:with-param name="angle"
select="$new-angle" />
<xsl:with-param name="x-values"
select="$x-values" />
<xsl:with-param name="y-values"
select="$y-values" />
<xsl:with-param name="angle-values"
select="$angle-values" />
</xsl:call-template>
</xsl:when>
@ -137,30 +161,34 @@
des coordonnées et des commandes restantes -->
<xsl:call-template
name="process-commands">
<xsl:with-param
name="commands" select="$commands[position() > 1]" />
<xsl:with-param
name="x" select="$new-x" />
<xsl:with-param
name="y" select="$new-y" />
<xsl:with-param
name="angle" select="$angle" />
<xsl:with-param name="states"
select="$states" />
<xsl:with-param name="commands"
select="$commands[position() > 1]" />
<xsl:with-param name="x"
select="$new-x" />
<xsl:with-param name="y"
select="$new-y" />
<xsl:with-param name="angle"
select="$angle" />
<xsl:with-param name="x-values"
select="$x-values" />
<xsl:with-param name="y-values"
select="$y-values" />
<xsl:with-param name="angle-values"
select="$angle-values" />
</xsl:call-template>
</xsl:when>
<!-- Si la commande est un store -->
<xsl:when test="local-name($current-command) = 'store'">
<!-- On enregistre le nouvelle état -->
<xsl:variable name="new-state">
<state x="{$x}" y="{$y}" angle="{$angle}" />
</xsl:variable>
<!-- On l'ajoute au précédent -->
<xsl:variable
name="new-states" select="($states, $new-state)" />
<xsl:call-template
name="process-commands">
<xsl:variable name="new-x-values"
select="($x-values, $x)" />
<xsl:variable name="new-y-values"
select="($y-values, $y)" />
<xsl:variable name="new-angle-values"
select="($angle-values, $angle)" />
<!-- Appel récursif -->
<xsl:call-template name="process-commands">
<xsl:with-param name="commands"
select="$commands[position() > 1]" />
<xsl:with-param name="x"
@ -169,27 +197,27 @@
select="$y" />
<xsl:with-param name="angle"
select="$angle" />
<xsl:with-param name="states"
select="$new-states" />
<xsl:with-param name="x-values"
select="$new-x-values" />
<xsl:with-param name="y-values"
select="$new-y-values" />
<xsl:with-param name="angle-values"
select="$new-angle-values" />
</xsl:call-template>
</xsl:when>
<!-- Si la commande est un restore -->
<xsl:when test="local-name($current-command) = 'restore' and count($x-values) > 0">
<xsl:variable name="last-x"
select="$x-values[last()]" />
<xsl:variable name="last-y"
select="$y-values[last()]" />
<xsl:variable name="last-angle"
select="$angle-values[last()]" />
<!-- Si la commande est un restore et que au moins
un état est enregistré -->
<xsl:when test="local-name($current-command) = 'restore' and count($states) >= 1">
<!-- On séléctionne notre state (Revoir pourquoi ceci marche) -->
<xsl:variable
name="state"
select="$states/state[1]" />
<xsl:variable
name="remaining-states"
select="subsequence($states/state, 1, count($states/state) - 1)" />
<!-- Création de l'élément MOVETO avec les nouvelles
coordonnées restaurées -->
<!-- Création de l'élément MOVETO -->
<MOVETO
x="{format-number($states/state[last()]/@x, '#.######')}"
y="{format-number($states/state[last()]/@y, '#.######')}" />
x="{format-number($last-x, '#.######')}"
y="{format-number($last-y, '#.######')}" />
<!-- Appel récursif -->
<xsl:call-template
@ -197,13 +225,17 @@
<xsl:with-param name="commands"
select="$commands[position() > 1]" />
<xsl:with-param name="x"
select="($state/@x)[last()]" />
select="$last-x" />
<xsl:with-param name="y"
select="($state/@y)[last()]" />
select="$last-y" />
<xsl:with-param name="angle"
select="($state/@angle)[last()]" />
<xsl:with-param name="states"
select="$remaining-states" />
select="$last-angle" />
<xsl:with-param name="x-values"
select="subsequence($x-values, 1, count($x-values) - 1)" />
<xsl:with-param name="y-values"
select="subsequence($y-values, 1, count($y-values) - 1)" />
<xsl:with-param name="angle-values"
select="subsequence($angle-values, 1, count($angle-values) - 1)" />
</xsl:call-template>
</xsl:when>
</xsl:choose>