Exemple #1
0
def test_distance2():
    p1 = pgf.var_vec2()
    p2 = pgf.var_vec2()
    dist = pgf.distance(p1, p2)
    for _ in range(20):
        val1 = (random.uniform(1.2, 12.5), random.uniform(2.5, 15.6))
        val2 = (random.uniform(1.26, 22.5), random.uniform(1.5, 13.9))
        dval = math.sqrt(
            math.pow(val1[0] - val2[0], 2.) + math.pow(val1[1] - val2[1], 2.))
        pgf.assign(p1, val1)
        pgf.assign(p2, val2)

        assert tu.equalf(pgf.read(dist), dval)
Exemple #2
0
def test_cachedOffsetDataRegression():
    # This tests for a regression (lack of) happened while working on PR # 53.
    pt = pgf.var_vec3((0., 0., 0.))
    norm = pgf.var_vec3((0., 0., 1.))
    plane = pgf.plane(pt, norm)
    minpt = pgf.var_vec3((-.5, -.5, 0.))
    maxpt = pgf.var_vec3((.5, .5, 0.))
    box2 = pgf.box2(pgf.var_vec2((-.5, -.5)), pgf.var_vec2((.5, .5)))
    box3 = pgf.box3(minpt, maxpt)
    npts = pgf.var_int(4)
    cloud = pgf.randomPointsInBox(box3, npts)
    edgeLen = pgf.var_float(1)
    rect = pgf.rectangleMesh(plane, box2, edgeLen)
    distances = pgf.distance(pgf.graft(pgf.vertices(rect)), cloud)
    pdists = pgf.read(pgf.flatten(distances))
    assert len(pdists) == 16
Exemple #3
0

pt = pgf.var_vec3((0., 0., 0.))
norm = pgf.var_vec3((0., 0., 1.))
plane = pgf.plane(pt, norm)
minpt = pgf.var_vec3((-.5, -.5, 0.))
maxpt = pgf.var_vec3((.5, .5, 0.))
box2 = pgf.box2(pgf.var_vec2((-.5, -.5)), pgf.var_vec2((.5, .5)))
box3 = pgf.box3(minpt, maxpt)
npts = pgv.slideri32("Point count", 5, 50, 25)
cloud = pgf.randomPointsInBox(box3, npts)

edgeLen = pgf.var_float(.01)
rect = pgf.rectangleMesh(plane, box2, edgeLen)

distances = pgf.distance(pgf.graft(pgf.vertices(rect)), cloud)
sortedDists = pgf.sort(distances, distances)
maxDist = pgf.listItem(sortedDists, pgf.sub(pgf.listLength(sortedDists), pgf.var_int(1)))

scheme = pgf.var_vec3([
    (0., 0., 1.),
    (0., 1., 0.),
    (1., 1., 0.),
    (1., 0., 0.)
])
colors = pgf.mapValueToColor(maxDist, pgf.var_vec2((.5, 1.2)), scheme)
colored = pgf.meshWithVertexColors(rect, colors)

circ, *_ = pgf.boundingCircle(cloud)

# pgv.show("rectangle", rect)