11% \VignetteEncoding{UTF-8}
22% File src/library/grid/vignettes/locndimn.Rnw
33% Part of the R package, https://www.R-project.org
4- % Copyright 2001–2026 Paul Murrell and the R Core Team
4+ % Copyright 2001-13 Paul Murrell and the R Core Team
55% Distributed under GPL 2 or later
66
77\documentclass [a4paper ]{article }
88% \VignetteIndexEntry{Locations versus Dimensions}
99% \VignettePackage{grid}
10-
1110\setlength {\parindent }{0in}
1211\setlength {\parskip }{.1in}
1312\setlength {\textwidth }{140mm}
1716\newcommand {\pkg }[1]{{\normalfont\fontseries {b}\selectfont #1}}
1817\newcommand {\grid }{\pkg {grid}}
1918
20- \title {The Difference Between Locations and Dimensions in \grid {}}
19+ \title {The difference between Locations and Dimensions in \grid {}}
2120\author {Paul Murrell}
2221
2322\begin {document }
23+
2424\maketitle
2525
2626<<echo =FALSE , results =hide >>=
@@ -29,31 +29,31 @@ library(grid)
2929ps.options(pointsize = 12 )
3030options(width = 60 )
3131@
32-
33- \section* { Introduction }
34- The \grid {} package makes use of unit objects to express both the
35- locations and dimensions of graphical components. For example,
36- \code {grid.rect()} interprets its \code {x} and \code {y} arguments as
37- locations within the current viewport, while its \code {width} and
38- \code {height} arguments are treated as dimensions.
39-
40- These interpretations are usually implicit: if the argument is an
41- \code {x} or \code {y} value, it represents a location; if it is a
42- \code {width} or \code {height} value, it represents a dimension.
43-
44- The distinction matters because, in some coordinate systems —
45- notably \code {"native"} coordinates — a location value can have a
46- different meaning from a dimension value. This occurs whenever the
47- minimum value of the coordinate system is not zero.
48-
49- In simple unit specifications, the difference may not be noticeable.
50- However, there are two areas where the distinction is critical.
51-
52- \section* { 1. Arithmetic on Units }
53- When adding or performing arithmetic operations on units, it is
54- important to remember that locations behave like vectors, while
55- dimensions behave like lengths. The following diagram demonstrates
56- the difference:
32+ \grid {} makes use of unit objects to express both the locations and
33+ dimensions of graphical components. For example, the \code {grid.rect() }
34+ function treats its x- and y-arguments as locations within the current
35+ viewport, and its width- and height-arguments as dimensions within the
36+ current viewport.
37+
38+ These different interpretations of units are usually implicit like this;
39+ if its an x- or y-value then its a location, if its a width- or height-value
40+ then its a dimension.
41+
42+ The distinction is made at all because, in some coordinate systems, notably
43+ \code {"native"} coordinates, the location $ x $ can have a very different
44+ meaning
45+ from the dimension $ x $ -- basically, whenever the minimum value of the
46+ coordinate system is not zero.
47+
48+ In the specification of simple units, the difference between locations
49+ and dimensions is often not noticeable. However, there are a couple
50+ of tricky areas:
51+
52+ \begin { enumerate }
53+ \item When adding ( or performing any arithmetic operation on) units,
54+ it is important to keep in mind that locations are added like vectors
55+ and dimensions are added like lengths. The following
56+ diagram demonstrates the difference:
5757
5858<<fig =TRUE , echo =FALSE , results =hide >>=
5959diagram.locn <- function (i , n , locn ) {
@@ -96,28 +96,28 @@ diagram.dimn(8, n, unit(0.4, "native"))
9696diagram.dimn(9 , n , unit(1 , " native" ) + unit(- 0.4 , " native" ))
9797diagram.dimn(10 , n , unit(1 , " native" ) - unit(0.4 , " native" ))
9898@
99-
100- \section* { 2. Converting Units }
101- The functions \code {convertX}, \code {convertY}, \code {convertWidth},
102- and \code {convertHeight} are used to convert between coordinate
103- systems. It is essential to distinguish whether the conversion is for
104- a location or for a dimension.
105-
106- The following code demonstrates the difference :
99+ \item The functions \code {convertX},
100+ \code {convertY}, \code {convertWidth}, \code {convertHeight }
101+ are used to convert from one coordinate system to another.
102+ Again, it is important whether the conversion is for a location or
103+ for a dimension.
104+ The following code
105+ demonstrates some results from these functions based on a similar
106+ situation to that in the preceding diagram :
107107
108108<<fig =FALSE >>=
109109pushViewport(viewport(yscale = c(- 0.6 , 1.3 )))
110- # Location conversions
110+ # Unexpected results?
111111convertY(unit(1 ,' native' ), " native" )
112112convertY(unit(- .4 ,' native' ), " native" )
113113convertY(unit(1 ,' native' )+ unit(- .4 ,' native' ), " native" )
114114convertY(unit(1 ,' native' )- unit(.4 ,' native' ), " native" )
115- # Dimension conversions
115+ # Expected results
116116convertHeight(unit(1 ,' native' ), " native" )
117117convertHeight(unit(- .4 ,' native' ), " native" )
118118convertHeight(unit(1 ,' native' )+ unit(- .4 ,' native' ), " native" )
119119convertHeight(unit(1 ,' native' )- unit(.4 ,' native' ), " native" )
120120popViewport()
121121@
122-
123- \end {document }
122+ \end { enumerate }
123+ \end {document }
0 commit comments