LinearXform.g

LinearXform.g — performs linear transformation functions on points.

Code

[Note]

The code for this and other example scripts can be found in the DataHub distribution archive, typically at this location:

C:\Program Files\Cogent\Cogent DataHub\scripts\

Please refer to Section 3.1, “How to Run a Script” for more information on using scripts.

/* This script creates a class that performs linear
   transformation functions on DataHub points. */
class LinearXform
{
    verbose;
}
method LinearXform.cbLinearXform (dst, value, mult, add)
{
    if (.verbose)
        princ ("xform ", dst, " = ", value, " * ", mult, 
               " + ", add, "\n");
    if (number_p(value))
        set (dst, value * mult + add);
    else
        set (dst, value);
}
method LinearXform.AddLinearXform (app, src, dst, mult, add, 
                                   bidirectional_p?=nil)
{
    datahub_command (string ("(create \"", src, "\" 1)"));
    datahub_command (string ("(create \"", dst, "\" 1)"));
    app.OnChange (src, `(@self).cbLinearXform (#@dst, value, 
                                               @mult, @add));
    if (bidirectional_p && mult != 0)
    {
        allow_self_reference (src, 1);
        allow_self_reference (dst, 1);
        app.OnChange (dst, `(@self).cbLinearXform (#@src, value, 
                                                   @(1/mult), 
                                                   @(-add/mult)));
    }
}