package vg
Install
Dune Dependency
Authors
Maintainers
Sources
sha512=ccd0d0f61cdbdb3420b5f4d747fe6e6b95e487738f70163a6e26396b1eeb9a42118306bc9c2c9afc9256171d57f81fbdf08ec558625eb5d723230aa0e9564fb6
doc/semantics.html
The semantics of Vg
The following notations and definitions give precise meaning to images and their combinators.
Colors
The semantics of colors is the one ascribed to Gg.color
: colors are in a linearized sRGBA space.
Color stops
A value of type Gg.Color.stops
specifies a color at each point of the 1D unit space. It is defined by a list of pairs (t
i, c
i)
where t
i is a value from 0
to 1
and c
i the corresponding color at that value. Colors at points between t
i and t
i+1 are linearly interpolated between c
i and c
i+1. If t
i lies outside 0
to 1
or if t
i-1 >= t
i the semantics is undefined.
Given a stops value stops = [
(t
0, c
0);
(t
1,c
1);
... (t
n, c
n)
]
and any point t
of 1D space, the semantic function:
[] : Gg.Color.stops -> float -> Gg.color
maps them to a color value written [stops
]t as follows.
- [
stops
]t =(0, 0, 0, 0)
for anyt
ifstops = []
- [
stops
]t= c
0 ift < t
0. - [
stops
]t= c
n ift >= t
n. - [
stops
]t= (1-u)c
i+ uc
i+1 withu = (t - t
i)/(t
i+1-t
i)
ift
i<= t <
t
i+1
Images
Values of type Vg.image
represent maps from the infinite 2D euclidian space to colors. Given an image i
and a point pt
of the plane the semantic function
[]: image -> Gg.p2 -> Gg.color
maps them to a color value written [i
]pt
representing the image's color at this point.
Paths and areas
A value of type Vg.path
is a list of subpaths. A subpath is a list of directed and connected curved segments. Subpaths are disconnected from each other and may (self-)intersect.
A path and an area specification of type Vg.P.area
define a finite area of the 2D euclidian space. Given an area specification a
, a path p
and a point pt
, the semantic function:
[]: P.area -> path -> Gg.p2 -> bool
maps them to a boolean value written [a
, p
]pt
that indicates whether pt
belongs to the area or not.
The semantics of area rules is as follows:
- [
`Anz
,p
]pt
istrue
iff the winding number ofp
aroundpt
is non zero. To determine the winding number cast a ray frompt
to infinity in any direction (just make sure the ray doesn't intersectp
tangently or at a singularity). Starting with zero add one for each intersection with a counter-clockwise oriented segment ofp
and substract one for each clockwise ones. The resulting sum is the winding number. This is usually refered to as the non-zero winding rule and is the default forVg.I.cut
. - [
`Aeo
,p
]pt
istrue
iff the number of intersections ofp
with a ray cast frompt
to infinity in any direction is odd (just make sure the ray doesn't intersectp
tangently or at a singularity). This is usually refered to as the even-odd rule. - [
`O o
,p
]pt
istrue
iffpt
is in the outline area ofp
as defined by the valueo
of typeVg.P.outline
. See Outline areas, Segment jointures, Subpath caps, Outline dashes.
Outline areas
The outline area of a path specified by a value o
of type Vg.P.outline
is the union of its subpaths outline areas.
A subpath outline area is inside the parallel curves at a distance o.width / 2
of its path segments that are joined accoring to the join style o.join
(see below) and closed at the subpath end points with a cap style o.cap
(see below). The outline area of a subpath can also be chopped at regular intervals according to the o.dashes
parameter (see below).
Segment jointures
The shape of subpath segment jointures is specified in o.join
by a value of type Vg.P.join
. From left to right:
`Miter
, the outer parallel curves are extended until they meet unless the joining angle is smaller thano.miter_angle
in which case the join is converted to a bevel.`Round
, joins the outer parallel curves by a semicircle centered at the end point with a diameter equal too.width
.`Bevel
, joins the outer parallel curves by a segment.
Subpath caps
The shape of subpath (or dashes) end points is specified in o.cap
by a value of type Vg.P.cap
. From left to right:
`Butt
, end points are square and extend only to the exact end point of the path.`Round
, end points are rounded by a semicircle at the end point with a diameter equal too.width
.`Square
, end points are square and extend by a distance equal to halfo.width
.
Outline dashes
The path outline area can be chopped at regular intervals by specifying a value (off, pat)
of type Vg.P.dashes
in o.dashes
.
The dash pattern pat
is a list of lengths that specify the length of alternating dashes and gaps (starting with dashes). The dash offset off
is a positive offset that indicates where to start in the dash pattern at the beginning of a subpath.