<commit_before>/**
 * @class A scene node that specifies the spatial boundaries of scene graph subtrees to support visibility and
 * level-of-detail culling.
 *
 * <p>The subgraphs of these are only traversed when the boundary intersects the current view frustum. When this node
 * is defined within the subgraph of a {@link SceneJS.Locality} node, then the boundary must also intersect the inner
 * and outer radii of the Locality in order for its sub-nodes to be rendered.</p>
 *
 * <p>When configured with a projected size threshold for each child, a {@link SceneJS.BoundingBox} can also function
 * as level-of-detail (LOD) selectors.</p>
 *
 *  <p><b>Example 1.</b></p><p>This BoundingBox is configured to work as a level-of-detail selector. The 'levels'
 * property specifies thresholds for the boundary's projected size, each corresponding to one of the node's children,
 * such that the child corresponding to the threshold imediately below the boundary's current projected size is the only
 * one that is currently rendered.</p><p>This boundingBox will select exactly one of its child nodes to render for its
 * current projected size, where the levels parameter specifies for each child the size threshold above which the child
 * becomes selected. No child is selected (ie. nothing is rendered) when the projected size is below the lowest level.</p>
 * <pre><code>
 * var bb = new SceneJS.BoundingBox({
 *          xmin: -2,
 *          ymin: -2,
 *          zmin: -2,
 *          xmax:  2,
 *          ymax:  2,
 *          zmax:  2,
 *
 *           // Levels are optional - acts as regular
 *          // frustum-culling bounding box when not specified
 *
 *          levels: [
 *             10,
 *             200,
 *             400,
 *             600
 *         ]
 *     },
 *
 *     // When size > 10px, draw a cube
 *
 *     new SceneJS.Cube(),
 *
 *     // When size > 200px,  draw a low-detail sphere
 *
 *     new SceneJS.Sphere({
 *         radius: 1,
 *         slices:10,
 *         rings:10
 *     }),
 *
 *     // When size > 400px, draw a medium-detail sphere
 *
 *     new SceneJS.Sphere({
 *         radius: 1,
 *         slices:20,
 *         rings:20
 *     }),
 *
 *     // When size > 600px, draw a high-detail sphere
 *
 *     new SceneJS.Sphere({
 *         radius: 1,
 *         slices:120,
 *         rings:120
 *     })
 * )
 * </code></pre>
 * @extends SceneJS.Node
 * @since Version 0.7.4
 * @constructor
 * Creates a new SceneJS.BoundingBox
 * @param {Object} [cfg] Static configuration object
 * @param {double} [cfg.xmin = -1.0] Minimum X-axis extent
 * @param {double} [cfg.ymin = -1.0] Minimum Y-axis extent
 * @param {double} [cfg.zmin = -1.0] Minimum Z-axis extent
 * @param {double} [cfg.xmax = 1.0] Maximum X-axis extent
 * @param {double} [cfg.ymax = 1.0] Maximum Y-axis extent
 * @param {double} [cfg.zmax = 1.0] Maximum Z-axis extent
 * @param {double[]} [cfg.levels] Projected size thresholds for level-of-detail culling
 * @param {...SceneJS.Node} [childNodes] Child nodes
 */
SceneJS.BoundingBox = SceneJS.createNodeType("boundingBox");

// @private
SceneJS.BoundingBox.prototype._init = function(params) {

    /* Local extents
     */
    this._xmin = params.xmin || 0;
    this._ymin = params.ymin || 0;
    this._zmin = params.zmin || 0;
    this._xmax = params.xmax || 0;
    this._ymax = params.ymax || 0;
    this._zmax = params.zmax || 0;

    this._levels = null; // LOD levels
    this._level = -1; // Current LOD level
    this._states = [];
    this._state = SceneJS.BoundingBox.STATE_INITIAL;

    this._localCoords = null;       // Six local-space vertices for memo level 1
    this._modelBox = null;          // Axis-aligned model-space box for memo level 2
    this._viewBox = null;           // Axis-aligned view-space box for memo level 2
    this._canvasBox = null;         // Axis-aligned canvas-space box for memo level 2

    if (params.levels) {
        this._levels = params.levels;
    }

    this._validated = false;        // true when params validated
};

