// SPDX-License-Identifier: MIT
// Copyright (c) 2026 Incoprea
// Estimate area under a profile
// Not compiled or tested in-world
// Setup: Put in a spare prim you own. Touch to integrate height(x) = x squared on zero through three using twelve slices.
// Stop / restore: Disable or remove the script. It only reports to its owner and does not change prim properties. Reset clears its temporary state.
// Notes: The exact result here is nine. More slices reduce this smooth example’s error but increase work; it is a numerical estimate.
// License: see LICENSE in this distribution.
// Original Incoprea example. MIT. Owner-only calculation; no scene changes.
float height(float x)
{
    return x*x;
}
default
{
    touch_start(integer detectedCount)
    {
        if (llDetectedKey(0) != llGetOwner()) return;
        float left=0.0;
        float right=3.0;
        integer slices=12;
        float width=(right-left)/(float)slices;
        float sum=0.5*(height(left)+height(right));
        integer i;
        for (i=1; i<slices; ++i) sum+=height(left+width*(float)i);
        llOwnerSay("Estimated area="+(string)(sum*width)+"; exact example area=9.");
    }
    changed(integer change)
    {
        if (change & CHANGED_OWNER) llResetScript();
    }
}
