\path markup command computes incorrect extents when using rmoveto after closepath

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

\path markup command computes incorrect extents when using rmoveto after closepath

Aaron Hill
The logic within the \path markup command ignores the effect of
closepath when converting relative coordinates to absolute ones.  
closepath moves the pen back to the starting point of the path.  
Relative coordinates are based on the current pen position, not the most
recently specified point.  When rmoveto is used after closepath, the
value of current-point will be incorrect.

Here is an example showing the problem:

%%%%
\version "2.19.83"

% Here is the expected result (using moveto):
\markup \box \path #0.1 #'(
   (moveto 2 3) (rlineto 1 1) (rlineto 0 -1) (closepath)
   (moveto 3.5 3) (rlineto 1 1) (rlineto -1 0) (closepath))

% Here is the actual result (using rmoveto):
\markup \box \path #0.1 #'(
   (moveto 2 3) (rlineto 1 1) (rlineto 0 -1) (closepath)
   (rmoveto 1.5 0) (rlineto 1 1) (rlineto -1 0) (closepath))

% Here is a picture of what \path *thinks* is going on:
\markup \box \overlay {
   \path #0.1 #'(
     (moveto 2 3) (rlineto 1 1) (rlineto 0 -1) (closepath)
     (rmoveto 1.5 0) (rlineto 1 1) (rlineto -1 0) (closepath))
   \with-color #red \path #0.1 #'(
     (moveto 4.5 3) (rlineto 1 1) (rlineto -1 0) (closepath))
}
%%%%

The following patch seems to address the issue:

====
--- define-markup-commands.scm.bak      2020-01-19 22:09:02.904948800
-0800
+++ define-markup-commands.scm  2020-01-19 22:13:20.858573300 -0800
@@ -1179,8 +1179,15 @@
  }
  @end lilypond"
    (let* ((half-thickness (/ thickness 2))
+         (start-point '())
           (current-point '(0 . 0))
-         (set-point (lambda (lst) (set! current-point lst)))
+         (set-point (lambda (lst)
+                       (if (null? start-point)
+                         (set! start-point lst))
+                       (set! current-point lst)))
+         (reset-point (lambda ()
+                        (set! current-point start-point)
+                        (set! start-point '())))
           (relative? (lambda (x)
                        (string-prefix? "r" (symbol->string (car x)))))
           ;; For calculating extents, we want to modify the command
@@ -1224,7 +1231,7 @@
                                  (drop x 1))
                                 ;; keep closepath for filtering;
                                 ;; see `without-closepath'.
-                               (else x)))
+                               (else (reset-point) x)))
                              commands))
           ;; path-min-max does not accept 0-arg lists,
           ;; and since closepath does not affect extents, filter
====


-- Aaron Hill
_______________________________________________
bug-lilypond mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/bug-lilypond

path-bounding-bug.cropped.png (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: \path markup command computes incorrect extents when using rmoveto after closepath

Aaron Hill
On 2020-01-19 10:20 pm, Aaron Hill wrote:
> The following patch seems to address the issue:
>
> ====
> [ . . . ]
> ====

After my work on \svgPath (submitted to the main mailing list), I do not
believe the patch is correct.  closepath should only be setting
current-point to start-point, while start-point should be preserved.  
Rather, it is only on a moveto/rmoveto that the start-point would be
set.


-- Aaron Hill

_______________________________________________
bug-lilypond mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/bug-lilypond
Reply | Threaded
Open this post in threaded view
|

Re: \path markup command computes incorrect extents when using rmoveto after closepath

Schneidy
Hi Aaron,
A workaround could be to use 'make-path-stencil instead, eg.:

\version "2.19"
#(set-global-staff-size 100)

% Result using M (moveto):
\markup\box\stencil
  #(make-path-stencil
    `(M 2 3 l 1 1 l 0 -1 z M 3.5 3 l 1 1 l -1 0 z)
    .1 1 1 #f)

% Result using m (rmoveto):
\markup\box\stencil
  #(make-path-stencil
    `(M 2 3 l 1 1 l 0 -1 z m 1.5 0 l 1 1 l -1 0 z)
    .1 1 1 #f)

Cheers,
Pierre

Le lun. 20 janv. 2020 à 12:10, Aaron Hill <[hidden email]> a
écrit :

> On 2020-01-19 10:20 pm, Aaron Hill wrote:
> > The following patch seems to address the issue:
> >
> > ====
> > [ . . . ]
> > ====
>
> After my work on \svgPath (submitted to the main mailing list), I do not
> believe the patch is correct.  closepath should only be setting
> current-point to start-point, while start-point should be preserved.
> Rather, it is only on a moveto/rmoveto that the start-point would be
> set.
>
>
> -- Aaron Hill
>
> _______________________________________________
> bug-lilypond mailing list
> [hidden email]
> https://lists.gnu.org/mailman/listinfo/bug-lilypond
>
_______________________________________________
bug-lilypond mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/bug-lilypond