![]() |
Points, frames, curves and grids | ![]() |
This page describes the classes of Graphics/Types/. Their use by the typesetter of graphics (the frame edit_env_rep::fr, the grids gr-grid and gr-edit-grid, the typeset_* routines for curves) is explained in the graphics editor: typesetting, and is not repeated here.
A point is an array<double> (
Graphics/Types/point.hpp
). Points usually have two coordinates, three for the three dimensional objects; the empty array serves as an invalid point, which is what as_point returns for a tree that is neither a point nor a tuple.
Graphics/Types/math_util.hpp
defines the constants tm_infinity (the largest float), tm_PI and tm_E, and helpers square, norm (double), nearest, sign, fnull (x, eps) and an integer power pow (double, int).
A frame (
Graphics/Types/frame.hpp
) is an invertible map from local coordinates to the coordinates of a parent system. f (p) applies the direct map and f [p] the inverse one; both are also defined on rectangles (enclose transforms the four edges, sampled at 20 points each unless the frame is linear, and returns the bounding box) and on curves (f (c) is a transformed curve, see below). Besides direct_transform and inverse_transform, a frame_rep implements
The derivative at p applied to the vector v, used to compute tangents of transformed curves.
A \(\delta\) such that points within \(\delta\) of p are mapped within eps of the image of p; used to choose the precision with which a curve must be rectified before it is transformed.
The length of the image of a horizontal vector of length \(x\). The typesetter uses inverse_scalar to convert pixel sizes and pen widths into graphical units (
Typeset/Concat/concat_graphics.cpp
,
Edit/Interface/edit_graphics.cpp
). The header itself notes that this is “error-prone”: it is only meaningful for conformal maps.
A flag which is set when the frame maps segments to segments (this includes the affine frames). Only for such frames can a transformed curve be rectified, and enclose uses the corners alone.
A description for debugging, such as (tuple "scale" …).
Translation.
The map \(p \mapsto \operatorname{shift}+ m p\), with a scalar or a point (one factor per axis) as \(m\). This is the frame of every picture: update_frame builds it from gr-frame.
Rotation (angle in radians) and horizontal slanting; the latter is used by the poor man's italic fonts (
Graphics/Fonts/poor_italic.cpp
).
A linear map given by a \(2 \times 2\) matrix, inverted once at construction. The transformations of the form (tuple "linear" a b c d) given to gr-transform (get_transformation in
concat_graphics.cpp
) and the glyph transformations of
Graphics/Bitmap_fonts/glyph_transforms.cpp
produce such frames.
An affine map given by a \(3 \times 3\) matrix in homogeneous coordinates. Only the direct map is implemented.
A vertical bending \((x, y) \mapsto (x, y +\operatorname{fun}(x))\), optionally conjugated by a rectangle. It is not linear and has no Jacobian; nothing uses it.
Composition (apply f2 first) and inversion; both are lazy wrappers.
A curve (
Graphics/Types/curve.hpp
) is a map from \([0, 1]\) to points: c (t) evaluates it. The virtual methods of curve_rep are
The number of pieces, used to choose step sizes and to parameterize concatenations.
Appends to a a polyline approximating the curve within eps (without the starting point); rectify (eps) returns the full polyline. This is how curves are drawn: curve_box rectifies its curve with a precision of a quarter of PIXEL (
Typeset/Boxes/Graphics/graphics_boxes.cpp
).
A parameter distance within which the curve moves by less than eps. The default implementation divides eps by the norm of the gradient and halves the result until the neighbouring points are close enough.
The derivative.
A bound on the curvature between two parameters (several implementations return tm_infinity).
The parameters, points and source paths of the control points. The paths connect the curve to the point trees of the document and are what allows the graphics editor to select and drag control points.
Local minima of the distance to p, found by walking along the curve with steps given by bound, and sorted by distance.
A segment and a polyline; the polyline has \(N (a) - 1\) components with equal parameter intervals.
A quadratic B-spline. With interpol (the default) the control points are first computed by solving a tridiagonal (or, for closed splines, cyclic tridiagonal) system so that the curve passes through the given points; the solvers are in
Graphics/Types/equations.cpp
(tridiag_solve, xtridiag_solve, quasitridiag_solve). The spline and cspline tags produce such curves.
A cubic Bezier curve given by exactly four points, and a sequence of them. In simple mode (the smooth and csmooth tags), the intermediate control points are computed from the given points; otherwise (bezier, cbezier) every third point is on the curve and the others are control points.
The circular arc through three points (a full circle if close); degenerate input gives a single point.
Concatenation (continuity at the junctions is not checked).
Reversed parameterization, a portion of a curve, and the initial part of a curve covering a given portion of its length. part is used to cut curves at the white zones around arrow heads and dots (adjust_extremities in
concat_graphics.cpp
).
The image of a curve by a frame. Its rectify_cumul rectifies the original curve with precision f->direct_bound (c(0), eps) and maps the points; this only works for linear frames.
The same curve with other control points; used for calligraphic strokes, whose shape is computed but whose control points are those of the source markup.
closest (c, p) refines find_closest_point up to ten times and returns the closest point on the curve; the graphics editor uses it to snap to curves (
Edit/Interface/edit_graphics.cpp
,
Typeset/Boxes/Modifier/change_boxes.cpp
). intersection (f, g, p0, eps) looks for an intersection of two (two dimensional) curves near p0: it starts from the closest points of both curves to p0 and runs a Newton iteration on the parameters, stopping when the distance no longer decreases by at least ten percent. For f == g it looks for a self intersection between the two closest points. The editor uses it to snap to the intersections of the curves found near the mouse (snap_to_guide).
Graphics/Types/curve_extras.cpp
contains routines on arrays of points, all used by the calligraphy tag (typeset_calligraphy in
concat_graphics.cpp
): refine and smoothen (subdivision and moving average), bezier_fit (a piecewise cubic approximation within a tolerance), rectify_bezier, oval_profile (the outline of an elliptic pen) and calligraphy (the outline swept by such a pen along a polyline), and simplify_polyline (removal of points within a tolerance). Two least squares fitting methods, std_bezier_fit and alt_bezier_fit, are present but unused.
A grid (
Graphics/Types/grid.hpp
) produces the curves to be drawn within given limits (get_curves), the curves near a point (get_curves_around) and the closest grid point (find_closest_point, find_point_around). The concrete grids are empty_grid, cartesian, polar and logarithmic; as_grid and as_tree convert from and to the tuples stored in gr-grid. Their role in drawing and snapping is described in the graphics editor: typesetting.
The Jacobian of the inverse of a slanting uses +slant instead of -slant (
Graphics/Types/frame.cpp:172
), so tangents of curves mapped by an inverted slanting are wrong.
The bounds of shift_2D, rotation_2D, linear_2D and affine_2D return eps unchanged. This is right for isometries, but for a linear_2D or affine_2D map which enlarges distances, a transformed curve is rectified too coarsely by the factor of enlargement. The bound of scaling with a negative factor is negative.
Several operations abort with "not yet implemented": the inverse of an affine_2D frame and the Jacobians of bend_frame, of the inverse of an affine frame and of the inverse of a composed frame (frame.cpp:227-235, 259-265, 302-304), and the rectification of a curve transformed by a non linear frame and the curvature of any transformed curve (curve.cpp:1165, 1180).
The Jacobian of affine_2D multiplies the \(3 \times 3\) matrix with a two dimensional vector, which fails the dimension check of the matrix product (frame.cpp:216, 231). No code calls affine_2D at present.
bezier (a) reads four points without checking that a has them (curve.cpp:691-696).
A closed spline appends two points to the array it was given, which is shared with the caller (
curve.cpp:392
).
arg (p) divides by the norm and is undefined for the zero vector; pow (double, int) returns 1 for negative exponents.