Skip to content

Commit

Permalink
final edits
Browse files Browse the repository at this point in the history
  • Loading branch information
pmur002 committed May 31, 2022
1 parent 91c5e47 commit da0b35e
Show file tree
Hide file tree
Showing 55 changed files with 334 additions and 211 deletions.
10 changes: 7 additions & 3 deletions Dockerfile
Expand Up @@ -23,6 +23,10 @@ RUN apt-get update && apt-get install -y \
libgit2-dev
RUN Rscript -e 'install.packages(c("knitr", "devtools"), repos="https://cran.rstudio.com/")'
RUN Rscript -e 'library(devtools); install_version("xml2", "1.3.2", repos="https://cran.rstudio.com/")'
RUN apt-get install -y \
libmagick++-dev \
libpoppler-cpp-dev
RUN Rscript -e 'library(devtools); install_version("gdiff", "0.2-3", repos="https://cran.rstudio.com/")'

# Tools used in the report
RUN apt-get install -y librsvg2-dev
Expand All @@ -35,9 +39,9 @@ RUN Rscript -e 'library(devtools); install_version("grImport2", "0.2-0", repos="
# Package dependencies

# Using COPY will update (invalidate cache) if the tar ball has been modified!
COPY gridGeometry_0.3-1.tar.gz .
RUN R CMD INSTALL gridGeometry_0.3-1.tar.gz
# RUN Rscript -e 'devtools::install_github("pmur002/gridGeometry@v0.3-1")'
# COPY gridGeometry_0.3-1.tar.gz .
# RUN R CMD INSTALL gridGeometry_0.3-1.tar.gz
RUN Rscript -e 'devtools::install_github("pmur002/gridGeometry@v0.3-1")'

RUN apt-get install -y locales && locale-gen en_US.UTF-8
ENV LANG en_US.UTF-8
Expand Down
9 changes: 5 additions & 4 deletions Makefile
@@ -1,13 +1,12 @@

TARFILE = ../coords-deposit-$(shell date +'%Y-%m-%d').tar.gz

ifndef Rscript
# For building on my office desktop
# Rscript = ~/R/r-devel-vecpat/BUILD/bin/Rscript
# Rscript = ~/R/r-devel/BUILD/bin/Rscript
# Rscript = Rscript

# For building in Docker container
Rscript = Rscript
endif

%.xml: %.cml %.bib
# Protect HTML special chars in R code chunks
Expand All @@ -23,11 +22,13 @@ Rscript = Rscript
%.html : %.Rhtml
# Use knitr to produce HTML
$(Rscript) knit.R $*.Rhtml
# Check that figures have not changed
$(Rscript) gdiff.R

docker:
cp ../../gridGeometry_0.3-1.tar.gz .
sudo docker build -t pmur002/coords-report .
sudo docker run -v $(shell pwd):/home/work/ -w /home/work --rm pmur002/coords-report make coords.html
sudo docker run -e Rscript=Rscript -v $(shell pwd):/home/work/ -w /home/work --rm pmur002/coords-report make coords.html

web:
make docker
Expand Down
20 changes: 18 additions & 2 deletions coords-bib.html
Expand Up @@ -46,10 +46,10 @@


<dt>
[<a name="pkg:gridGeometry">Murrell, 2022</a>]
[<a name="pkg:gridGeometry">Murrell, 2022a</a>]
</dt>
<dd>
Murrell, P. (2022).
Murrell, P. (2022a).
<em>gridGeometry: Polygon Geometry in 'grid'</em>.
https://github.com/pmur002/gridgeometry,
https://stattech.wordpress.fos.auckland.ac.nz/2019/03/04/2019-01-a-geometry-engine-interface-for-grid/.
Expand All @@ -58,6 +58,22 @@
</dd>


<dt>
[<a name="murrell-vecpat-2022">Murrell, 2022b</a>]
</dt>
<dd>
Murrell, P. (2022b).
Vectorised pattern fills in r graphics.
Technical Report 2022-01, Department of Statistics, The University of
Auckland.
version 1.
[&nbsp;<a href="coords-bib_bib.html#murrell-vecpat-2022">bib</a>&nbsp;|
<a href="http://dx.doi.org/10.17608/k6.auckland.19945787">DOI</a>&nbsp;|
<a href="https://stattech.blogs.auckland.ac.nz/2022/06/01/2022-01">http</a>&nbsp;]

</dd>


