grid.polyclip: Perform Geometric Operations on Grobs

View source: R/grid.R

grid.polyclipR Documentation

Perform Geometric Operations on Grobs

Description

These functions allow two or more grobs to be combined using one of the following operations: intersection, union, minus, and xor.

Usage

polyclipGrob(A, B, op="intersection",
             openFn=xyListToLine, closedFn=xyListToPath,
             name=NULL, gp=gpar(),  ...) 
grid.polyclip(A, B, ...)

Arguments

A

A grob, gList, or gTree, or a gPath or a character value identifying a grob that has already been drawn. This is known as the subject grob.

B

A grob, gList, or gTree, or a gPath or a character value identifying a grob that has already been drawn. This is known as the clip grob.

op

A character value describing the operation. One of "intersection", "minus", "union", or "xor".

openFn

The function used to create grobs from the open shapes in the result.

closedFn

The function used to create grobs from the closed shapes in the result.

name

A name for the resulting grob.

gp

Graphical parameter settings for the resulting grob.

...

For polyclipGrob, arguments passed on to polyclip. For grid.polyclip, arguments used by methods.

Details

The subject grob is combined with the clip grob using the op operation.

The grobs are converted to coordinates by calling grid::grobCoords and then the operation is performed by calling polyclip.

The result is a new grob. In the case of grid.polyclip, this new grob will be drawn on the current device. In the special case that A is a gPath, by default, the new grob will replace the old grob (the original grob identified by A) in the current scene (and the new grob will use the same gp settings as the old grob).

The subject grob can be any combination of open or closed shapes (e.g., a combination of lines and polygons), but the clip grob must only consist of closed shapes.

Value

polyclipGrob returns a gTree with two children, one representing the open shapes within the result and one representing the closed shapes within the result.

grid.polyclip is only used for its side-effect of drawing on the current graphics device.

Author(s)

Paul Murrell

See Also

polyclip

Examples

r <- rectGrob(x=1/3, y=1/3, width=.4, height=.4)
c <- circleGrob(x=2/3, y=2/3, r=.2)
grid.draw(r)
grid.draw(c)
grid.polyclip(r, c, gp=gpar(fill="grey"))

gridGeometry documentation built on Sept. 11, 2024, 8:41 p.m.