Example #1
0
/**
 * This test constructs a two sets of variables related to each
 * other by a simple linear transformation (scale and offset). The
 * time is measured to change a variable on either side of the
 * mapping and to change the scale and offset factors.
 */
function projectionTest($n)
{
    global $planner;
    $planner = new Planner();
    $scale = new Variable("scale", 10);
    $offset = new Variable("offset", 1000);
    $src = null;
    $dst = null;
    $dests = new OrderedCollection();
    for ($i = 0; $i < $n; $i++) {
        $src = new Variable("src{$i}", $i);
        $dst = new Variable("dst{$i}", $i);
        $dests->add($dst);
        new StayConstraint($src, Strength::Normal());
        new ScaleConstraint($src, $scale, $offset, $dst, Strength::Required());
    }
    change($src, 17);
    if ($dst->value != 1170) {
        alert("Projection 1 failed");
    }
    change($dst, 1050);
    if ($src->value != 5) {
        alert("Projection 2 failed");
    }
    change($scale, 5);
    for ($i = 0; $i < $n - 1; $i++) {
        if ($dests->at($i)->value != $i * 5 + 1000) {
            alert("Projection 3 failed");
        }
    }
    change($offset, 2000);
    for ($i = 0; $i < $n - 1; $i++) {
        if ($dests->at($i)->value != $i * 5 + 2000) {
            alert("Projection 4 failed");
        }
    }
}
Example #2
0
function projectionTest($n)
{
    global $planner;
    $planner = new Planner();
    $scale = new Variable("scale", 10);
    $offset = new Variable("offset", 1000);
    $src = null;
    $dst = null;
    $dests = new OrderedCollection();
    for ($i = 0; $i < $n; ++$i) {
        $src = new Variable("src" . $i, $i);
        $dst = new Variable("dst" . $i, $i);
        $dests->add($dst);
        new StayConstraint($src, $GLOBALS['NORMAL']);
        new ScaleConstraint($src, $scale, $offset, $dst, $GLOBALS['REQUIRED']);
    }
    change($src, 17);
    if ($dst->value != 1170) {
        echo "Projection test 1 failed!";
    }
    change($dst, 1050);
    if ($src->value != 5) {
        echo "Projection test 2 failed!";
    }
    change($scale, 5);
    for ($i = 0; $i < $n - 1; ++$i) {
        if ($dests->at($i)->value != $i * 5 + 1000) {
            echo "Projection test 3 failed!";
        }
    }
    change($offset, 2000);
    for ($i = 0; $i < $n - 1; ++$i) {
        if ($dests->at($i)->value != $i * 5 + 2000) {
            echo "Projection test 4 failed!";
        }
    }
}