MCPcopy Create free account
hub / github.com/Image-Py/imagepy / Coordinate

Class Coordinate

imagepy/tools/Measure/coordinate_tol.py:14–55  ·  view source on GitHub ↗

Define the coordinate class

Source from the content-addressed store, hash-verified

12import pandas as pd
13
14class Coordinate:
15 """Define the coordinate class"""
16 dtype = 'coordinate'
17 def __init__(self, body=None, unit=None):
18 self.body = body if body!=None else []
19 self.unit = unit
20
21 def add(self, p):
22 self.body.append(p)
23
24 def snap(self, x, y, lim):
25 cur, minl = None, 1000
26 for i in self.body:
27 d = (i[0]-x)**2+(i[1]-y)**2
28 if d < minl:cur,minl = i,d
29 if minl**0.5>lim:return None
30 return self.body.index(cur)
31
32 def pick(self, x, y, lim):
33 return self.snap(x, y, lim)
34
35 def draged(self, ox, oy, nx, ny, i):
36 self.body[i] = (nx, ny)
37
38 def draw(self, dc, f, **key):
39 dc.SetPen(wx.Pen(Setting['color'], width=1, style=wx.SOLID))
40 dc.SetTextForeground(Setting['tcolor'])
41 font = wx.Font(10, wx.FONTFAMILY_DEFAULT,
42 wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL, False)
43
44 dc.SetFont(font)
45 for i in self.body:
46 x,y = f(*i)
47 unit = 1 if self.unit is None else self.unit[0]
48 dc.DrawCircle(x, y, 2)
49 dc.DrawText('(%.1f,%.1f)'%(i[0]*unit, i[1]*unit), x, y)
50
51 def report(self, title):
52 unit = 1 if self.unit is None else self.unit[0]
53 rst = [(x*unit, y*unit) for x,y in self.body]
54 titles = ['OX', 'OY']
55 IPy.show_table(pd.DataFrame(rst, columns=titles), title)
56
57class Plugin(Tool):
58 """Define the coordinate class plugin with the event callback functions"""

Callers 1

mouse_downMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected