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