diff --git a/docs/src/gallery/forms.md b/docs/src/gallery/forms.md index d3f6c524..8cf295a7 100644 --- a/docs/src/gallery/forms.md +++ b/docs/src/gallery/forms.md @@ -131,7 +131,7 @@ img = compose(context(), ``` -## [`slice`](@ref) +## [`sector`](@ref) ```@example using Compose set_default_graphic_size(14cm, 4cm) @@ -139,13 +139,13 @@ 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) ``` diff --git a/docs/src/tutorial.md b/docs/src/tutorial.md index 613e1f0f..8a281fdc 100644 --- a/docs/src/tutorial.md +++ b/docs/src/tutorial.md @@ -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 diff --git a/examples/arc_slice.jl b/examples/arc_sector.jl similarity index 67% rename from examples/arc_slice.jl rename to examples/arc_sector.jl index 9c8696d2..aa5bffc1 100644 --- a/examples/arc_slice.jl +++ b/examples/arc_sector.jl @@ -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)) ) diff --git a/src/Compose.jl b/src/Compose.jl index 8dfef4e3..d6f41fa4 100644 --- a/src/Compose.jl +++ b/src/Compose.jl @@ -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, diff --git a/src/cairo_backends.jl b/src/cairo_backends.jl index 4588688e..de221682 100644 --- a/src/cairo_backends.jl +++ b/src/cairo_backends.jl @@ -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 diff --git a/src/form.jl b/src/form.jl index 125461b1..41cdd1dc 100644 --- a/src/form.jl +++ b/src/form.jl @@ -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, @@ -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) diff --git a/src/pgf_backend.jl b/src/pgf_backend.jl index 3ea1d50b..50bfd32e 100644 --- a/src/pgf_backend.jl +++ b/src/pgf_backend.jl @@ -597,7 +597,7 @@ 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) ) @@ -605,7 +605,7 @@ function draw(img::PGF, prim::ArcPrimitive, idx::Int) 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 diff --git a/src/svg.jl b/src/svg.jl index e736d313..42afd6b1 100644 --- a/src/svg.jl +++ b/src/svg.jl @@ -1215,7 +1215,7 @@ function Compose.draw(img::SVG, prim::ArcPrimitive, idx::Int) indent(img) print(img.out, "\n")