Exemple #1
0
 def draw_wedge(self, head, tail, color):
     width = self.displaymlb * 0.2
     tmpl = '<polygon points="{}" fill="{}" />\n'
     t1 = m_seg(tail, head, math.pi / -2, width / 2)[0]
     t2 = m_seg(tail, head, math.pi / 2, width / 2)[0]
     ptext = ' '.join(['{},{}'.format(
         round(x, 2), round(y, 2)) for x, y in (head, t1, t2)])
     self._elems.append(tmpl.format(ptext, color))
Exemple #2
0
 def _draw_wedge(self, head, tail, width, color=(0, 0, 0)):
     chead = self._convert(head)
     ctail = self._convert(tail)
     b1 = m_seg(ctail, chead, math.pi / -2, width / 2)[0]
     b2 = m_seg(ctail, chead, math.pi / 2, width / 2)[0]
     ps = (chead, b1, b2)
     polygon = QtGui.QPolygonF()
     for ver in ps:
         polygon.append(QtCore.QPointF(*ver))
     pen = QtGui.QPen(QtGui.QColor(*color), 1, QtCore.Qt.SolidLine)
     self.painter.setPen(pen)
     self.painter.setBrush(QtGui.QColor(*color))
     self.painter.drawPolygon(polygon)
Exemple #3
0
 def draw_dashed_wedge(self, head, tail, color):
     width = self.displaymlb * 0.2
     t1 = m_seg(tail, head, math.pi / -2, width / 2)[0]
     t2 = m_seg(tail, head, math.pi / 2, width / 2)[0]
     step_num = 7
     for i in range(step_num):
         step = distance(head, tail) / step_num * i
         trim = 1 / step_num * i
         tp1, tp2 = p_seg(t1, t2, True, step, trim)
         tpx, tpy = [tuple(p) for p in zip(tp1, tp2)]
         self.ax.add_line(mpl.lines.Line2D(
             tpx, tpy, c=color, lw=1.5, clip_on=False
         ))
Exemple #4
0
 def draw_wave_line(self, p1, p2, color):
     width = self.displaymlb * 0.2
     tmpl = '<polyline points="{}" stroke="{}" fill="none" />\n'
     s1 = m_seg(p1, p2, math.pi / -2, width / 2)
     s2 = m_seg(p1, p2, math.pi / 2, width / 2)
     ps = [p1]
     for i, s in enumerate((s1, s2, s1, s2, s1, s2)):
         p = scale(s[1], (i + 1) / 7, s[0])
         ps.append(p)
     ps.append(p2)
     ptext = ' '.join(['{},{}'.format(
         round(x, 2), round(y, 2)) for x, y in ps])
     self._elems.append(tmpl.format(ptext, color))
Exemple #5
0
 def draw_dashed_wedge(self, head, tail, color):
     width = self.displaymlb * 0.2
     tmpl = '<line x1="{}" y1="{}" x2="{}" y2="{}" stroke="{}" />\n'
     t1 = m_seg(tail, head, math.pi / -2, width / 2)[0]
     t2 = m_seg(tail, head, math.pi / 2, width / 2)[0]
     step_num = 7
     for i in range(step_num):
         step = distance(head, tail) / step_num * i
         trim = 1 / step_num * i
         tp1, tp2 = p_seg(t1, t2, True, step, trim)
         self._elems.append(
             tmpl.format(round(tp1[0], 2), round(tp1[1], 2),
                         round(tp2[0], 2), round(tp2[1], 2), color))
Exemple #6
0
 def _draw_wave_line(self, pos1, pos2, width, color=(0, 0, 0)):
     cpos1 = self._convert(pos1)
     cpos2 = self._convert(pos2)
     b1 = m_seg(cpos1, cpos2, math.pi / -2, width / 2)
     b2 = m_seg(cpos1, cpos2, math.pi / 2, width / 2)
     path = QtGui.QPainterPath()
     path.moveTo(*cpos1)
     for i, b in enumerate([b1, b2, b1, b2, b1, b2]):
         p = scale(b[1], (i + 1) / 7, b[0])
         path.lineTo(*p)
     path.lineTo(*cpos2)
     pen = QtGui.QPen(QtGui.QColor(*color), 1, QtCore.Qt.SolidLine)
     self.painter.setPen(pen)
     self.painter.drawPath(path)
Exemple #7
0
 def _draw_dashed_wedge(self, head, tail, width, color=(0, 0, 0)):
     chead = self._convert(head)
     ctail = self._convert(tail)
     b1 = m_seg(ctail, chead, math.pi / -2, width / 2)[0]
     b2 = m_seg(ctail, chead, math.pi / 2, width / 2)[0]
     pen = QtGui.QPen(QtGui.QColor(*color), 1, QtCore.Qt.SolidLine)
     self.painter.setPen(pen)
     step_num = 6
     # TODO: adjust step number
     for i in range(step_num):
         step = distance(chead, ctail) / step_num * i
         trim = 1 / step_num * i
         bp1, bp2 = p_seg(b1, b2, True, step, trim)
         qp1 = QtCore.QPointF(*bp1)
         qp2 = QtCore.QPointF(*bp2)
         self.painter.drawLine(qp1, qp2)
Exemple #8
0
 def draw_wave_line(self, pos1, pos2, color):
     width = self.displaymlb * 0.2
     s1 = m_seg(pos1, pos2, math.pi / -2, width / 2)
     s2 = m_seg(pos1, pos2, math.pi / 2, width / 2)
     codes = [mpl.path.Path.MOVETO]
     vers = [pos1]
     for i, s in enumerate((s1, s2, s1, s2, s1, s2)):
         p = scale(s[1], (i + 1) / 7, s[0])
         codes.append(mpl.path.Path.LINETO)
         vers.append(p)
     codes.append(mpl.path.Path.LINETO)
     vers.append(pos2)
     path = mpl.path.Path(vers, codes)
     self.ax.add_patch(mpl.patches.PathPatch(
         path, fc="None", ec=color, lw=1.5, clip_on=False
     ))
Exemple #9
0
 def test_move_seg(self):
     p1 = (1, 1)
     p2 = (2, 2)
     seg = gm.m_seg(p1, p2, math.pi / -2, math.sqrt(2) / 2)
     self.assertEqual(seg, ((1.5, 0.5), (2.5, 1.5)))