Skip to content

Commit

Permalink
Merge pull request #307 from Mattriks/sector
Browse files Browse the repository at this point in the history
Change `slice` to `sector`
  • Loading branch information
tlnagy authored Sep 25, 2018
2 parents 1936c4a + 85bb855 commit 69b4d95
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 35 deletions.
10 changes: 5 additions & 5 deletions docs/src/gallery/forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,21 +131,21 @@ img = compose(context(),
```


## [`slice`](@ref)
## [`sector`](@ref)
```@example
using Compose
set_default_graphic_size(14cm, 4cm)
colv = ["red","orange","green","blue", "purple"]
a = range(-π/4, stop=7π/4, length=6)+ 0.2*randn(6)
a[6] = a[1]
sliceobj = slice([0.5], [0.5], [0.3], a[1:5], a[2:6])
sectorobj = sector([0.5], [0.5], [0.3], a[1:5], a[2:6])
img1 = compose(context(),
(context(), sliceobj, fill(colv)) )
(context(), sectorobj, fill(colv)) )
img2 = compose(context(),
(context(), sliceobj, stroke("white"), fill(colv), linewidth(1.4mm)) )
(context(), sectorobj, stroke("white"), fill(colv), linewidth(1.4mm)) )
img3 = compose(context(),
(context(), sliceobj, stroke(colv), fill("transparent"), linewidth(1.4mm)) )
(context(), sectorobj, stroke(colv), fill("transparent"), linewidth(1.4mm)) )
hstack(img1, img2, img3)
```

Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,8 @@ These are basic constructors for the in-built forms - see the [Forms gallery](@r
* `line(points)`
* `curve(anchor0, ctrl0, ctrl1, anchor1)`
* `bitmap(mime, data, x0, y0, width, height)`
* `arc(x, y, r, angle1, angle2, slice)`
* `slice(x, y, r, angle1, angle2)`
* `arc(x, y, r, angle1, angle2, sector)`
* `sector(x, y, r, angle1, angle2)`

## Coordinates

Expand Down
6 changes: 3 additions & 3 deletions examples/arc_slice.jl → examples/arc_sector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
using Compose


imgs = [SVG("arc_slice.svg", 7cm, 7cm),
PDF("arc_slice.pdf", 7cm, 7cm)]
imgs = [SVG("arc_sector.svg", 7cm, 7cm),
PDF("arc_sector.pdf", 7cm, 7cm)]

a = range(-0.5π, stop=1.5π, length=13)
colv = repeat(["white","black"], outer=6)

img = compose(context(),
(context(), slice([0.5], [0.5], [0.4], a[1:12], a[2:13]), fill(colv)),
(context(), sector([0.5], [0.5], [0.4], a[1:12], a[2:13]), fill(colv)),
(context(order=2), arc([0.5], [0.5], [0.2], [0, π], [π,0]),
fill(["black","white"]), stroke(["white","black"]), linewidth(6pt))
)
Expand Down
2 changes: 1 addition & 1 deletion src/Compose.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Measures: resolve, w, h

export compose, compose!, Context, UnitBox, AbsoluteBoundingBox, Rotation, Mirror,
ParentDrawContext, context, ctxpromise, table, set_units!, minwidth, minheight,
text_extents, max_text_extents, polygon, line, rectangle, circle, arc, slice,
text_extents, max_text_extents, polygon, line, rectangle, circle, arc, sector,
ellipse, text, curve, bitmap, stroke, fill, strokedash, strokelinecap,
strokelinejoin, linewidth, visible, fillopacity, strokeopacity, clip,
font, fontsize, svgid, svgclass, svgattribute, jsinclude, jscall, Measure,
Expand Down
4 changes: 2 additions & 2 deletions src/cairo_backends.jl
Original file line number Diff line number Diff line change
Expand Up @@ -778,9 +778,9 @@ function Compose.draw(img::Compose.Image, prim::ArcPrimitive)
new_sub_path(img)
xc = prim.center[1]
yc = prim.center[2]
prim.slice && move_to(img, (xc, yc))
prim.sector && move_to(img, (xc, yc))
arc(img, xc.value, yc.value, prim.radius.value, prim.angle1, prim.angle2)
prim.slice && line_to(img, (xc, yc))
prim.sector && line_to(img, (xc, yc))
fillstroke(img)
end

Expand Down
36 changes: 18 additions & 18 deletions src/form.jl
Original file line number Diff line number Diff line change
Expand Up @@ -636,57 +636,57 @@ struct ArcPrimitive{P<:Vec, M<:Measure} <: Compose.FormPrimitive
radius::M
angle1::Float64
angle2::Float64
slice::Bool
sector::Bool
end

ArcPrimitive(center::P, radius::M, angle1, angle2, slice) where {P, M} = ArcPrimitive{P, M}(center, radius, angle1, angle2, slice)
ArcPrimitive(x, y, r, θ1, θ2, slice) = ArcPrimitive((x_measure(x), y_measure(y)), x_measure(r), θ1, θ2, slice)
ArcPrimitive(center::P, radius::M, angle1, angle2, sector) where {P, M} = ArcPrimitive{P, M}(center, radius, angle1, angle2, sector)
ArcPrimitive(x, y, r, θ1, θ2, sector) = ArcPrimitive((x_measure(x), y_measure(y)), x_measure(r), θ1, θ2, sector)

Arc{P<:ArcPrimitive} = Compose.Form{P}


"""
arc(x, y, r, θ1, θ2, slice)
arc(x, y, r, θ1, θ2, sector)
Define an arc with its center at (`x`,`y`), radius of `r`, between `θ1` and `θ2`.
`slice` (optional) is true or false, true for a pie slice, false for an arc.
`sector` (optional) is true or false, true for a pie sector, false for an arc.
Arcs are drawn clockwise from θ1 to θ2.
"""
function arc(x, y, r, θ1, θ2, slice=false, tag=empty_tag)
prim = ArcPrimitive(x, y, r, θ1, θ2, slice)
function arc(x, y, r, θ1, θ2, sector=false, tag=empty_tag)
prim = ArcPrimitive(x, y, r, θ1, θ2, sector)
return Arc{typeof(prim)}([prim], tag)
end

"""
slice(x, y, r, θ1, θ2)
sector(x, y, r, θ1, θ2)
Define a pie slice with its center at (`x`,`y`), radius of `r`, between `θ1` and `θ2`.
Define a pie sector with its center at (`x`,`y`), radius of `r`, between `θ1` and `θ2`.
"""
slice(x, y, r, θ1, θ2) = arc(x,y,r,θ1,θ2,true)
sector(x, y, r, θ1, θ2) = arc(x,y,r,θ1,θ2,true)

"""
arc(xs::AbstractVector, ys::AbstractVector, rs::AbstractVector, θ1s::AbstractVector, θ2s::AbstractVector, slices::AbstractVector)
arc(xs::AbstractVector, ys::AbstractVector, rs::AbstractVector, θ1s::AbstractVector, θ2s::AbstractVector, sectors::AbstractVector)
Arguments can be passed in arrays in order to perform multiple drawing operations.
"""
function arc(xs::AbstractVector, ys::AbstractVector, rs::AbstractVector, θ1s::AbstractVector, θ2s::AbstractVector, slices::AbstractVector=[false], tag=empty_tag)
return @makeform (x in xs, y in ys, r in rs, θ1 in θ1s, θ2 in θ2s, slice in slices),
ArcPrimitive((x_measure(x), y_measure(y)), x_measure(r), θ1, θ2, slice) tag
function arc(xs::AbstractVector, ys::AbstractVector, rs::AbstractVector, θ1s::AbstractVector, θ2s::AbstractVector, sectors::AbstractVector=[false], tag=empty_tag)
return @makeform (x in xs, y in ys, r in rs, θ1 in θ1s, θ2 in θ2s, sector in sectors),
ArcPrimitive((x_measure(x), y_measure(y)), x_measure(r), θ1, θ2, sector) tag
end

"""
slice(xs::AbstractVector, ys::AbstractVector, rs::AbstractVector, θ1s::AbstractVector, θ2s::AbstractVector)
sector(xs::AbstractVector, ys::AbstractVector, rs::AbstractVector, θ1s::AbstractVector, θ2s::AbstractVector)
Arguments can be passed in arrays in order to perform multiple drawing operations.
"""
slice(xs::AbstractVector, ys::AbstractVector, rs::AbstractVector, θ1s::AbstractVector, θ2s::AbstractVector) =
sector(xs::AbstractVector, ys::AbstractVector, rs::AbstractVector, θ1s::AbstractVector, θ2s::AbstractVector) =
arc(xs, ys, rs, θ1s, θ2s, [true])


resolve(box::AbsoluteBox, units::UnitBox, t::Compose.Transform, p::ArcPrimitive) =
ArcPrimitive{AbsoluteVec2, AbsoluteLength}(
resolve(box, units, t, p.center),
resolve(box, units, t, p.radius), p.angle1, p.angle2, p.slice)
resolve(box, units, t, p.radius), p.angle1, p.angle2, p.sector)

boundingbox(form::ArcPrimitive, linewidth::Measure, font::AbstractString, fontsize::Measure) =
BoundingBox(form.center[1] - form.radius - linewidth,
Expand All @@ -696,7 +696,7 @@ boundingbox(form::ArcPrimitive, linewidth::Measure, font::AbstractString, fontsi

form_string(::Arc) = "A"


@deprecate slice(x,y,r,θ1,θ2) sector(x,y,r,θ1,θ2)



Expand Down
4 changes: 2 additions & 2 deletions src/pgf_backend.jl
Original file line number Diff line number Diff line change
Expand Up @@ -597,15 +597,15 @@ function draw(img::PGF, prim::ArcPrimitive, idx::Int)
join(props, ","),
svg_fmt_float(prim.center[1].value),
svg_fmt_float(prim.center[2].value) )
prim.slice && write(img.buf, "-- ")
prim.sector && write(img.buf, "-- ")
@printf(img.buf, "+(%s:%s) ",
svg_fmt_float(rad2deg(prim.angle1)),
svg_fmt_float(prim.radius.value) )
@printf(img.buf, "arc [radius=%s, start angle=%s, end angle=%s]",
svg_fmt_float(prim.radius.value),
svg_fmt_float(rad2deg(prim.angle1)),
svg_fmt_float(rad2deg(angle2)) )
prim.slice && write(img.buf, " -- cycle")
prim.sector && write(img.buf, " -- cycle")
write(img.buf, ";\n")
end

4 changes: 2 additions & 2 deletions src/svg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ function Compose.draw(img::SVG, prim::ArcPrimitive, idx::Int)
indent(img)

print(img.out, "<path d=\"M")
prim.slice && print(img.out,"0,0 L")
prim.sector && print(img.out,"0,0 L")
svg_print_float(img.out, x1)
print(img.out, ",")
svg_print_float(img.out, y1)
Expand All @@ -1227,7 +1227,7 @@ function Compose.draw(img::SVG, prim::ArcPrimitive, idx::Int)
svg_print_float(img.out, x2)
print(img.out, ",")
svg_print_float(img.out, y2)
prim.slice && print(img.out, "L0,0")
prim.sector && print(img.out, "L0,0")
print(img.out, '"')
print(img.out, " class=\"primitive\"")
print(img.out, "/>\n")
Expand Down

0 comments on commit 69b4d95

Please sign in to comment.