DIVISION BY ZERO in grid units: - There are two main conversion scenarios in grid: + converting a unit to a final location/dimension for drawing (or for determining the boundary of a drawn object) - The grid graphics package converts all incoming units to INCHES (then uses R graphics engine to convert to device coordinates) - Almost all conversions to INCHES involve multiplication only - The exception is "native" units, which require a division by the range of the native scale. This creates the possibility of division by zero if the range of the native scale is zero (i.e., the scale limits are identical). SOLUTION: make it an error to set a scale with identical limits. + converting from one unit to another (within a viewport context) - Conversions, via convertUnit(), involve two steps: conversion from the original unit TO inches and then conversion FROM inches to the final unit. - Any division-by-zero in the conversion TO inches is avoided by the solution above. - Division-by-zero in the conversion FROM inches can occur IF the viewport has zero physical width or height AND the final unit is relative ("npc" or "native"). SOLUTION: (i) IF original unit is also relative ... (a) IF original unit is plain unit AND we are NOT converting 'x' to 'y' (or vice versa) catch this as special case and make it work. (b) OTHERWISE (original unit is complex or we are converting 'x' to 'y' or vice versa) return zero. (ii) IF original unit is absolute, throw an error (because the conversion does not make sense) UNLESS the original unit value is zero, in which case return zero. - NOTE that conversion FROM anything TO an absolute final unit does not risk division-by-zero, even when viewport has zero physical width or height. (The result is either zero, if the original unit is relative, or an identity operation [in terms of the physical result] if the original unit is absolute.)