MeshGradientPatch Class
A patch of a MeshGradientBrush: a surface bounded by four cubic Bézier curves, with a color at each of its four corners, mixed across the surface. It is a Coons patch (MeshGradientPatch.CreateCoons, PDF shading type 6, the patches of SVG 2's meshgradient) or a tensor-product patch (MeshGradientPatch.CreateTensorProduct, PDF shading type 7).
public sealed class MeshGradientPatchRemarks
Control points. A patch is stored as the 16 control points of a bicubic tensor-product surface, row by row: P[r, c] is MeshGradientPatch.ControlPoints[4 r + c]. The position of the parameters (u, v), from 0 to 1, is S(u, v) = sum B_r(v) B_c(u) P[r, c], with the Bernstein polynomials B_0(t) = (1 - t)^3, B_1(t) = 3 t (1 - t)^2, B_2(t) = 3 t^2 (1 - t) and B_3(t) = t^3: u goes along the rows (from the "left" side to the "right" one) and v along the columns (from the "top" side to the "bottom" one). The four sides are the Bézier curves of the outer control points; the four inner ones shape the inside.
Colors. The color of (u, v) is the bilinear mix of the corner colors: (1 - u)(1 - v) of the top-left one, u (1 - v) of the top-right one, u v of the bottom-right one and (1 - u) v of the bottom-left one, as PDF interpolates them in the parameter space.
Properties
| Name | Description |
|---|---|
| ControlPoints | Gets the 16 control points of the tensor-product surface, row by row from the top-left corner. |
| CornerColors | Gets the colors of the corners, with straight alpha: top-left (P[0, 0]), top-right (P[0, 3]), bottom-right (P[3, 3]) and bottom-left (P[3, 0]). |
ControlPoints
MeshGradientPatch.csGets the 16 control points of the tensor-product surface, row by row from the top-left corner.
public ReadOnlyMemory<PointD> ControlPoints { get; }Property value
CornerColors
MeshGradientPatch.csGets the colors of the corners, with straight alpha: top-left (P[0, 0]), top-right (P[0, 3]), bottom-right (P[3, 3]) and bottom-left (P[3, 0]).
public ReadOnlyMemory<Rgba64> CornerColors { get; }Property value
Methods
| Name | Description |
|---|---|
| CreateCoons(ReadOnlySpan<PointD>, ReadOnlySpan<Rgba64>) | Creates a Coons patch from the four Bézier curves of its boundary: the patch whose inside is shaped by its sides only, as PDF's shading type 6 and SVG 2's mesh gradients define it. |
| CreateTensorProduct(ReadOnlySpan<PointD>, ReadOnlySpan<Rgba64>) | Creates a tensor-product patch from its 16 control points, as PDF's shading type 7 defines it. |
| GetPoint(double, double) | Gets the position of the parameters (u, v) on the surface. |
CreateCoons(ReadOnlySpan<PointD>, ReadOnlySpan<Rgba64>)
MeshGradientPatch.csCreates a Coons patch from the four Bézier curves of its boundary: the patch whose inside is shaped by its sides only, as PDF's shading type 6 and SVG 2's mesh gradients define it.
public static MeshGradientPatch CreateCoons(ReadOnlySpan<PointD> boundary, ReadOnlySpan<Rgba64> cornerColors)Parameters
boundaryReadOnlySpan<PointD>- The 12 points of the boundary, in canvas coordinates. They are copied.
cornerColorsReadOnlySpan<Rgba64>- The colors of the top-left, top-right, bottom-right and bottom-left corners (
boundary[0],[3],[6]and[9]), with straight alpha, or one color for every corner.
Returns
MeshGradientPatch The patch.
Exceptions
ArgumentException- There are not 12 points, the number of colors is neither one nor four, or a coordinate is not a finite number.
ArgumentOutOfRangeException- The magnitude of a coordinate exceeds 16777216.
Remarks
The 12 points go around the patch: the top side from left to right (boundary[0..3]), the right side from top to bottom (boundary[3..6]), the bottom side from right to left (boundary[6..9]) and the left side from bottom to top (boundary[9..11] and boundary[0]). Each side is a cubic Bézier curve: its two ends and, between them, its two control points; a straight side has its control points on the segment, at a third and two thirds of it. It is the order of the points of a patch in a PDF type 6 stream (p00 p01 p02 p03 p13 p23 p33 p32 p31 p30 p20 p10, with the corner colors c00 c03 c33 c30) and of an SVG meshpatch walked from its top-left corner. The inner control points of the equivalent tensor-product patch are computed with the formulas of the PDF specification (section 8.7.4.5.8).
CreateTensorProduct(ReadOnlySpan<PointD>, ReadOnlySpan<Rgba64>)
MeshGradientPatch.csCreates a tensor-product patch from its 16 control points, as PDF's shading type 7 defines it.
public static MeshGradientPatch CreateTensorProduct(ReadOnlySpan<PointD> controlPoints, ReadOnlySpan<Rgba64> cornerColors)Parameters
controlPointsReadOnlySpan<PointD>- The 16 control points, in canvas coordinates. They are copied.
cornerColorsReadOnlySpan<Rgba64>- The colors of the top-left, top-right, bottom-right and bottom-left corners (
P[0, 0],P[0, 3],P[3, 3]andP[3, 0]), with straight alpha, or one color for every corner.
Returns
MeshGradientPatch The patch.
Exceptions
ArgumentException- There are not 16 points, the number of colors is neither one nor four, or a coordinate is not a finite number.
ArgumentOutOfRangeException- The magnitude of a coordinate exceeds 16777216.
Remarks
The points are given row by row: controlPoints[4 r + c] is P[r, c], the 12 outer ones forming the four sides and the four inner ones shaping the inside. A PDF type 7 stream gives the points of a patch in the order p00 p01 p02 p03 p13 p23 p33 p32 p31 p30 p20 p10 p11 p12 p22 p21, where pij is P[i, j].
GetPoint(double, double)
MeshGradientPatch.csGets the position of the parameters (u, v) on the surface.
Parameters
udouble- The parameter along the rows, from 0 (left side) to 1 (right side).
vdouble- The parameter along the columns, from 0 (top side) to 1 (bottom side).
Returns
PointD The position, in canvas coordinates (before MeshGradientBrush.Transform).