<dt>
[<a name="pkg:rsvg">Ooms, 2022</a>]
</dt>
Expand Down
100 changes: 58 additions & 42 deletions coords-bib.xml
Expand Up @@ -78,8 +78,8 @@ options(bitmapType="cairo")
the <code>grobCoords()</code> function.
</p>
<p>
These features are available in the development version of R
(to become 4.2.0) and in 'gridGeometry' version 0.3-0.
These features are available in R version 4.2.0
and in 'gridGeometry' version 0.3-0.
</p>
<div>
<h2>Table of Contents:</h2>
Expand Down Expand Up @@ -142,7 +142,7 @@ coords <- grobCoords(rectangle, closed = TRUE)
coords
]]></rcode>
<p>
The 'gridGeometry' package (<a href="#pkg:gridGeometry">Murrell, 2022</a>)
The 'gridGeometry' package (<a href="#pkg:gridGeometry">Murrell, 2022a</a>)
combines 'grid' grobs using
operators like "union" and "intersection".
For example, in the following code we define a triangle shape
Expand Down Expand Up @@ -214,7 +214,7 @@ class(coords)
<p>
That additional information becomes more important when
we work with a grob that draws more than one shape.
For example, the following code defines a grob that draws
For example, the following code defines a grob that describes
two rectangles (and draws them) and then calculates the
coordinates from that grob. The result shows coordinates
for two shapes, both of which belong to "grob r2".
Expand Down Expand Up @@ -296,7 +296,7 @@ grobCoords(gt, closed = TRUE)
because the children of a gTree can themselves
be gTrees, but hopefully it is now clear how that would go.
We will turn instead to an example of how the coordinates
from <code>grobCoords()</code>
that <code>grobCoords()</code> returns
can be used, by looking at the latest changes to the
'gridGeometry' package.
</p>
Expand Down Expand Up @@ -375,8 +375,8 @@ grid.polyclip(rectangle, circle, "minus", reduceB = "xor",
]]></rcode>
<p>
There is also a new function, <code>grid.reduce()</code>, that just performs
this grob reduction. This function
takes a grob and reduces it a new grob that describes a single
the grob reduction. This function
takes a grob and reduces it to a new grob that describes a single
shape (either a path or a line).
For example, the following code reduces the grob that
draws three circles into a single shape using "xor".
Expand Down Expand Up @@ -442,13 +442,10 @@ grid.ls(logoGrob)
grid.draw(logoGrob)
]]></rcode>
<p>
The following code calls <code>xyListFromGrob()</code> to convert
that complicated gTree to a single shape using the default
The following code calls <code>grid.reduce()</code> to convert
that complicated gTree to a single shape (using the default
"union" operator). This forms the union of the "R" shape with the ellipse
shape.
We then convert the result back to a path grob with
<code>xyListToPath()</code>
and draw it.
</p>
<rcode fig.width="2" fig.height="2"><![CDATA[
grid.reduce(logoGrob, gp=gpar(fill="grey"))
Expand Down Expand Up @@ -663,8 +660,6 @@ ggc
</p>
<p>
This represents the shapes that are described by a 'grid' gTree.
</p>
<p>
The list has a <code>"name"</code> attribute.
</p>
<p>
Expand Down Expand Up @@ -710,7 +705,7 @@ ggtc2
to convert <code>grobCoords()</code> output to a list of xy-lists.
</p>
<p>
<!-- pdflatex diagram.tex; convert diagram.pdf diagram.png -->
<!-- pdflatex diagram.tex; convert -density 96 diagram.pdf diagram.png -->
<img src="diagram.png"/>
</p>
<p>
Expand All @@ -731,8 +726,8 @@ ggtc2
in <code>reduceA</code> or <code>reduceB</code>.
A gTree reduces each of its children and then combines the
reduced children together.
This function provides another way to enter the 'polyclip'
world, starting from a 'grid' grob.
This function provides a to enter the 'polyclip'
world of lists of xy-lists, starting from a 'grid' grob.
</p>
<p>
The functions <code>xyListToPath()</code>,
Expand Down Expand Up @@ -779,10 +774,11 @@ ggtc2
The <code>grobCoords()</code> function has a <code>closed</code>
argument to indicate whether we want the coordinates of a closed
shape or an open shape.
From R 4.3.0, and in 'gridGeometry' &gt;= 0.3-1, where it can
From R 4.3.0 or from 'gridGeometry' 0.3-1, where it can
be determined that the grob is open, <code>closed</code> defaults
to <code>FALSE</code>. Otherwise, <code>closed</code> defaults
to <code>TRUE</code>.
to <code>TRUE</code>. Prior to that, the <code>closed</code>
argument must be specified explicitly.
</p>
<p>
When we ask for the coordinates from a polygon grob,
Expand Down Expand Up @@ -832,20 +828,15 @@ grid.polyclip(gTree(children=gList(rectGrob(width=.5, height=.5),
</p>
<h3>To reduce or not to reduce</h3>
<p>
Another question is whether, although we have to do some reducing for
complex grobCoords() results (e.g., from a gTree),
do we need to reduce coords from simple
collections of shapes, e.g.,
a rect grob that draws multiple shapes?
'polyclip' (and the Clipper
library) can handle a list of xy-lists.
The answer to that is that we CAN simply pass through a list
of xy-lists (one per shape) by specifying op="flatten" !
That is not the *default* value for closed shapes, but we
can explicitly specify it if we want to!
NOTE that if we pass the list of xy-lists to 'polyclip',
we still have to give it a fill rule, AND then we have to
provide a fill rule when turning the result back into a grob.
By default, any grob (including gTrees) that draws more than one
shape will be reduced. When <code>closed=TRUE</code>, the
result will be a single shape based on the union of the multiple shapes.
The 'polyclip' package (and the Clipper
library) will accept a list of xy-lists, i.e., multiple shapes,
so should we always reduce multiple shapes to a single shape?
By default, we do always reduce, but the user has the option
of specifying <code>op="flatten"</code>, which will result in
sending multiple shapes to 'polyclip'.
</p>
<h2>
<a name="discussion">6. Discussion</a>
Expand All @@ -865,17 +856,26 @@ grid.polyclip(gTree(children=gList(rectGrob(width=.5, height=.5),
<p>
The grobCoords() function is also
used by 'grid' itself for resolving fill patterns
(by making use of the names on <code>grobCoords()</code> output),
as described in the vecpat tech report.
Here the extra information is important because it allows
(<a href="#murrell-vecpat-2022">Murrell, 2022b</a>),
by making use of the names on <code>grobCoords()</code> output.
In that case, the extra information is important because it allows
us to resolve a pattern relative to individual shapes within a grob
as well as relative to the bounding box around all shapes within a
grob.
</p>
<p>
It is also hoped that the extra information may prove useful to
It is also hoped that the extra information provided by
<code>grobCoords()</code> may prove useful to
code writers and package developers that make use of
<code>grobCoords()</code> output.
One speculative application is for graphics device packages
that do not natively support some of the new graphics engine
features, like affine transformations, to add support for some
features by
working with grob coordinates. For example, a transformed
circle could be produce by calculating the coordinates
of the original circle, transforming the coordinates, and drawing the
transformed coordinates as a polygon.
</p>
<h2>
<a name="requirements">7. Technical requirements</a>
Expand Down Expand Up @@ -921,11 +921,11 @@ grid.polyclip(gTree(children=gList(rectGrob(width=.5, height=.5),
<h2>How to cite this report</h2>
<p>
Murrell, P. (2022). "Constructive Geometry for Complex Grobs"
Technical Report 2022-??, Department of Statistics, The University of Auckland.
Technical Report 2022-02, Department of Statistics, The University of Auckland.
Version 1.
[ <a href="how-to-cite.bib">bib</a> |
<a href="http://dx.doi.org/">DOI</a> |
<a href="https://stattech.blogs.auckland.ac.nz/">http</a> ]
<a href="http://dx.doi.org/10.17608/k6.auckland.19945814">DOI</a> |
<a href="https://stattech.blogs.auckland.ac.nz/2022/06/01/2022-02-constructive-geometry-for-complex-grobs">http</a> ]
</p>
<h2>
<a name="references">9. References</a>
Expand Down Expand Up @@ -958,10 +958,10 @@ Johnson, A. and Baddeley, A. (2019).


<dt>
[<a name="pkg:gridGeometry">Murrell, 2022</a>]
[<a name="pkg:gridGeometry">Murrell, 2022a</a>]
</dt>
<dd>
Murrell, P. (2022).
Murrell, P. (2022a).
<em>gridGeometry: Polygon Geometry in 'grid'</em>.
https://github.com/pmur002/gridgeometry,
https://stattech.wordpress.fos.auckland.ac.nz/2019/03/04/2019-01-a-geometry-engine-interface-for-grid/.
Expand All @@ -970,6 +970,22 @@ Murrell, P. (2022).
</dd>


<dt>
[<a name="murrell-vecpat-2022">Murrell, 2022b</a>]
</dt>
<dd>
Murrell, P. (2022b).
Vectorised pattern fills in r graphics.
Technical Report 2022-01, Department of Statistics, The University of
Auckland.
version 1.
[ <a href="coords-bib_bib.html#murrell-vecpat-2022">bib</a> |
<a href="http://dx.doi.org/10.17608/k6.auckland.19945787">DOI</a> |
<a href="https://stattech.blogs.auckland.ac.nz/2022/06/01/2022-01">http</a> ]

</dd>


<dt>
[<a name="pkg:rsvg">Ooms, 2022</a>]
</dt>
Expand Down
13 changes: 13 additions & 0 deletions coords-bib_bib.html
Expand Up @@ -72,6 +72,19 @@ <h1>coords.bib</h1><a name="R"></a><pre>
}
</pre>

<a name="murrell-vecpat-2022"></a><pre>
@techreport{<a href="coords-bib.html#murrell-vecpat-2022">murrell-vecpat-2022</a>,
title = {Vectorised Pattern Fills in R Graphics},
author = {Paul Murrell},
year = {2022},
note = {version 1},
institution = {Department of Statistics, The University of Auckland},
number = {2022-01},
url = {https://stattech.blogs.auckland.ac.nz/2022/06/01/2022-01},
doi = {<a href="http://dx.doi.org/10.17608/k6.auckland.19945787">http://dx.doi.org/10.17608/k6.auckland.19945787</a>}
}
</pre>

<hr><p><em>This file was generated by
<a href="http://www.lri.fr/~filliatr/bibtex2html/">bibtex2html</a> 1.99.</em></p>
</body>
Expand Down

0 comments on commit da0b35e

Please sign in to comment.