Пример #1
0
    def value(self, y_0=0):
        pws = py2geom.PiecewiseSBasis()
        for i in range(0, self.handles_per_curve, self.curve_size):
            pws.push_cut(self.pts[i][0])
            for j in range(i, i + self.curve_size):
                self.pts[j] = py2geom.Point(self.pts[j][0],
                                            self.pts[j][1] - y_0)
            hnd = self.pts[i:i + self.curve_size]
            pws.push_seg(bez_to_sbasis(hnd, self.curve_size - 1))
            for j in range(i, i + self.curve_size):
                self.pts[j] = py2geom.Point(self.pts[j][0],
                                            self.pts[j][1] + y_0)

        pws.push_cut(self.pts[self.handles_per_curve - 1][0])
        assert (pws.invariants())
        return pws
Пример #2
0
    def move_to(self, hit, om, m):
        om = py2geom.Point(*om)
        m = py2geom.Point(*m)
        if hit != None:
            i, hand = hit
            self.pts[hand] = m
            for i in range(self.curve_size, self.handles_per_curve,
                           self.curve_size):
                self.pts[i - 1] = py2geom.Point(self.pts[i][0],
                                                self.pts[i - 1][1])

            for i in range(0, self.handles_per_curve, self.curve_size):
                for j in range(1, (self.curve_size - 1)):
                    t = float(j) / (self.curve_size - 1)
                    x = lerp(self.pts[i][0],
                             self.pts[i + self.curve_size - 1][0], t)
                    self.pts[i + j] = py2geom.Point(x, self.pts[i + j][1])
Пример #3
0
 def __init__(self):
     toyframework.Toy.__init__(self)
     self.handles.append(toyframework.PointHandle(200, 200))
     self.path_b_name = "star.svgd"
     self.pv = py2geom.read_svgd(self.path_b_name)
     centr = py2geom.Point()
     for p in self.pv:
         c, area = py2geom.centroid(p.toPwSb())
         centr += c
     self.pv = self.pv * py2geom.Matrix(py2geom.Translate(-centr))
Пример #4
0
    def draw(self, cr, pos, save):
        cr.set_source_rgba(0., 0., 0., 1)
        cr.set_line_width(1)

        pws = [self.pwsbh[i].value() for i in range(self.curves)]
        for p in pws:
            cairo_pw(cr, p)
        cr.stroke()

        d = locals().copy()
        for i in dir(py2geom):
            d[i] = py2geom.__dict__[i]
        d['l2s'] = l2s
        d['constant'] = constant
        pw_out = eval(self.func, d)

        bs = py2geom.bounds_local(
            pw_out,
            py2geom.OptInterval(
                py2geom.Interval(self.interval_test[0].pos[0],
                                 self.interval_test[1].pos[0])))
        if not bs.isEmpty():
            bs = bs.toInterval()
            for ph in self.interval_test:
                ph.pos = py2geom.Point(ph.pos[0], bs.middle())
            cr.save()
            cr.set_source_rgba(.0, 0.25, 0.5, 1.)
            cr.rectangle(
                self.interval_test[0].pos[0], bs.min(),
                self.interval_test[1].pos[0] - self.interval_test[0].pos[0],
                bs.extent())
            cr.stroke()
        bs = py2geom.bounds_exact(pw_out)
        cr.set_source_rgba(0.25, 0.25, .5, 1.)
        if not bs.isEmpty():
            bs = bs.toInterval()
            cairo_horiz(cr, bs.middle(), pw_out.cuts)
            cr.stroke()
        cr.restore()

        cr.set_source_rgba(0., 0., .5, 1.)
        cairo_pw(cr, pw_out)
        cr.stroke()

        self.notify = str(bs)
        toyframework.Toy.draw(self, cr, pos, save)
Пример #5
0
#!/usr/bin/python

import py2geom as g

a = g.Point(1, 2)
b = g.Point(31, 2)
print a, b

point_fns_1 = [
    "L1", "L2", "L2sq", "LInfty", "is_zero", "is_unit_vector", "atan2",
    "rot90", "unit_vector", "abs"
]
point_fns_2 = ["dot", "angle_between", "distance", "distanceSq", "cross"]

for i in point_fns_1:
    print "%s:" % i, g.__dict__[i](a)
for i in point_fns_2:
    print "%s:" % i, g.__dict__[i](a, b)
print "a == b", a == b
print "Lerp:", g.lerp(0.3, a, b)

bo = g.BezOrd(2, 3)
print bo
print bo.point_at(0.3)

print bo.reverse()

sn = g.sin(g.BezOrd(0.0, 8.0), 5)
print sn
print g.inverse(sn, 10)
print list(sn)
Пример #6
0
# test of 2geom ray bindings

import py2geom as g

# find one point along a ray
a = g.Point(0, 0)
b = g.Point(2, 2)

r = g.Ray(a, b)
from math import sqrt
print r.pointAt(sqrt(2))

# measure the angle between two rays
c = g.Point(2, -2)
r2 = g.Ray(a, c)
from math import degrees
# FIXME: the third argument (clockwise) ought to be optional, but has to be supplied
print degrees(g.angle_between(r, r2, True))
print degrees(g.angle_between(r, r2))
Пример #7
0
 def hit(self, mouse):
     for i, p in enumerate(self.pts):
         if (py2geom.distance(py2geom.Point(*mouse), p) < 5):
             return i
     return None
Пример #8
0
 def append(self, x, y):
     self.pts.append(py2geom.Point(x, y))