MCPcopy Create free account
hub / github.com/cogentcore/core / ClosestDataToPixel

Method ClosestDataToPixel

plot/plot.go:222–243  ·  view source on GitHub ↗

ClosestDataToPixel returns the Plotter data point closest to given pixel point, in the Pixels image.

(px, py int)

Source from the content-addressed store, hash-verified

220// ClosestDataToPixel returns the Plotter data point closest to given pixel point,
221// in the Pixels image.
222func (pt *Plot) ClosestDataToPixel(px, py int) (plt Plotter, idx int, dist float32, data, pixel math32.Vector2, legend string) {
223 tp := math32.Vec2(float32(px), float32(py))
224 dist = float32(math32.MaxFloat32)
225 for _, p := range pt.Plotters {
226 dts, pxls := p.XYData()
227 for i := range pxls.Len() {
228 ptx, pty := pxls.XY(i)
229 pxy := math32.Vec2(ptx, pty)
230 d := pxy.DistanceTo(tp)
231 if d < dist {
232 dist = d
233 pixel = pxy
234 plt = p
235 idx = i
236 dx, dy := dts.XY(i)
237 data = math32.Vec2(dx, dy)
238 legend = pt.Legend.LegendForPlotter(p)
239 }
240 }
241 }
242 return
243}

Callers 1

WidgetTooltipMethod · 0.80

Calls 6

Vec2Function · 0.92
LegendForPlotterMethod · 0.80
XYDataMethod · 0.65
LenMethod · 0.65
XYMethod · 0.65
DistanceToMethod · 0.45

Tested by

no test coverage detected