MCPcopy Index your code
hub / github.com/gonum/plot / Rectangle

Method Rectangle

text/text.go:138–164  ·  view source on GitHub ↗

Rectangle returns a rectangle giving the bounds of this text assuming that it is drawn at (0, 0).

(txt string)

Source from the content-addressed store, hash-verified

136// Rectangle returns a rectangle giving the bounds of
137// this text assuming that it is drawn at (0, 0).
138func (s Style) Rectangle(txt string) vg.Rectangle {
139 e := s.Handler.Extents(s.Font)
140 w, h := s.box(txt)
141 desc := vg.Length(e.Height - e.Ascent) // descent + linegap
142 xoff := vg.Length(s.XAlign) * w
143 yoff := vg.Length(s.YAlign)*h - desc
144
145 // lower left corner
146 p1 := rotatePoint(s.Rotation, vg.Point{X: xoff, Y: yoff})
147 // upper left corner
148 p2 := rotatePoint(s.Rotation, vg.Point{X: xoff, Y: h + yoff})
149 // lower right corner
150 p3 := rotatePoint(s.Rotation, vg.Point{X: w + xoff, Y: yoff})
151 // upper right corner
152 p4 := rotatePoint(s.Rotation, vg.Point{X: w + xoff, Y: h + yoff})
153
154 return vg.Rectangle{
155 Max: vg.Point{
156 X: max(p1.X, p2.X, p3.X, p4.X),
157 Y: max(p1.Y, p2.Y, p3.Y, p4.Y),
158 },
159 Min: vg.Point{
160 X: min(p1.X, p2.X, p3.X, p4.X),
161 Y: min(p1.Y, p2.Y, p3.Y, p4.Y),
162 },
163 }
164}
165
166// rotatePoint applies rotation theta (in radians) about the origin to point p.
167func rotatePoint(theta float64, p vg.Point) vg.Point {

Callers

nothing calls this directly

Calls 5

boxMethod · 0.95
rotatePointFunction · 0.85
maxFunction · 0.85
minFunction · 0.85
ExtentsMethod · 0.65

Tested by

no test coverage detected