# Compose.jl has the radius of Forms tied to width

**URL:** <https://discourse.julialang.org/t/compose-jl-has-the-radius-of-forms-tied-to-width/58142>\
**Category:** Visualization\
**Created:** [March 29, 2021, 2:40am UTC](https://discourse.julialang.org/t/compose-jl-has-the-radius-of-forms-tied-to-width/58142 "2021-03-29T02:40:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![SL6Trip](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@SL6Trip](https://discourse.julialang.org/u/SL6Trip)\
**Post date:** [March 29, 2021, 2:40am UTC](https://discourse.julialang.org/t/compose-jl-has-the-radius-of-forms-tied-to-width/58142/1 "2021-03-29T02:40:12Z")

</div>

I was playing around with `Compose.jl` recently, when I realise that `Forms` that use a radius, such as `circle` have their radius tied to the width of the context window. See the two images and the code below for an example. As you can see, the first image fits nicely in the left and right halves of the image as I want, but in the second image, the radius fills to the width of the top and bottom halves, and the `circle` “exceeds” the respective halves.

![besided](https://global.discourse-cdn.com/julialang/original/3X/d/9/d9ef7f1a0fe8e135b7413b48c09df1280059da52.png)  
 ![stacked](https://global.discourse-cdn.com/julialang/original/3X/0/a/0ab4fcd9077fa883ef4ad13cbd342287e690bcc2.png)

```julia
using Compose

set_default_graphic_size(10cm, 10cm)

function beside(left, right)
    compose(
        context(),
        (context(0, 0, 0.5, 1), left),
        (context(0.5, 0, 0.5, 1), right)
    )
end

function stack(top, btm)
    compose(
        context(),
        (context(0, 0, 1, 0.5), top),
        (context(0, 0.5, 1, 0.5), btm)
    )
end

c = circle()

besided = beside(c, c)
compose(
    context(),
    besided,
    (context(), rectangle(), fill("white"))
)
besided |> SVG("besided.svg")

stacked = stack(c, c)
compose(
    context(),
    stacked,
    (context(), rectangle(), fill("white"))
)
stacked |> SVG("stacked.svg")

```

The behavior seems to persist with other “radius based” Forms like `star`, `ngon`. I’m wondering if there is any way to tell the `Form` to always use the shorter side for the radius instead of only sticking to the width?

---

<div class="post-metadata">

**Author:** ![Mattriks](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mattriks/32/351_2.png) [@Mattriks](https://discourse.julialang.org/u/Mattriks)\
**Post date:** [March 29, 2021, 8:56am UTC](https://discourse.julialang.org/t/compose-jl-has-the-radius-of-forms-tied-to-width/58142/2 "2021-03-29T08:56:19Z")

</div>

> have their radius tied to the width of the context window

By default, that’s correct. But Compose actually has 4 size units: Context (`cx`, `cy`), relative (`w`, `h`), absolute (`mm`, `pt` etc), and recently Context (“relative position”) size (`sx`, `sy`)  
(see [Compose.jl#409](https://github.com/GiovineItalia/Compose.jl/pull/409)). Units `sx`, `sy` are available in [Compose 0.9.2](https://github.com/GiovineItalia/Compose.jl/releases).

This info would also be available in the Compose docs, but there’s an unresolved issue ([Compose.jl#410](https://github.com/GiovineItalia/Compose.jl/pull/410)) 😬

Here’s your 2nd image with `sy`,`sx` units:

```julia
function stack(top, btm)
    compose(context(), fill(nothing), stroke("black"),
        (context(0, 0, 1, 0.5), top),
        (context(0, 0.5, 1, 0.5), btm)
    )
end

stack(circle(0.5w, 0.5h, 0.5sy), circle(0.5w, 0.5h, 0.5sx))

```

![Compose_units](https://global.discourse-cdn.com/julialang/original/3X/c/7/c74cdd33c04778acd44dba7826bba3e70a569077.png)

---

<div class="post-metadata">

**Author:** ![SL6Trip](https://avatars.discourse-cdn.com/v4/letter/s/4da419/32.png) [@SL6Trip](https://discourse.julialang.org/u/SL6Trip)\
**Post date:** [March 29, 2021, 9:21am UTC](https://discourse.julialang.org/t/compose-jl-has-the-radius-of-forms-tied-to-width/58142/3 "2021-03-29T09:21:54Z")

</div>

Thanks! Also I realised something really interesting. I can actually apply the `min` function on the relative units. So something like this will work:

```julia
c = circle(0.5w, 0.5h, min(0.5sx, 0.5sy))

beside(c, stack(c, c))

```

![beside_stack](https://global.discourse-cdn.com/julialang/original/3X/f/5/f5d4d246e4bb2cc650d787259d49f8d221c0823d.png)

This allows me to always take the shorter side’s radius, regardless of dimensions of the context!
