A method for laying out diagrams using a circle packing algorithm. For details on the algorithm, see Optimisation.CirclePacking in the module circle-packing.
Here is an example:
import Optimisation.CirclePacking colorize = zipWith fc $ cycle [red,blue,yellow,magenta,cyan,bisque,firebrick,indigo] objects = colorize $ [ circle r | r <- [0.1,0.2..1.6] ] ++ [ hexagon r | r <- [0.1,0.2..0.7] ] ++ [ decagon r | r <- [0.1,0.2..0.7] ] -- Just a approximation, diagram objects do not have an exact radius radiusApproximation o = maximum [ radius (e (alpha :: Turn)) o | alpha <- [0,0.1..1.0]] circlePackingExample = position $ map (\(o,(x,y)) -> (p2 (x,y),o)) $ packCircles radiusApproximation objects
- renderCirclePacking :: Monoid' m => RadiusFunction b m -> [QDiagram b R2 m] -> QDiagram b R2 m
- createCirclePacking :: Monoid' m => (a -> Double) -> (a -> QDiagram b R2 m) -> [a] -> QDiagram b R2 m
- type RadiusFunction b m = QDiagram b R2 m -> Double
- approxRadius :: Int -> RadiusFunction b m
- circleRadius :: RadiusFunction b m
Combines the passed objects, whose radius is estimated using the given
RadiusFunction, so that they do not overlap (according to the radius
function) and otherwise form, as far as possible, a tight circle.
More general version of
renderCirclePacking. You can use this if you
have more information available in the values of type
a that allows you to
calculate the radius better (or even exactly).
A safe approximation. Calculates the outer radius of the smallest axis-aligned polygon with the given number of edges that contains the object. A parameter of 4 up to 8 should be sufficient for most applications.