GNU TeXmacsUser manualReferenceAboutEnglish
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.

1.Points and axes

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.

Arithmetic.
The operators +, -, * and / between points work componentwise on the common length of their operands: adding a two dimensional and a three dimensional point silently gives a two dimensional result, and any operation with an invalid point gives an invalid point. Scalar multiplication and division, abs, min and max (the last two assert a non empty point) are also provided. Equality == compares with a tolerance of \(10^{- 6}\).
Geometry.
inner, norm, arg (the angle in \([0, 2 \pi)\)), rotate_2D (p, o, angle), slanted (p, slant), collinear, linearly_dependent (three points), orthogonalize (an orthonormal basis of the plane through three points, which works in any dimension) and inside_rectangle. An axis is a pair of points describing a line; proj, dist, seg_dist (distance to the segment), midperp (perpendicular bisector of the first two points, in the plane of the three points) and intersection (axis, axis) operate on them. Degenerate cases return invalid points rather than failing.
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).

2.Frames

2.1.The abstract interface

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

jacobian (p, v, error), jacobian_of_inverse

The derivative at p applied to the vector v, used to compute tangents of transformed curves.

direct_bound (p, eps), inverse_bound

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.

direct_scalar (x), inverse_scalar

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.

linear

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.

operator tree

A description for debugging, such as (tuple "scale" …).

2.2.Concrete frames

shift_2D (d)

Translation.

scaling (m, shift)

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_2D (center, angle), slanting (center, slant)

Rotation (angle in radians) and horizontal slanting; the latter is used by the poor man's italic fonts (

Graphics/Fonts/poor_italic.cpp

).

linear_2D (m)

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.

affine_2D (m)

An affine map given by a \(3 \times 3\) matrix in homogeneous coordinates. Only the direct map is implemented.

bend_frame (fun, …)

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.

f1 * f2, invert (f)

Composition (apply f2 first) and inversion; both are lazy wrappers.

3.Curves

3.1.The abstract interface

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

nr_components ()

The number of pieces, used to choose step sizes and to parameterize concatenations.

rectify_cumul (a, eps)

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

).

bound (t, eps)

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.

grad (t, error)

The derivative.

curvature (t1, t2)

A bound on the curvature between two parameters (several implementations return tm_infinity).

get_control_points (abs, pts, cip)

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.

find_closest_points (t1, t2, p, eps), find_closest_point

Local minima of the distance to p, found by walking along the curve with steps given by bound, and sorted by distance.

3.2.Concrete curves

segment (p1, p2), poly_segment (a, cip)

A segment and a polyline; the polyline has \(N (a) - 1\) components with equal parameter intervals.

spline (a, cip, close, interpol)

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.

bezier (a), poly_bezier (a, cip, simple, closed)

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.

arc (a, cip, close)

The circular arc through three points (a full circle if close); degenerate input gives a single point.

compound (cs)

Concatenation (continuity at the junctions is not checked).

invert (c), part (c, t0, t1), truncate (c, portion, eps)

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

).

f (c)

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.

recontrol (c, a, cip)

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.

3.3.Closest points and intersections

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).

3.4.Polyline helpers

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.

4.Grids

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.

5.Pitfalls

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with no Invariant Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".