diagrams / diagrams-lib

Diagrams standard library
https://diagrams.github.io/
Other
138 stars 62 forks source link

Wrong arrow endpoint with translate #309

Closed kolchanov closed 6 years ago

kolchanov commented 6 years ago

{-# LANGUAGE TypeFamilies #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE NoMonomorphismRestriction #-}

import Diagrams.Prelude import Diagrams.Backend.SVG.CmdLine

out :: Diagram B out = (rect 2 1 # named "a" ||| rect 2 1 # translateX 3 # translateY (-3) # named "b") # connect "a" "b"

main = mainWith ( out )

produces arrow with wrong endpoint

arrowissue
byorgey commented 6 years ago

Hi @kolchanov , I think the problem is that you apply named "b" after translating the rectangle. This can be a bit counterintuitive, but named always attaches a name to the local origin of the diagram, and translateX and translateY work by moving the diagram relative to the local origin. You can see this if you do rect 2 1 # translateX 3 # translateY (-3) # showOrigin, which will show you the point to which a name will be attached if you use named at that point.

I think what you want to do is just switch the call to named to come before the calls to translateX and translateY. Let us know if that works!

kolchanov commented 6 years ago

This recommendation works for me. Thank you!

byorgey commented 6 years ago

Great! Glad to help.