Documentation
¶
Overview ¶
Package geom 是与具体绘制库无关的二维几何与渐变引擎,供 internal/render 及其各绘制后端(canvas/gg/ftgg/tinyskia)共用。
说明:本包的路径子系统(path.go、path_intersection.go、path_stroke.go、 path_util.go、path_simplify.go、path_tiling.go、path_scanner.go、shapes.go、 polyline.go、util.go)是从 MIT 许可的 github.com/tdewolff/canvas 路径引擎 移植而来,以保证布尔运算(And/Or)、描边展开(Stroke)、Settle 等结果与 canvas 逐点一致。为便于与上游对照,这些文件保留了上游英文注释;本仓库 新增或修改的代码(colors.go、paint.go 等)使用中文注释。
移植时只删除了依赖渲染分辨率(Resolution)的 ToVectorRasterizer / ToScanxScanner,以及两处紧跟 panic 的不可达 continue 和已废弃 FastClip 的旧实现,其余逻辑未改动。
Index ¶
- Constants
- Variables
- func Equal(a, b float64) bool
- func Interval(f, lower, upper float64) bool
- func IntervalExclusive(f, lower, upper float64) bool
- func SolveCubicFormula(a, b, c, d float64) (float64, float64, float64)
- func SolveQuadraticFormula(a, b, c float64) (float64, float64)
- type ArcsJoiner
- type BevelJoiner
- type ButtCapper
- type CSSColor
- type Capper
- type CoordinateFilter
- type FillRule
- type Grad
- type Gradient
- type GradientFunc
- type Intersection
- type Intersections
- type Joiner
- type LinearGradient
- type Matrix
- func (m Matrix) Decompose() (float64, float64, float64, float64, float64, float64)
- func (m Matrix) Det() float64
- func (m Matrix) Dot(p Point) Point
- func (m Matrix) Eigen() (float64, float64, Point, Point)
- func (m Matrix) Equals(q Matrix) bool
- func (m Matrix) HasRotation() bool
- func (m Matrix) HasScaling() bool
- func (m Matrix) HasTranslation() bool
- func (m Matrix) Inv() Matrix
- func (m Matrix) IsIdentity() bool
- func (m Matrix) IsRigid() bool
- func (m Matrix) IsRotation() bool
- func (m Matrix) IsScaling() bool
- func (m Matrix) IsSimilarity() bool
- func (m Matrix) IsTranslation() bool
- func (m Matrix) Mul(q Matrix) Matrix
- func (m Matrix) Pos() (float64, float64)
- func (m Matrix) ReflectX() Matrix
- func (m Matrix) ReflectXAbout(x float64) Matrix
- func (m Matrix) ReflectY() Matrix
- func (m Matrix) ReflectYAbout(y float64) Matrix
- func (m Matrix) Rotate(rot float64) Matrix
- func (m Matrix) RotateAbout(rot, x, y float64) Matrix
- func (m Matrix) Scale(sx, sy float64) Matrix
- func (m Matrix) ScaleAbout(sx, sy, x, y float64) Matrix
- func (m Matrix) Shear(sx, sy float64) Matrix
- func (m Matrix) ShearAbout(sx, sy, x, y float64) Matrix
- func (m Matrix) String() string
- func (m Matrix) T() Matrix
- func (m Matrix) ToSVG(h float64) string
- func (m Matrix) Translate(x, y float64) Matrix
- type MiterJoiner
- type Paint
- type Path
- func Arc(r, theta0, theta1 float64) *Path
- func BeveledRectangle(w, h, r float64) *Path
- func Circle(r float64) *Path
- func Ellipse(rx, ry float64) *Path
- func EllipticalArc(rx, ry, rot, theta0, theta1 float64) *Path
- func Grid(w, h float64, nx, ny int, r float64) *Path
- func Line(x, y float64) *Path
- func MustParseSVGPath(s string) *Path
- func NewPathFromData(d []float64) *Path
- func ParseSVGPath(s string) (*Path, error)
- func Rectangle(w, h float64) *Path
- func RegularPolygon(n int, r float64, up bool) *Path
- func RegularStarPolygon(n, d int, r float64, up bool) *Path
- func RoundedRectangle(w, h, r float64) *Path
- func StarPolygon(n int, R, r float64, up bool) *Path
- func Triangle(r float64) *Path
- func (p *Path) And(q *Path) *Path
- func (p *Path) Append(qs ...*Path) *Path
- func (p *Path) Arc(rx, ry, rot, theta0, theta1 float64)
- func (p *Path) ArcTo(rx, ry, rot float64, large, sweep bool, x, y float64)
- func (p *Path) Bounds() Rect
- func (p *Path) CCW() bool
- func (p *Path) Clip(x0, y0, x1, y1 float64) *Path
- func (p *Path) Close()
- func (p *Path) Closed() bool
- func (p *Path) Contains(q *Path) bool
- func (p *Path) ContainsPoint(x, y float64, fillRule FillRule) bool
- func (p *Path) CoordDirections() []Point
- func (p *Path) Coords() []Point
- func (p *Path) Copy() *Path
- func (p *Path) CopyTo(q *Path) *Path
- func (p *Path) CrossingsAt(x, y float64) (int, bool)
- func (p *Path) CubeTo(cpx1, cpy1, cpx2, cpy2, x, y float64)
- func (p *Path) Curvature(seg int, t float64) float64
- func (p *Path) Dash(offset float64, d ...float64) *Path
- func (p *Path) Data() []float64
- func (p *Path) Direction(seg int, t float64) Point
- func (p *Path) Div(q *Path) *Path
- func (p *Path) Empty() bool
- func (p *Path) Equals(q *Path) bool
- func (p *Path) FastBounds() Rect
- func (p *Path) FastClip(x0, y0, x1, y1 float64) *Path
- func (p *Path) Filling(fillRule FillRule) []bool
- func (p *Path) Flatten(tolerance float64) *Path
- func (p *Path) GobDecode(b []byte) error
- func (p *Path) GobEncode() ([]byte, error)
- func (p *Path) Gridsnap(spacing float64) *Path
- func (p *Path) HasSubpaths() bool
- func (p *Path) Intersections(q *Path) []Point
- func (p *Path) IsFlat() bool
- func (p *Path) Join(q *Path) *Path
- func (p *Path) Len() int
- func (p *Path) Length() float64
- func (p *Path) LineTo(x, y float64)
- func (p *Path) Markers(first, mid, last *Path, align bool) []*Path
- func (p *Path) MarshalBinary() ([]byte, error)
- func (p *Path) MoveTo(x, y float64)
- func (p *Path) Not(q *Path) *Path
- func (p *Path) Offset(w float64, tolerance float64) *Path
- func (p *Path) Or(q *Path) *Path
- func (p *Path) Overlaps(q *Path) bool
- func (p *Path) PointClosed() bool
- func (p *Path) Pos() Point
- func (p *Path) QuadTo(cpx, cpy, x, y float64)
- func (p *Path) RayIntersections(x, y float64) []Intersection
- func (p *Path) Relate(q *Path) (Relation, []Point)
- func (p *Path) ReplaceArcs() *Path
- func (p *Path) Reset()
- func (p *Path) Reverse() *Path
- func (p *Path) ReverseScanner() *PathReverseScanner
- func (p *Path) Rotate(deg float64) *Path
- func (p *Path) Same(q *Path) bool
- func (p *Path) Sane() bool
- func (p *Path) Scale(sx, sy float64) *Path
- func (p *Path) Scanner() *PathScanner
- func (p *Path) Segments() []Segment
- func (p *Path) Settle(fillRule FillRule) *Path
- func (p *Path) SimplifyVisvalingamWhyatt(tolerance float64) *Path
- func (p *Path) Split() []*Path
- func (p *Path) SplitAt(ts ...float64) []*Path
- func (p *Path) StartPos() Point
- func (p *Path) String() string
- func (p *Path) Stroke(w float64, cr Capper, jr Joiner, tolerance float64) *Path
- func (p *Path) Tile(clip *Path, cell Matrix) *Path
- func (p *Path) ToPDF() string
- func (p *Path) ToPS() string
- func (p *Path) ToSVG() string
- func (p *Path) Touches(q *Path) bool
- func (p *Path) Transform(m Matrix) *Path
- func (p *Path) TransformFunc(f func(float64, float64) (float64, float64)) *Path
- func (p *Path) Translate(x, y float64) *Path
- func (p *Path) Triangulate() ([][3]Point, [][5]Point)
- func (p *Path) UnmarshalBinary(b []byte) error
- func (p *Path) WindingsAt(x, y float64) (int, bool)
- func (p *Path) XMonotone() *Path
- func (p *Path) Xor(q *Path) *Path
- type PathReverseScanner
- func (s *PathReverseScanner) Arc() (float64, float64, float64, bool, bool)
- func (s *PathReverseScanner) CP1() Point
- func (s *PathReverseScanner) CP2() Point
- func (s *PathReverseScanner) Cmd() float64
- func (s *PathReverseScanner) End() Point
- func (s *PathReverseScanner) Path() *Path
- func (s *PathReverseScanner) Scan() bool
- func (s *PathReverseScanner) Start() Point
- func (s *PathReverseScanner) Values() []float64
- type PathScanner
- func (s *PathScanner) Arc() (float64, float64, float64, bool, bool)
- func (s *PathScanner) CP1() Point
- func (s *PathScanner) CP2() Point
- func (s *PathScanner) Cmd() float64
- func (s *PathScanner) End() Point
- func (s *PathScanner) Path() *Path
- func (s *PathScanner) Scan() bool
- func (s *PathScanner) Start() Point
- func (s *PathScanner) Values() []float64
- type Paths
- type Point
- func (p Point) Add(q Point) Point
- func (p Point) Angle() float64
- func (p Point) AngleBetween(q Point) float64
- func (p Point) Div(f float64) Point
- func (p Point) Dot(q Point) float64
- func (p Point) Equals(q Point) bool
- func (p Point) Gridsnap(spacing float64) Point
- func (p Point) Hadamard(q Point) Point
- func (p Point) Interpolate(q Point, t float64) Point
- func (p Point) InterpolateX(q Point, x float64) Point
- func (p Point) InterpolateY(q Point, y float64) Point
- func (p Point) IsZero() bool
- func (p Point) Length() float64
- func (p Point) Mul(f float64) Point
- func (p Point) Neg() Point
- func (p Point) Norm(length float64) Point
- func (p Point) PerpDot(q Point) float64
- func (p Point) Rot(phi float64, p0 Point) Point
- func (p Point) Rot90CCW() Point
- func (p Point) Rot90CW() Point
- func (p Point) Slope() float64
- func (p Point) String() string
- func (p Point) Sub(q Point) Point
- func (p Point) Transform(m Matrix) Point
- type Polyline
- func (p *Polyline) Add(x, y float64) *Polyline
- func (p *Polyline) Area() float64
- func (p *Polyline) Centroid() Point
- func (p *Polyline) Close() *Polyline
- func (p *Polyline) Closed() bool
- func (p *Polyline) Coords() []Point
- func (p *Polyline) Empty() bool
- func (p *Polyline) FillCount(x, y float64) int
- func (p *Polyline) Interior(x, y float64, fillRule FillRule) bool
- func (p *Polyline) Len() int
- func (p *Polyline) Smoothen() *Path
- func (p *Polyline) ToPath() *Path
- type RadialGradient
- type Rect
- func (r Rect) Add(q Rect) Rect
- func (r Rect) AddPoint(p Point) Rect
- func (r Rect) And(q Rect) Rect
- func (r Rect) Area() float64
- func (r Rect) Center() Point
- func (r Rect) ClosestPoint(p Point) Point
- func (r Rect) Contains(q Rect) bool
- func (r Rect) ContainsLine(a, b Point) bool
- func (r Rect) ContainsPoint(p Point) bool
- func (r Rect) DistanceToPoint(p Point) float64
- func (r Rect) Empty() bool
- func (r Rect) Equals(q Rect) bool
- func (r Rect) Expand(d float64) Rect
- func (r Rect) H() float64
- func (r Rect) Overlaps(q Rect) bool
- func (r Rect) OverlapsLine(a, b Point) bool
- func (r Rect) String() string
- func (r Rect) ToPath() *Path
- func (r Rect) Touches(q Rect) bool
- func (r Rect) TouchesLine(a, b Point) bool
- func (r Rect) TouchesPoint(p Point) bool
- func (r Rect) Transform(m Matrix) Rect
- func (r Rect) Translate(x, y float64) Rect
- func (r Rect) W() float64
- func (r Rect) Zero() bool
- type Relation
- func (rel Relation) Contains() bool
- func (rel Relation) CoveredBy() bool
- func (rel Relation) Covers() bool
- func (rel Relation) Disjoint() bool
- func (rel Relation) Equals() bool
- func (rel Relation) Intersects() bool
- func (rel Relation) Overlaps() bool
- func (rel Relation) String() string
- func (rel Relation) Touches() bool
- func (rel Relation) Within() bool
- type Resolution
- type RoundCapper
- type RoundJoiner
- type Segment
- type SquareCapper
- type Stop
- type SweepEvents
- func (q *SweepEvents) AddPathEndpoints(p *Path, seg int, clipping bool) int
- func (q SweepEvents) Init()
- func (q SweepEvents) Less(i, j int) bool
- func (q *SweepEvents) Pop() *SweepPoint
- func (q SweepEvents) Print(w io.Writer)
- func (q *SweepEvents) Push(item *SweepPoint)
- func (q SweepEvents) String() string
- func (q SweepEvents) Swap(i, j int)
- func (q *SweepEvents) Top() *SweepPoint
- type SweepNode
- type SweepPoint
- func (a *SweepPoint) CompareH(b *SweepPoint) int
- func (a *SweepPoint) CompareV(b *SweepPoint) int
- func (s *SweepPoint) InResult(op pathOp, fillRule FillRule) uint8
- func (s *SweepPoint) InterpolateY(x float64) float64
- func (a *SweepPoint) LessH(b *SweepPoint) bool
- func (s *SweepPoint) Reverse()
- func (s *SweepPoint) SplitAt(z Point) (*SweepPoint, *SweepPoint)
- func (s *SweepPoint) String() string
- func (s *SweepPoint) ToleranceEdgeY(xLeft, xRight float64) (float64, float64)
- type SweepStatus
- type VisvalingamWhyatt
Constants ¶
const ( MoveToCmd = 1.0 LineToCmd = 2.0 QuadToCmd = 4.0 CubeToCmd = 8.0 ArcToCmd = 16.0 CloseCmd = 32.0 )
Command values as powers of 2 so that the float64 representation is exact TODO: make CloseCmd a LineTo + CloseCmd, where CloseCmd is only a command value, no coordinates TODO: optimize command memory layout in paths: we need three bits to represent each command, thus 6 to specify command going forward and going backward. The remaining 58 bits, or 28 per direction, should specify the index into Path.d of the end of the sequence of coordinates. MoveTo should have an index to the end of the subpath. Use math.Float64bits. For long flat paths this will reduce memory usage in half since besides all coordinates, the only overhead is: 64 bits first MoveTo, 64 bits end of MoveTo and start of LineTo, 64 bits end of LineTo and start of Close, 64 bits end of Close.
const DefaultResolution = Resolution(96.0 / mmPerInch)
DefaultResolution 是默认分辨率,等于 96 DPI。
Variables ¶
var ( Transparent = color.RGBA{0x00, 0x00, 0x00, 0x00} Black = color.RGBA{0x00, 0x00, 0x00, 0xff} White = color.RGBA{0xff, 0xff, 0xff, 0xff} )
常用颜色(与 canvas 的 Transparent/Black/White 一致)。
var BentleyOttmannEpsilon = 1e-8
BentleyOttmannEpsilon is the snap rounding grid used by the Bentley-Ottmann algorithm. This prevents numerical issues. It must be larger than Epsilon since we use that to calculate intersections between segments. It is the number of binary digits to keep.
var DebugPathIntersection = false
DebugPathIntersection enables debugging mode for path intersection edge-cases. Please send us the test cases generated as temporary files.
var Epsilon = 1e-10
Epsilon is the smallest number below which we assume the value to be zero. This is to avoid numerical floating point issues.
var FastStroke = false
FastStroke skips "settling" the resulting paths for Path.Offset and Path.Stroke, which ensures a well-formed path without overlapping nor holes. This fixes overlapping strokes or the inner-bend for corners. Inner-bends are currently already fixed for two line segments, but will otherwise leave a hole. Overlapping strokes may not be a problem when using the NonZero winding order for drawing. Strokes that are significantly larger than the path itself may be problematic with this enabled, but it may provide a stark performance gain for most (trivial) cases.
var Identity = Matrix{
{1.0, 0.0, 0.0},
{0.0, 1.0, 0.0},
}
Identity is the identity affine transformation matrix, i.e. transforms any point to itself.
var Origin = Point{0.0, 0.0}
Origin is the coordinate system's origin.
var PixelTolerance = 0.1
PixelTolerance is the maximum deviation of the rasterized path from the original for flattening purposed in pixels.
var Precision = 8
Precision is the number of significant digits at which floating point value will be printed to output formats.
var Tolerance = 0.01
Tolerance is the maximum deviation from the original path in millimeters when e.g. flatting. Used for flattening in the renderers, font decorations, and path intersections.
Functions ¶
func Equal ¶
Equal returns true if a and b are equal within an absolute tolerance of Epsilon or within a relative tolerance of Epsilon (relative to the largest of the two).
func Interval ¶
Interval returns true if f is in closed interval [lower-Epsilon,upper+Epsilon] where lower and upper can be interchanged.
func IntervalExclusive ¶
IntervalExclusive returns true if f is in open interval [lower+Epsilon,upper-Epsilon] where lower and upper can be interchanged.
func SolveQuadraticFormula ¶
Types ¶
type ArcsJoiner ¶
ArcsJoiner is an arcs joiner.
func (ArcsJoiner) Join ¶
func (j ArcsJoiner) Join(rhs, lhs *Path, halfWidth float64, pivot, n0, n1 Point, r0, r1 float64)
Join adds a join to a right-hand-side and left-hand-side path, of width 2*halfWidth, around a pivot point with starting and ending normals of n0 and n1, and radius of curvatures of the previous and next segments, which are positive for CCW arcs.
func (ArcsJoiner) String ¶
func (j ArcsJoiner) String() string
type BevelJoiner ¶
type BevelJoiner struct{}
BevelJoiner is a bevel joiner.
func (BevelJoiner) Join ¶
func (BevelJoiner) Join(rhs, lhs *Path, halfWidth float64, pivot, n0, n1 Point, r0, r1 float64)
Join adds a join to a right-hand-side and left-hand-side path, of width 2*halfWidth, around a pivot point with starting and ending normals of n0 and n1, and radius of curvatures of the previous and next segments.
func (BevelJoiner) String ¶
func (BevelJoiner) String() string
type ButtCapper ¶
type ButtCapper struct{}
ButtCapper is a butt capper.
func (ButtCapper) Cap ¶
func (ButtCapper) Cap(p *Path, halfWidth float64, pivot, n0 Point)
Cap adds a cap to path p of width 2*halfWidth, at a pivot point and initial normal direction of n0.
func (ButtCapper) String ¶
func (ButtCapper) String() string
type CSSColor ¶
CSSColor is a string formatter to convert a color.RGBA to a CSS color (hexadecimal or using rgba()).
type Capper ¶
Capper implements Cap, with rhs the path to append to, halfWidth the half width of the stroke, pivot the pivot point around which to construct a cap, and n0 the normal at the start of the path. The length of n0 is equal to the halfWidth.
var ButtCap Capper = ButtCapper{}
ButtCap caps the start or end of a path by a butt cap.
var RoundCap Capper = RoundCapper{}
RoundCap caps the start or end of a path by a round cap.
var SquareCap Capper = SquareCapper{}
SquareCap caps the start or end of a path by a square cap.
type CoordinateFilter ¶
type FillRule ¶
type FillRule int
FillRule is the algorithm to specify which area is to be filled and which not, in particular when multiple subpaths overlap. The NonZero rule is the default and will fill any point that is being enclosed by an unequal number of paths winding clock-wise and counter clock-wise, otherwise it will not be filled. The EvenOdd rule will fill any point that is being enclosed by an uneven number of paths, whichever their direction. Positive fills only counter clock-wise oriented paths, while Negative fills only clock-wise oriented paths.
type Grad ¶
type Grad []Stop
Grad 是按 offset 升序排列的渐变色标集合。
func (Grad) ToLinear ¶
func (g Grad) ToLinear(start, end Point) *LinearGradient
ToLinear 把色标集合绑定到线性渐变。
type Gradient ¶
Gradient 是与具体绘制库无关的渐变采样接口:返回 (x,y) 处的颜色。 canvas 后端把它包装成 canvas.Gradient;gg 等后端直接用采样画笔消费。
type GradientFunc ¶
GradientFunc 让普通函数实现 Gradient。
type Intersection ¶
type Intersection struct {
Point // coordinate of intersection
T [2]float64 // position along segment [0,1]
Dir [2]float64 // direction at intersection [0,2*pi)
Tangent bool // intersection is tangent (touches) instead of secant (crosses)
Same bool // intersection is of two overlapping segments (tangent is also true)
}
Intersection is an intersection between two path segments, e.g. Line x Line. Note that an intersection is tangent also when it is at one of the endpoints, in which case it may be tangent for this segment but may or may not cross the path depending on the adjacent segment. Notabene: for quad/cube/ellipse aligned angles at the endpoint for non-overlapping curves are deviated slightly to correctly calculate the value for Into, and will thus not be aligned
func (Intersection) Equals ¶
func (z Intersection) Equals(o Intersection) bool
func (Intersection) Into ¶
func (z Intersection) Into() bool
Into returns true if first path goes into the left-hand side of the second path, i.e. the second path goes to the right-hand side of the first path.
func (Intersection) String ¶
func (z Intersection) String() string
type Intersections ¶
type Intersections []Intersection
func (Intersections) Has ¶
func (zs Intersections) Has() bool
Has returns true if there are secant/tangent intersections.
func (Intersections) HasSecant ¶
func (zs Intersections) HasSecant() bool
HasSecant returns true when there are secant intersections, i.e. the curves intersect and cross (they cut).
func (Intersections) HasTangent ¶
func (zs Intersections) HasTangent() bool
HasTangent returns true when there are tangent intersections, i.e. the curves intersect but don't cross (they touch).
type Joiner ¶
Joiner implements Join, with rhs the right path and lhs the left path to append to, pivot the intersection of both path elements, n0 and n1 the normals at the start and end of the path respectively. The length of n0 and n1 are equal to the halfWidth.
var ArcsClipJoin Joiner = ArcsJoiner{nil, 4.0}
var ArcsJoin Joiner = ArcsJoiner{BevelJoin, 4.0}
ArcsJoin connects two path elements by extending the ends of the paths as circle arcs until they meet. If this point is further than the limit, this will result in a bevel join (ArcsJoin) or they will meet at the limit (ArcsClipJoin).
var BevelJoin Joiner = BevelJoiner{}
BevelJoin connects two path elements by a linear join.
var MiterClipJoin Joiner = MiterJoiner{nil, 4.0} // TODO: should extend limit*halfwidth before bevel
var MiterJoin Joiner = MiterJoiner{BevelJoin, 4.0}
MiterJoin connects two path elements by extending the ends of the paths as lines until they meet. If this point is further than the limit, this will result in a bevel join (MiterJoin) or they will meet at the limit (MiterClipJoin).
var RoundJoin Joiner = RoundJoiner{}
RoundJoin connects two path elements by a round join.
type LinearGradient ¶
LinearGradient 是 start→end 的线性渐变。
func NewLinearGradient ¶
func NewLinearGradient(start, end Point) *LinearGradient
NewLinearGradient 返回线性渐变。
type Matrix ¶
type Matrix [2][3]float64
Matrix is used for affine transformations, which are transformations such as translation, scaling, reflection, rotation, shear stretching. See https://en.wikipedia.org/wiki/Affine_transformation#Image_transformation for an overview of the transformations. The affine transformation matrix contains all transformations in a matrix, where we can concatenate transformations to apply them sequentially. Be aware that concatenated transformations will be evaluated right-to-left! So that Identity.Rotate(30).Translate(20,0) will first translate 20 points horizontally and then rotate 30 degrees counter clockwise.
func ParallelogramCell ¶
ParallelogramCell is a paralellogram cell with sides of length a and b at an angle of rot degrees used for tiling.
func PrimitiveCell ¶
PrimitiveCell is a (primitive) cell used for tiling.
func RectangleCell ¶
RectangleCell is a rectangular cell with width a and height b used for tiling.
func RhombusCell ¶
RhombusCell is a rhombus cell with sides of length a at an angle of 120 degrees used for tiling.
func SquareCell ¶
SquareCell is a square cell with sides of length a used for tiling.
func TileRectangle ¶
TileRectangle tiles the given cell (determines the axes along which cells are repeated) onto the rectangle dst (bounds of clipping path), where cells are filled by rectangle src (bounds of object to be tiled).
func (Matrix) Decompose ¶
Decompose extracts the translation, rotation, scaling and rotation components (applied in the reverse order) as (tx, ty, theta, sx, sy, phi) with rotation counter clockwise. This corresponds to Identity.Translate(tx, ty).Rotate(phi).Scale(sx, sy).Rotate(theta).
func (Matrix) Dot ¶
Dot returns the dot product between the matrix and the given vector, i.e. applying the transformation.
func (Matrix) Eigen ¶
Eigen returns the matrix eigenvalues and eigenvectors. The first eigenvalue is related to the first eigenvector, and so for the second pair. Eigenvectors are normalized.
func (Matrix) HasRotation ¶
HasRotation is true if the matrix has a rotation or skewing component.
func (Matrix) HasScaling ¶
HasScaling is true if the matrix contains a scaling component.
func (Matrix) HasTranslation ¶
HasTranslation is true if the matrix contains a translational component.
func (Matrix) IsIdentity ¶
func (Matrix) IsRigid ¶
IsRigid is true if the matrix is orthogonal and consists of only isometric transformations: translation, rotation, and reflection.
func (Matrix) IsRotation ¶
IsRotation is true if the matrix consists of only rotational components, i.e. no scaling or skew transformations (but may translate).
func (Matrix) IsScaling ¶
IsScaling is true if the matrix consists of only scaling components, i.e. no rotation, or skew transformations (but may translate).
func (Matrix) IsSimilarity ¶
IsSimilarity is true if the matrix consists of only translation, rotation, reflection, and uniform scaling transformations. Uniform scaling means that it scales equally horizontally as vertically. If the scaling factor is 1.0, it is also a rigid transformation.
func (Matrix) IsTranslation ¶
IsTranslation is true if the matrix consists of only translational components, i.e. no rotation, scaling, or skew transformations.
func (Matrix) Mul ¶
Mul multiplies the current matrix by the given matrix, i.e. combining transformations.
func (Matrix) ReflectXAbout ¶
ReflectXAbout adds a horizontal reflection transformation about x.
func (Matrix) ReflectYAbout ¶
ReflectYAbout adds a vertical reflection transformation about y.
func (Matrix) RotateAbout ¶
RotateAbout adds a rotation transformation about (x,y) with rot in degrees counter clockwise.
func (Matrix) Scale ¶
Scale adds a scaling transformation in sx and sy. When scale is negative it will flip those axes.
func (Matrix) ScaleAbout ¶
ScaleAbout adds a scaling transformation about (x,y) in sx and sy. When scale is negative it will flip those axes.
func (Matrix) Shear ¶
Shear adds a shear transformation with sx the horizontal shear and sy the vertical shear.
func (Matrix) ShearAbout ¶
ShearAbout adds a shear transformation about (x,y) with sx the horizontal shear and sy the vertical shear.
func (Matrix) String ¶
String returns a string representation of the affine transformation matrix as six values, where [a b c; d e f; g h i] will be written as "a b d e c f" as g, h and i have fixed values (0, 0 and 1 respectively).
type MiterJoiner ¶
MiterJoiner is a miter joiner.
func (MiterJoiner) Join ¶
func (j MiterJoiner) Join(rhs, lhs *Path, halfWidth float64, pivot, n0, n1 Point, r0, r1 float64)
Join adds a join to a right-hand-side and left-hand-side path, of width 2*halfWidth, around a pivot point with starting and ending normals of n0 and n1, and radius of curvatures of the previous and next segments.
func (MiterJoiner) String ¶
func (j MiterJoiner) String() string
type Path ¶
type Path struct {
// contains filtered or unexported fields
}
Path defines a vector path in 2D using a series of commands (MoveTo, LineTo, QuadTo, CubeTo, ArcTo and Close). Each command consists of a number of float64 values (depending on the command) that fully define the action. The first value is the command itself (as a float64). The last two values is the end point position of the pen after the action (x,y). QuadTo defined one control point (x,y) in between, CubeTo defines two control points, and ArcTo defines (rx,ry,phi,large+sweep) i.e. the radius in x and y, its rotation (in radians) and the large and sweep booleans in one float64. Only valid commands are appended, so that LineTo has a non-zero length, QuadTo's and CubeTo's control point(s) don't (both) overlap with the start and end point, and ArcTo has non-zero radii and has non-zero length. For ArcTo we also make sure the angle is in the range [0, 2*PI) and we scale the radii up if they appear too small to fit the arc.
func Arc ¶
Arc returns a circular arc with radius r and theta0 and theta1 the angles in degrees of the ellipse (before rot is applies) between which the arc will run. If theta0 < theta1, the arc will run in a CCW direction. If the difference between theta0 and theta1 is bigger than 360 degrees, one full circle will be drawn and the remaining part of diff % 360, e.g. a difference of 810 degrees will draw one full circle and an arc over 90 degrees.
func BeveledRectangle ¶
BeveledRectangle returns a rectangle of width w and height h with beveled corners at distance r from the corner.
func EllipticalArc ¶
EllipticalArc returns an elliptical arc with radii rx and ry, with rot the counter clockwise rotation in degrees, and theta0 and theta1 the angles in degrees of the ellipse (before rot is applies) between which the arc will run. If theta0 < theta1, the arc will run in a CCW direction. If the difference between theta0 and theta1 is bigger than 360 degrees, one full circle will be drawn and the remaining part of diff % 360, e.g. a difference of 810 degrees will draw one full circle and an arc over 90 degrees.
func Grid ¶
Grid returns a stroked grid of width w and height h, with grid line thickness r, and the number of cells horizontally and vertically as nx and ny respectively.
func MustParseSVGPath ¶
MustParseSVGPath parses an SVG path data string and panics if it fails.
func NewPathFromData ¶
NewPathFromData returns a new path using the raw data.
func ParseSVGPath ¶
ParseSVGPath parses an SVG path data string.
func RegularPolygon ¶
RegularPolygon returns a regular polygon with radius r. It uses n vertices/edges, so when n approaches infinity this will return a path that approximates a circle. n must be 3 or more. The up boolean defines whether the first point will point upwards or downwards.
func RegularStarPolygon ¶
RegularStarPolygon returns a regular star polygon with radius r. It uses n vertices of density d. This will result in a self-intersection star in counter clockwise direction. If n/2 < d the star will be clockwise and if n and d are not coprime a regular polygon will be obtained, possible with multiple windings. n must be 3 or more and d 2 or more. The up boolean defines whether the first point will point upwards or downwards.
func RoundedRectangle ¶
RoundedRectangle returns a rectangle of width w and height h with rounded corners of radius r. A negative radius will cast the corners inwards (i.e. concave).
func StarPolygon ¶
StarPolygon returns a star polygon of n points with alternating radius R and r. The up boolean defines whether the first point will be point upwards or downwards.
func (*Path) And ¶
And returns the boolean path operation of path p AND q, i.e. the intersection of both. It removes all self-intersections and overlapping areas, orients all filling paths CCW and all holes CW, and tries to separate paths as much as possible. Paths are grouped by the filling/outer ring followed by the corresponding holes/inner rings; the outer rings are ordered from left-to-right and secondly from bottom-to-top. Note that path p is flattened unless q is already flat. Path q is implicitly closed. It runs in O((n + k) log n), with n the number of segments, and k the number of intersections.
func (*Path) Arc ¶
Arc adds an elliptical arc with radii rx and ry, with rot the counter clockwise rotation in degrees, and theta0 and theta1 the angles in degrees of the ellipse (before rot is applies) between which the arc will run. If theta0 < theta1, the arc will run in a CCW direction. If the difference between theta0 and theta1 is bigger than 360 degrees, one full circle will be drawn and the remaining part of diff % 360, e.g. a difference of 810 degrees will draw one full circle and an arc over 90 degrees.
func (*Path) ArcTo ¶
ArcTo adds an arc with radii rx and ry, with rot the counter clockwise rotation with respect to the coordinate system in degrees, large and sweep booleans (see https://developer.mozilla.org/en-US/docs/Web/SVG/Tutorial/Paths#Arcs), and (x,y) the end position of the pen. The start position of the pen was given by a previous command's end point.
func (*Path) CCW ¶
CCW returns true when the path is counter clockwise oriented at its right-most coordinate (bottom-most of all right-most coordinates). It is most useful when knowing that the path does not self-intersect as it will tell you if the entire path is CCW or not. It will only return the result for the first subpath. It will return true for an empty path or a straight line.
func (*Path) Clip ¶
Clip clips the path against the given rectangle. This is O(n), which is faster than using Path.And(rect.ToPath()) and does not alter the path structurally beyond removing sections.
func (*Path) Close ¶
func (p *Path) Close()
Close closes a (sub)path with a LineTo to the start of the path (the most recent MoveTo command). It also signals the path closes as opposed to being just a LineTo command, which can be significant for stroking purposes for example.
func (*Path) Contains ¶
Contains returns true if the interior of p contains the interior of q. Equal shapes contain each other. If p contains q, then q is within p. This tests DE-9IM's Covers relation.
func (*Path) ContainsPoint ¶
Contains returns whether the point (x,y) is contained/filled by the path. This depends on the FillRule. It uses a ray from (x,y) toward (∞,y) and counts the number of intersections with the path. When the point is on the boundary it is considered to be on the path's exterior.
func (*Path) CoordDirections ¶
CoordDirections returns the direction of the segment start/end points. It will return the average direction at the intersection of two end points, and for an open path it will simply return the direction of the start and end points of the path.
func (*Path) Coords ¶
Coords returns all the coordinates of the segment start/end points. It omits zero-length CloseCmds.
func (*Path) CrossingsAt ¶
Crossings returns the number of crossings with the path from the given point outwards, i.e. the number of times a ray from (x,y) towards (∞,y) intersects the path. Additionally, it returns whether the point is on a path's boundary (which does not count towards the number of crossings).
func (*Path) CubeTo ¶
CubeTo adds a cubic Bézier path with control points (cpx1,cpy1) and (cpx2,cpy2) and end point (x,y).
func (*Path) Curvature ¶
Curvature returns the curvature of the path at the given segment and t in [0.0,1.0] along that path. It is zero for straight lines and for non-existing segments.
func (*Path) Dash ¶
Dash returns a new path that consists of dashes. The elements in d specify the width of the dashes and gaps. It will alternate between dashes and gaps when picking widths. If d is an array of odd length, it is equivalent of passing d twice in sequence. The offset specifies the offset used into d (or negative offset into the path). Dash will be applied to each subpath independently.
func (*Path) Direction ¶
Direction returns the direction of the path at the given segment and t in [0.0,1.0] along that path. The direction is a vector of unit length.
func (*Path) Div ¶
Div returns the boolean path operation of path p DIV q, i.e. p divided by q. It removes all self-intersections and overlapping areas, orients all filling paths CCW and all holes CW, and tries to separate paths as much as possible. Paths are grouped by the filling/outer ring followed by the corresponding holes/inner rings; the outer rings are ordered from left-to-right and secondly from bottom-to-top. Note that path p is flattened unless q is already flat. Path q is implicitly closed. It runs in O((n + k) log n), with n the number of segments, and k the number of intersections.
func (*Path) Empty ¶
Empty returns true if p is an empty path or consists of only MoveTos and Closes.
func (*Path) FastBounds ¶
FastBounds returns the maximum bounding box rectangle of the path. It is quicker than Bounds.
func (*Path) FastClip ¶
FastClip removes all segments that are completely outside the given clipping rectangle. To ensure that the removal doesn't cause a segment to cross the rectangle from the outside, it keeps points that cross at least two lines to infinity along the rectangle's edges. It doesn't clip crossing segments at the boundary like Path.Clip. NOTE: this is twice as slow as Path.Clip!
func (*Path) Filling ¶
Filling returns whether each subpath gets filled or not. Whether a path is filled depends on the FillRule and whether it negates another path. If a subpath is not closed, it is implicitly assumed to be closed.
func (*Path) Flatten ¶
Flatten flattens all Bézier and arc curves into linear segments and returns a new path. It uses tolerance as the maximum deviation.
func (*Path) Gridsnap ¶
Gridsnap snaps all vertices to a grid with the given spacing. This will significantly reduce numerical issues e.g. for path boolean operations. This operation is in-place.
func (*Path) HasSubpaths ¶
HasSubpaths returns true when path p has subpaths. TODO: naming right? A simple path would not self-intersect. Add IsXMonotone and IsFlat as well?
func (*Path) Intersections ¶
Intersections returns a list of points of all intersections of path p with q. The intersection can be tangent (touch) or secant (cross). If the two paths are partially coincident it will return an intersection at the start and end. Equal paths have no intersections. If q is nil it returns the intersections of p with itself. Intersections are sorted from left-to-right, and otherwise from bottom-to-top.
func (*Path) IsFlat ¶
IsFlat returns true if the path consists of solely line segments, that is only MoveTo, LineTo and Close commands.
func (*Path) Join ¶
Join joins path q to p and returns the extended path p (or q if p is empty). It's like executing the commands in q to p in sequence, where if the first MoveTo of q doesn't coincide with p, or if p ends in Close, it will fallback to appending the paths.
func (*Path) Length ¶
Length returns the length of the path in millimeters. The length is approximated for cubic Béziers.
func (*Path) Markers ¶
Markers returns an array of start, mid and end marker paths along the path at the coordinates between commands. Align will align the markers with the path direction so that the markers orient towards the path's left.
func (*Path) MarshalBinary ¶
func (*Path) MoveTo ¶
MoveTo moves the path to (x,y) without connecting the path. It starts a new independent subpath. Multiple subpaths can be useful when negating parts of a previous path by overlapping it with a path in the opposite direction. The behaviour for overlapping paths depends on the FillRule.
func (*Path) Not ¶
Not returns the boolean path operation of path p NOT q, i.e. the difference of both. It removes all self-intersections and overlapping areas, orients all filling paths CCW and all holes CW, and tries to separate paths as much as possible. Paths are grouped by the filling/outer ring followed by the corresponding holes/inner rings; the outer rings are ordered from left-to-right and secondly from bottom-to-top. Note that path p is flattened unless q is already flat. Path q is implicitly closed. It runs in O((n + k) log n), with n the number of segments, and k the number of intersections.
func (*Path) Offset ¶
Offset offsets the path by w and returns a new path. A positive w will offset the path to the right-hand side, that is, it expands CCW oriented contours and contracts CW oriented contours. If you don't know the orientation you can use `Path.CCW` to find out, but if there may be self-intersection you should use `Path.Settle` to remove them and orient all filling contours CCW. The tolerance is the maximum deviation from the actual offset when flattening Béziers and optimizing the path.
func (*Path) Or ¶
Or returns the boolean path operation of path p OR q, i.e. the union of both. It It removes all self-intersections and overlapping areas, orients all filling paths CCW and all holes CW, and tries to separate paths as much as possible. Paths are grouped by the filling/outer ring followed by the corresponding holes/inner rings; the outer rings are ordered from left-to-right and secondly from bottom-to-top. Note that path p is flattened unless q is already flat. Path q is implicitly closed. It runs in O((n + k) log n), with n the number of segments, and k the number of intersections.
func (*Path) Overlaps ¶
Overlaps returns true if the interiors of p and q have at least one point in common. Either they have a secant intersection, one path in contained in the other, or both paths are equal. This is different from DE-9IM's definition of Overlaps.
func (*Path) PointClosed ¶
PointClosed returns true if the last subpath of p is a closed path and the close command is a point and not a line.
func (*Path) Pos ¶
Pos returns the current position of the path, which is the end point of the last command.
func (*Path) QuadTo ¶
QuadTo adds a quadratic Bézier path with control point (cpx,cpy) and end point (x,y).
func (*Path) RayIntersections ¶
func (p *Path) RayIntersections(x, y float64) []Intersection
RayIntersections returns the intersections of a path with a ray starting at (x,y) to (∞,y). An intersection is tangent only when it is at (x,y), i.e. the start of the ray. The parameter T along the ray is zero at the start but NaN otherwise. Intersections are sorted along the ray. This function runs in O(n) with n the number of path segments.
func (*Path) Relate ¶
Relate returns the spatial relation as defined by DE-9IM between the two paths as well as the intersections between both. It is faster if you need to check multiple spatial relations and/or retrieve the intersections.
func (*Path) ReplaceArcs ¶
ReplaceArcs replaces ArcTo commands by CubeTo commands and returns a new path.
func (*Path) Reset ¶
func (p *Path) Reset()
Reset clears the path but retains the same memory. This can be used in loops where you append and process paths every iteration, and avoid new memory allocations.
func (*Path) Reverse ¶
Reverse returns a new path that is the same path as p but in the reverse direction.
func (*Path) ReverseScanner ¶
func (p *Path) ReverseScanner() *PathReverseScanner
ReverseScanner returns a path scanner in reverse order.
func (*Path) Rotate ¶
Rotate rotates the path by deg degrees counter clockwise. It modifies the path in-place.
func (*Path) Same ¶
Same returns true if p and q are equal shapes within tolerance Epsilon. Path q may start at an offset into path p or may be in the reverse direction.
func (*Path) Sane ¶
Sane returns true if the path is sane, ie. it does not have NaN or infinity values.
func (*Path) Settle ¶
Settle returns the "settled"/flattened path, a visually identical version of the original. It removes all self-intersections and overlapping areas, orients all filling paths CCW and all holes CW, and tries to separate paths as much as possible. Paths are grouped by the filling/outer ring followed by the corresponding holes/inner rings; the outer rings are ordered from left-to-right and secondly from bottom-to-top. Note that path p is flattened unless q is already flat. It runs in O((n + k) log n), with n the number of segments, and k the number of intersections.
func (*Path) SimplifyVisvalingamWhyatt ¶
func (*Path) Split ¶
Split splits the path into its independent subpaths. The path is split before each MoveTo command.
func (*Path) SplitAt ¶
SplitAt splits the path into separate paths at the specified intervals (given in millimeters) along the path.
func (*Path) StartPos ¶
StartPos returns the start point of the current subpath, i.e. it returns the position of the last MoveTo command.
func (*Path) String ¶
String returns a string that represents the path similar to the SVG path data format (but not necessarily valid SVG).
func (*Path) Stroke ¶
Stroke converts a path into a stroke of width w and returns a new path. It uses cr to cap the start and end of the path, and jr to join all path elements. If the path closes itself, it will use a join between the start and end instead of capping them. The tolerance is the maximum deviation from the original path when flattening Béziers and optimizing the stroke.
func (*Path) ToSVG ¶
ToSVG returns a string that represents the path in the SVG path data format with minification.
func (*Path) Touches ¶
Touches returns true if path p and q are not disjoint, their boundaries/interiors intersect. This is different from DE-9IM's definition of Touches.
func (*Path) Transform ¶
Transform transforms the path by the given transformation matrix. It modifies the path in-place.
func (*Path) TransformFunc ¶
TransformFunc transforms the path by the given function: (x,y)=>(x,y). It modifies the path in-place.
func (*Path) Triangulate ¶
Triangulate tessellates the path with triangles that fill the path. WIP
func (*Path) UnmarshalBinary ¶
func (*Path) WindingsAt ¶
Windings returns the number of windings at the given point, i.e. the sum of windings for each time a ray from (x,y) towards (∞,y) intersects the path. Counter clock-wise intersections count as positive, while clock-wise intersections count as negative. Additionally, it returns whether the point is on a path's boundary (which counts as being on the exterior).
func (*Path) XMonotone ¶
XMonotone replaces all Bézier and arc segments to be x-monotone and returns a new path, that is each path segment is either increasing or decreasing with X while moving across the segment. This is always true for line segments.
func (*Path) Xor ¶
Xor returns the boolean path operation of path p XOR q, i.e. the symmetric difference of both. It removes all self-intersections and overlapping areas, orients all filling paths CCW and all holes CW, and tries to separate paths as much as possible. Paths are grouped by the filling/outer ring followed by the corresponding holes/inner rings; the outer rings are ordered from left-to-right and secondly from bottom-to-top. Note that path p is flattened unless q is already flat. Path q is implicitly closed. It runs in O((n + k) log n), with n the number of segments, and k the number of intersections.
type PathReverseScanner ¶
type PathReverseScanner struct {
// contains filtered or unexported fields
}
PathReverseScanner scans the path in reverse order.
func (*PathReverseScanner) CP1 ¶
func (s *PathReverseScanner) CP1() Point
CP1 returns the first control point for quadratic and cubic Béziers.
func (*PathReverseScanner) CP2 ¶
func (s *PathReverseScanner) CP2() Point
CP2 returns the second control point for cubic Béziers.
func (*PathReverseScanner) Cmd ¶
func (s *PathReverseScanner) Cmd() float64
Cmd returns the current path segment command.
func (*PathReverseScanner) End ¶
func (s *PathReverseScanner) End() Point
End returns the current path segment end position.
func (*PathReverseScanner) Path ¶
func (s *PathReverseScanner) Path() *Path
Path returns the current path segment.
func (*PathReverseScanner) Scan ¶
func (s *PathReverseScanner) Scan() bool
Scan scans a new path segment and should be called before the other methods.
func (*PathReverseScanner) Start ¶
func (s *PathReverseScanner) Start() Point
Start returns the current path segment start position.
func (*PathReverseScanner) Values ¶
func (s *PathReverseScanner) Values() []float64
Values returns the current path segment values.
type PathScanner ¶
type PathScanner struct {
// contains filtered or unexported fields
}
PathScanner scans the path.
func (*PathScanner) CP1 ¶
func (s *PathScanner) CP1() Point
CP1 returns the first control point for quadratic and cubic Béziers.
func (*PathScanner) CP2 ¶
func (s *PathScanner) CP2() Point
CP2 returns the second control point for cubic Béziers.
func (*PathScanner) Cmd ¶
func (s *PathScanner) Cmd() float64
Cmd returns the current path segment command.
func (*PathScanner) End ¶
func (s *PathScanner) End() Point
End returns the current path segment end position.
func (*PathScanner) Path ¶
func (s *PathScanner) Path() *Path
Path returns the current path segment.
func (*PathScanner) Scan ¶
func (s *PathScanner) Scan() bool
Scan scans a new path segment and should be called before the other methods.
func (*PathScanner) Start ¶
func (s *PathScanner) Start() Point
Start returns the current path segment start position.
func (*PathScanner) Values ¶
func (s *PathScanner) Values() []float64
Values returns the current path segment values.
type Paths ¶
type Paths []*Path
func (Paths) And ¶
And is the same as Path.And, but faster if paths are already split. Each resulting path is a single filling path followed by its holes as subpaths.
func (Paths) Div ¶
Div is the same as Path.DivideBy, but faster if paths are already split. Each resulting path is a single filling path followed by its holes as subpaths.
func (Paths) Not ¶
Not is the same as Path.Not, but faster if paths are already split. Each resulting path is a single filling path followed by its holes as subpaths.
func (Paths) Or ¶
Or is the same as Path.Or, but faster if paths are already split. Each resulting path is a single filling path followed by its holes as subpaths.
type Point ¶
type Point struct {
X, Y float64
}
Point is a coordinate in 2D space. OP refers to the line that goes through the origin (0,0) and this point (x,y).
func EllipsePos ¶
EllipsePos returns the position on the ellipse at angle theta.
func PolarPoint ¶
PolarPoint returns a point from polar coordinates, with angle in radians CCW and radius the distance from (0,0).
func (Point) AngleBetween ¶
AngleBetween returns the angle in radians [-PI,PI] from OP to OQ.
func (Point) Dot ¶
Dot returns the dot product between OP and OQ, i.e. zero if perpendicular and |OP|*|OQ| if aligned.
func (Point) Hadamard ¶
Hadamard returns the Hadamard product, or the element-wise product, of the point.
func (Point) Interpolate ¶
Interpolate returns a point on PQ that is linearly interpolated by t in [0,1], i.e. t=0 returns P and t=1 returns Q.
func (Point) PerpDot ¶
PerpDot returns the perp dot product between OP and OQ, i.e. zero if aligned and |OP|*|OQ| if perpendicular. This is the cross product in two dimensions.
type Polyline ¶
type Polyline struct {
// contains filtered or unexported fields
}
Polyline defines a list of points in 2D space that form a polyline. If the last coordinate equals the first coordinate, we assume the polyline to close itself.
func PolylineFromPath ¶
PolylineFromPath returns a polyline from the given path by approximating it by linear line segments, i.e. by flattening.
func PolylineFromPathCoords ¶
PolylineFromPathCoords returns a polyline from the given path from each of the start/end coordinates of the segments, i.e. converting all non-linear segments to linear ones.
func (*Polyline) FillCount ¶
FillCount returns the number of times the test point is enclosed by the polyline. Counter clockwise enclosures are counted positively and clockwise enclosures negatively.
func (*Polyline) Interior ¶
Interior is true when the point (x,y) is in the interior of the path, i.e. gets filled. This depends on the FillRule.
type RadialGradient ¶
type RadialGradient struct {
Grad
C0, C1 Point
R0, R1 float64
// contains filtered or unexported fields
}
RadialGradient 是两个圆之间的径向渐变。
func NewRadialGradient ¶
func NewRadialGradient(c0 Point, r0 float64, c1 Point, r1 float64) *RadialGradient
NewRadialGradient 返回径向渐变。
type Rect ¶
type Rect struct {
X0, Y0, X1, Y1 float64
}
Rect is a rectangle in 2D defined by a position and its width and height.
func RectFromPoints ¶
func RectFromSize ¶
func (Rect) AddPoint ¶
AddPoint returns a rect that encompasses both the current rect and the given point.
func (Rect) ClosestPoint ¶
ClosestPoint returns a point in the rectangle closest to the given point.
func (Rect) ContainsLine ¶
func (Rect) ContainsPoint ¶
ContainsPoint returns true if the rectangle contains or touches an edge.
func (Rect) DistanceToPoint ¶
DistanceToPoint returns the distance between the rectangle and a point.
func (Rect) OverlapsLine ¶
func (Rect) TouchesLine ¶
func (Rect) TouchesPoint ¶
TouchesPoint returns true if the rectangle touches a point (within +-Epsilon).
type Relation ¶
type Relation byte
The DE-9IM naming scheme is used for spatial relationships and geometry intersection classification. Note: - Contains does not include the boundary: a point/line completely on the boundary of a polygon is not contained by the polygon. - Touches means both geometries touch but do not overlap nor are equal/contained/covered - Overlaps means that both geometries overlap but are not equal/contained/covered
func (Relation) Contains ¶
Contains returns true if at least one point of the second shape lies in the first, and no points of the second lie in the exterior of the first.
func (Relation) Covers ¶
Covers returns true if at least one point of the second shape lies in the first, and no points of the second lie in the exterior of the first, including boundaries. It is similar to Contains but includes lines on the boundary of an area.
func (Relation) Equals ¶
Equals returns true if all interior points of one are interior of the other, and the same for exterior points.
func (Relation) Intersects ¶
Intersects returns true if both shapes have at least one point in common, ie. they may touch/overlap/contain/equal.
func (Relation) Overlaps ¶
Overlaps returns true if both shapes have some but not all points in common. This is different from the DE-9IM specification since it does not consider the dimensionality of the shapes. The result is that equal shapes do not overlap, points never overlap, crossing lines overlap, and contained/covered shapes do not overlap.
type Resolution ¶
type Resolution float64
Resolution 是栅格化输出分辨率,内部以「点/毫米」存储(与 canvas.Resolution 语义一致)。DPI 用于对外表达「点/英寸」。
type RoundCapper ¶
type RoundCapper struct{}
RoundCapper is a round capper.
func (RoundCapper) Cap ¶
func (RoundCapper) Cap(p *Path, halfWidth float64, pivot, n0 Point)
Cap adds a cap to path p of width 2*halfWidth, at a pivot point and initial normal direction of n0.
func (RoundCapper) String ¶
func (RoundCapper) String() string
type RoundJoiner ¶
type RoundJoiner struct{}
RoundJoiner is a round joiner.
func (RoundJoiner) Join ¶
func (RoundJoiner) Join(rhs, lhs *Path, halfWidth float64, pivot, n0, n1 Point, r0, r1 float64)
Join adds a join to a right-hand-side and left-hand-side path, of width 2*halfWidth, around a pivot point with starting and ending normals of n0 and n1, and radius of curvatures of the previous and next segments.
func (RoundJoiner) String ¶
func (RoundJoiner) String() string
type Segment ¶
Segment is a path command.
type SquareCapper ¶
type SquareCapper struct{}
SquareCapper is a square capper.
func (SquareCapper) Cap ¶
func (SquareCapper) Cap(p *Path, halfWidth float64, pivot, n0 Point)
Cap adds a cap to path p of width 2*halfWidth, at a pivot point and initial normal direction of n0.
func (SquareCapper) String ¶
func (SquareCapper) String() string
type SweepEvents ¶
type SweepEvents []*SweepPoint
SweepEvents is a heap priority queue of sweep events.
func (*SweepEvents) AddPathEndpoints ¶
func (q *SweepEvents) AddPathEndpoints(p *Path, seg int, clipping bool) int
AddPathEndpoints adds all line segments of p to the queue q. The first command is converted to a MoveToCmd and any CloseCmd that is not at the end is converted to a LineToCmd.
func (SweepEvents) Init ¶
func (q SweepEvents) Init()
func (SweepEvents) Less ¶
func (q SweepEvents) Less(i, j int) bool
func (*SweepEvents) Pop ¶
func (q *SweepEvents) Pop() *SweepPoint
func (SweepEvents) Print ¶
func (q SweepEvents) Print(w io.Writer)
func (*SweepEvents) Push ¶
func (q *SweepEvents) Push(item *SweepPoint)
func (SweepEvents) String ¶
func (q SweepEvents) String() string
func (SweepEvents) Swap ¶
func (q SweepEvents) Swap(i, j int)
func (*SweepEvents) Top ¶
func (q *SweepEvents) Top() *SweepPoint
type SweepNode ¶
type SweepNode struct {
*SweepPoint
// contains filtered or unexported fields
}
type SweepPoint ¶
type SweepPoint struct {
// initial data
Point // position of this endpoint
// contains filtered or unexported fields
}
SweepPoint is of size 88 bytes on 64-bit architectures
func (*SweepPoint) CompareH ¶
func (a *SweepPoint) CompareH(b *SweepPoint) int
func (*SweepPoint) CompareV ¶
func (a *SweepPoint) CompareV(b *SweepPoint) int
func (*SweepPoint) InResult ¶
func (s *SweepPoint) InResult(op pathOp, fillRule FillRule) uint8
func (*SweepPoint) InterpolateY ¶
func (s *SweepPoint) InterpolateY(x float64) float64
func (*SweepPoint) LessH ¶
func (a *SweepPoint) LessH(b *SweepPoint) bool
func (*SweepPoint) Reverse ¶
func (s *SweepPoint) Reverse()
func (*SweepPoint) SplitAt ¶
func (s *SweepPoint) SplitAt(z Point) (*SweepPoint, *SweepPoint)
func (*SweepPoint) String ¶
func (s *SweepPoint) String() string
func (*SweepPoint) ToleranceEdgeY ¶
func (s *SweepPoint) ToleranceEdgeY(xLeft, xRight float64) (float64, float64)
ToleranceEdgeY returns the y-value of the SweepPoint at the tolerance edges given by xLeft and xRight, or at the endpoints of the SweepPoint, whichever comes first.
type SweepStatus ¶
type SweepStatus struct {
// contains filtered or unexported fields
}
TODO: test performance versus (2,4)-tree (current LEDA implementation), (2,16)-tree (as proposed by S. Naber/Näher in "Comparison of search-tree data structures in LEDA. Personal communication" apparently), RB-tree (likely a good candidate), and an AA-tree (simpler implementation may be faster). Perhaps an unbalanced (e.g. Treap) works well due to the high number of insertions/deletions. In any case, measure the amount of finds and inserts/deletes. If finds >> inserts probably AVL is better, if somewhat similar or inserts > finds then perhaps an RB tree (store color in sign bit of node's height).
func (*SweepStatus) FindPrevNext ¶
func (s *SweepStatus) FindPrevNext(item *SweepPoint) (*SweepNode, *SweepNode)
func (*SweepStatus) InsertAfter ¶
func (s *SweepStatus) InsertAfter(n *SweepNode, item *SweepPoint) *SweepNode
func (*SweepStatus) Remove ¶
func (s *SweepStatus) Remove(n *SweepNode)
func (*SweepStatus) String ¶
func (s *SweepStatus) String() string
type VisvalingamWhyatt ¶
type VisvalingamWhyatt struct {
// contains filtered or unexported fields
}
func NewVisvalingamWhyatt ¶
func NewVisvalingamWhyatt(filter CoordinateFilter) *VisvalingamWhyatt