MCPcopy Create free account
hub / github.com/tdewolff/canvas / Transform

Method Transform

util.go:438–448  ·  view source on GitHub ↗

Transform transforms the rectangle by affine transformation matrix m and returns the new bounds of that rectangle.

(m Matrix)

Source from the content-addressed store, hash-verified

436
437// Transform transforms the rectangle by affine transformation matrix m and returns the new bounds of that rectangle.
438func (r Rect) Transform(m Matrix) Rect {
439 p0 := m.Dot(Point{r.X0, r.Y0})
440 p1 := m.Dot(Point{r.X1, r.Y0})
441 p2 := m.Dot(Point{r.X1, r.Y1})
442 p3 := m.Dot(Point{r.X0, r.Y1})
443 x0 := math.Min(p0.X, math.Min(p1.X, math.Min(p2.X, p3.X)))
444 y0 := math.Min(p0.Y, math.Min(p1.Y, math.Min(p2.Y, p3.Y)))
445 x1 := math.Max(p0.X, math.Max(p1.X, math.Max(p2.X, p3.X)))
446 y1 := math.Max(p0.Y, math.Max(p1.Y, math.Max(p2.Y, p3.Y)))
447 return Rect{x0, y0, x1, y1}
448}
449
450// Add returns a rect that encompasses both the current rect and the given rect.
451func (r Rect) Add(q Rect) Rect {

Callers 2

TestRectFunction · 0.95
BoundsMethod · 0.95

Calls 1

DotMethod · 0.45

Tested by 1

TestRectFunction · 0.76