1

Is there an equivalent to the boundingRect function which includes the diagram's lines width(*), so that each line, however thick it is, is entirely contained within the bounding rectangle? (the boundingRect function "ignores" their thickness and parts of the lines stay outside the bounding rectangle).

(*) My question is for lines with width expressed in local units.

4

1 回答 1

1

不幸的是,目前还没有办法自动执行此操作。最简单的方法是frame在找到boundingRect. 由于您使用的是局部单位,因此您只需要将frame图中使用的局部宽度减半(如果边界矩形也有线,则添加用于边界矩形的线宽的一半)。

这是一个简单的例子:

{-# LANGUAGE GADTs #-}

import Diagrams.Prelude
import Diagrams.Backend.Rasterific.CmdLine

main :: IO ()
main = mainWith $ frame 1 rects

rects :: Diagram B
rects = hsep 1 $ map (dia <>) [br1, br2, br3]
  where
    br1 = boundingRect dia # lwL 0.2 # lc red
    br2 = boundingRect (frame 0.1 dia) # fc dodgerblue # lw none
    br3 = boundingRect (frame 0.2 dia) # lwL 0.2 # lc red

dia :: Diagram B
dia = circle 3 # fc orange # lwL 0.2

边界矩形

更通用的解决方案是使用 中的局部线宽绘制每条路径的偏移曲线Diagram并找到其边界框。Diagrams.TwoD.Offset几乎可以做到这一点,但我认为它并不适用于所有情况。

于 2016-01-21T16:28:40.193 回答