Skip to content

Commit

Permalink
Merge pull request #359 from Mattriks/clip_docs
Browse files Browse the repository at this point in the history
Clip example
  • Loading branch information
tlnagy authored Oct 8, 2019
2 parents a081070 + f03d2b6 commit 2b561b0
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
18 changes: 18 additions & 0 deletions docs/src/gallery/properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,24 @@ img = compose(context(), arrow(), stroke("black"), fill(nothing),
)
```

## [`clip`](@ref)

```@example
using Colors, Compose
set_default_graphic_size(14cm,7cm)
X = rand(10,2)
colv = HSVA.(range(0,stop=180,length=10), 1, 1, 0.5)
img = compose(context(units=UnitBox(0,0,2,1)), stroke("black"),
(context(), rectangle(), fill(nothing)),
(context(), ngon([0.5,1.5],[0.5], [0.4], [10]), fill(nothing), stroke("lightgray")),
(context(), xgon(X[:,1],X[:,2],[0.2],[4]), fill(colv)),
(context(), xgon(X[:,1].+1,X[:,2],[0.2],[4]), fill(colv),
clip(points(ngon(1.5,0.5, 0.4, 10))) )
)
```



## [`fill`](@ref), [`fillopacity`](@ref)

```@example
Expand Down
4 changes: 2 additions & 2 deletions src/Compose.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export compose, compose!, Context, UnitBox, AbsoluteBoundingBox,
ParentDrawContext, context, ctxpromise, table, set_units!, minwidth, minheight,
text_extents, max_text_extents, polygon, ngon, star, xgon,
line, rectangle, circle, arc, sector, ellipse, text, curve, bitmap,
stroke, fill, strokedash, strokelinecap, arrow,
strokelinejoin, linewidth, visible, fillopacity, strokeopacity, clip,
stroke, fill, strokedash, strokelinecap, arrow, strokelinejoin,
linewidth, visible, fillopacity, strokeopacity, clip, points,
font, fontsize, svgid, svgclass, svgattribute, jsinclude, jscall, Measure,
inch, mm, cm, pt, px, cx, cy, w, h, hleft, hcenter, hright, vtop, vcenter,
vbottom, SVG, SVGJS, PGF, PNG, PS, PDF, draw, pad, pad_inner, pad_outer,
Expand Down
6 changes: 6 additions & 0 deletions src/form.jl
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,12 @@ function xgon(xs::AbstractVector, ys::AbstractVector, rs::AbstractVector, ns::Ab
return Form{PrimType}(polyprims, tag)
end

"""
points(x::Compose.Form)
Extract points from a Compose.Form
"""
points(x::Compose.Form) = x.primitives[1].points



Expand Down
12 changes: 12 additions & 0 deletions src/property.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,12 @@ const Clip = Property{ClipPrimitive}

clip() = Clip([ClipPrimitive(Array{Vec}(undef, 0))])


"""
clip(points::AbstractArray)
`clip()` is a property. Only forms inside the clip shape will be visible.
"""
function clip(points::AbstractArray{T}) where T <: XYTupleOrVec
XM, YM = narrow_polygon_point_types(Vector[points])
if XM == Any
Expand All @@ -273,6 +279,12 @@ function clip(points::AbstractArray{T}) where T <: XYTupleOrVec
return Clip(typeof(prim)[prim])
end


"""
clip(point_arrays::AbstractArray...)
Arguments can be passed in arrays in order to perform multiple clipping operations at once.
"""
function clip(point_arrays::AbstractArray...)
XM, YM = narrow_polygon_point_types(point_arrays)
VecType = XM == YM == Any ? Vec : Vec{XM, YM}
Expand Down

0 comments on commit 2b561b0

Please sign in to comment.