/**
 * State of the BoundingBox when not rendered yet
 */
SceneJS.BoundingBox.STATE_INITIAL = "init";

/**
 * State of the BoundingBox when it is completely outside the outer locality radius,
 * which which may be either that defined explicitly by a higher {@link SceneJS.Locality} node, or the
 * default value (see {@link SceneJS.Locality}). In this state it is therefore also completely
 * outside the inner radius and the view frustum.
 */
SceneJS.BoundingBox.STATE_OUTSIDE_OUTER_LOCALITY = "outside";

/**
 * State of the BoundingBox when it intersects the outer locality radius, but does not
 * intersect the inner radius
 */
SceneJS.BoundingBox.STATE_INTERSECTING_OUTER_LOCALITY = "far";

/**
 * State of the BoundingBox when it intersects the inner locality radius, while therefore also intersecting
 * the outer locality radius
 */
SceneJS.BoundingBox.STATE_INTERSECTING_INNER_LOCALITY = "near";

/**
 * State of the BoundingBox when it is intersecting the view frustum, while therefore also intersecting
 * the inner and outer locality radius
 */
SceneJS.BoundingBox.STATE_INTERSECTING_FRUSTUM = "visible";

// @private
SceneJS.BoundingBox.prototype._changeState = function(newState, params) {
    this._state = newState;
    if (this._listeners["state-changed"]) {
        params = params || {};
        params.oldState = this._state;
        params.newState = newState;
        this._fireEvent("state-changed", params);
    }<commit_msg>Set oldState and newState properly when state-changed is fired.<commit_after>/**
 * @class A scene node that specifies the spatial boundaries of scene graph subtrees to support visibility and
 * level-of-detail culling.
 *
 * <p>The subgraphs of these are only traversed when the boundary intersects the current view frustum. When this node
 * is defined within the subgraph of a {@link SceneJS.Locality} node, then the boundary must also intersect the inner
 * and outer radii of the Locality in order for its sub-nodes to be rendered.</p>
 *
 * <p>When configured with a projected size threshold for each child, a {@link SceneJS.BoundingBox} can also function
 * as level-of-detail (LOD) selectors.</p>
 *
 *  <p><b>Example 1.</b></p><p>This BoundingBox is configured to work as a level-of-detail selector. The 'levels'
 * property specifies thresholds for the boundary's projected size, each corresponding to one of the node's children,
 * such that the child corresponding to the threshold imediately below the boundary's current projected size is the only
 * one that is currently rendered.</p><p>This boundingBox will select exactly one of its child nodes to render for its
 * current projected size, where the levels parameter specifies for each child the size threshold above which the child
 * becomes selected. No child is selected (ie. nothing is rendered) when the projected size is below the lowest level.</p>
 * <pre><code>
 * var bb = new SceneJS.BoundingBox({
 *          xmin: -2,
 *          ymin: -2,
 *          zmin: -2,
 *          xmax:  2,
 *          ymax:  2,
 *          zmax:  2,
 *
 *           // Levels are optional - acts as regular
 *          // frustum-culling bounding box when not specified
 *
 *          levels: [
 *             10,
 *             200,
 *             400,
 *             600
 *         ]
 *     },
 *
 *     // When size > 10px, draw a cube
 *
 *     new SceneJS.Cube(),
 *
 *     // When size > 200px,  draw a low-detail sphere
 *
 *     new SceneJS.Sphere({
 *         radius: 1,
 *         slices:10,
 *         rings:10
 *     }),
 *
 *     // When size > 400px, draw a medium-detail sphere
 *
 *     new SceneJS.Sphere({
 *         radius: 1,
 *         slices:20,
 *         rings:20
 *     }),
 *
 *     // When size > 600px, draw a high-detail sphere
 *
 *     new SceneJS.Sphere({
 *         radius: 1,
 *         slices:120,
 *         rings:120
 *     })
 * )
 * </code></pre>
 * @extends SceneJS.Node
 * @since Version 0.7.4
 * @constructor
 * Creates a new SceneJS.BoundingBox
 * @param {Object} [cfg] Static configuration object
 * @param {double} [cfg.xmin = -1.0] Minimum X-axis extent
 * @param {double} [cfg.ymin = -1.0] Minimum Y-axis extent
 * @param {double} [cfg.zmin = -1.0] Minimum Z-axis extent
 * @param {double} [cfg.xmax = 1.0] Maximum X-axis extent
 * @param {double} [cfg.ymax = 1.0] Maximum Y-axis extent
 * @param {double} [cfg.zmax = 1.0] Maximum Z-axis extent
 * @param {double[]} [cfg.levels] Projected size thresholds for level-of-detail culling
 * @param {...SceneJS.Node} [childNodes] Child nodes
 */
SceneJS.BoundingBox = SceneJS.createNodeType("boundingBox");

// @private
SceneJS.BoundingBox.prototype._init = function(params) {

    /* Local extents
     */
    this._xmin = params.xmin || 0;
    this._ymin = params.ymin || 0;
    this._zmin = params.zmin || 0;
    this._xmax = params.xmax || 0;
    this._ymax = params.ymax || 0;
    this._zmax = params.zmax || 0;

    this._levels = null; // LOD levels
    this._level = -1; // Current LOD level
    this._states = [];
    this._state = SceneJS.BoundingBox.STATE_INITIAL;

    this._localCoords = null;       // Six local-space vertices for memo level 1
    this._modelBox = null;          // Axis-aligned model-space box for memo level 2
    this._viewBox = null;           // Axis-aligned view-space box for memo level 2
    this._canvasBox = null;         // Axis-aligned canvas-space box for memo level 2

    if (params.levels) {
        this._levels = params.levels;
    }

    this._validated = false;        // true when params validated
};

/**
 * State of the BoundingBox when not rendered yet
 */
SceneJS.BoundingBox.STATE_INITIAL = "init";

/**
 * State of the BoundingBox when it is completely outside the outer locality radius,
 * which which may be either that defined explicitly by a higher {@link SceneJS.Locality} node, or the
 * default value (see {@link SceneJS.Locality}). In this state it is therefore also completely
 * outside the inner radius and the view frustum.
 */
SceneJS.BoundingBox.STATE_OUTSIDE_OUTER_LOCALITY = "outside";

/**
 * State of the BoundingBox when it intersects the outer locality radius, but does not
 * intersect the inner radius
 */
SceneJS.BoundingBox.STATE_INTERSECTING_OUTER_LOCALITY = "far";

/**
 * State of the BoundingBox when it intersects the inner locality radius, while therefore also intersecting
 * the outer locality radius
 */
SceneJS.BoundingBox.STATE_INTERSECTING_INNER_LOCALITY = "near";

/**
 * State of the BoundingBox when it is intersecting the view frustum, while therefore also intersecting
 * the inner and outer locality radius
 */
SceneJS.BoundingBox.STATE_INTERSECTING_FRUSTUM = "visible";

// @private
SceneJS.BoundingBox.prototype._changeState = function(newState, params) {
    var oldState = this._state;
    this._state = newState;
    if (this._listeners["state-changed"]) {
        params = params || {};
        params.oldState = oldState;
        params.newState = newState;
        this._fireEvent("state-changed", params);
    }
{'fraction_non_alphanumeric': 0.10760466588299122, 'fraction_numerical': 0.013021068812731712, 'mean_word_length': 2.7402773080825162, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7539856', 'n_tokens_mistral': 3484, 'n_tokens_neox': 3258, 'n_words': 1153}