<commit_before>/**
 * @file Surface
 * @author <NAME> <<EMAIL>>
 * @private
 */


import { Vector3, Box3, Geometry, BufferGeometry, Group, Color } from "../../lib/three.es6.js";

import { Debug, Log, ColormakerRegistry } from "../globals.js";
import { AtomPicker, SurfacePicker } from "../utils/picker.js";
import { uniformArray, uniformArray3, serialArray } from "../math/array-utils.js";
import Selection from "../selection.js";


/**
 * Surface
 * @class
 * @param {String} name - surface name
 * @param {String} path - source path
 * @param {Object} data - surface data
 * @param {Float32Array} data.position - surface positions
 * @param {Int32Array} data.index - surface indices
 * @param {Float32Array} data.normal - surface normals
 * @param {Float32Array} data.color - surface colors
 * @param {Int32Array} data.atomindex - atom indices
 * @param {boolean} data.contour - contour mode flag
 */
function Surface( name, path, data ){

    this.name = name;
    this.path = path;
    this.info = {};

    this.center = new Vector3();
    this.boundingBox = new Box3();

    if( data instanceof Geometry ||
        data instanceof BufferGeometry ||
        data instanceof Group
    ){

        // to be removed
        this.fromGeometry( data );

    }else if( data ){

        this.set(
            data.position,
            data.index,
            data.normal,
            data.color,
            data.atomindex,
            data.contour
        );

    }

}

Surface.prototype = {

    constructor: Surface,
    type: "Surface",

    /**
     * set surface data
     * @param {Float32Array} position - surface positions
     * @param {Int32Array} index - surface indices
     * @param {Float32Array} normal - surface normals
     * @param {Float32Array} color - surface colors
     * @param {Int32Array} atomindex - atom indices
     * @param {boolean} contour - contour mode flag
     * @return {undefined}
     */
    set: function( position, index, normal, color, atomindex, contour ){

        this.position = position;
        this.index = index;
        this.normal = normal;
        this.color = color;
        this.atomindex = atomindex;

        this.size = position.length / 3;
        this.contour = contour;

    },

    fromGeometry: function( geometry ){

        if( Debug ) Log.time( "GeometrySurface.fromGeometry" );

        var geo;

        if( geometry instanceof Geometry ){
            geometry.computeVertexNormals( true );
            geo = new BufferGeometry().fromGeometry( geometry );
        }else if( geometry instanceof BufferGeometry ){
            geo = geometry;
        }else{
            geo = geometry[ 0 ];
        }

        if( !geo.boundingBox ) geo.computeBoundingBox();

        this.center.copy( geo.boundingBox.center() );
        this.boundingBox.copy( geo.boundingBox );

        var position, color, index, normal;

        if( geo instanceof BufferGeometry ){

            var attr = geo.attributes;
            var an = attr.normal ? attr.normal.array : false;

            // assume there are no normals if the first is zero<commit_msg>added missing box and center calculation to surface class<commit_after>/**
 * @file Surface
 * @author <NAME> <<EMAIL>>
 * @private
 */


import { Vector3, Box3, Geometry, BufferGeometry, Group, Color } from "../../lib/three.es6.js";

import { Debug, Log, ColormakerRegistry } from "../globals.js";
import { AtomPicker, SurfacePicker } from "../utils/picker.js";
import { uniformArray, uniformArray3, serialArray } from "../math/array-utils.js";
import Selection from "../selection.js";


/**
 * Surface
 * @class
 * @param {String} name - surface name
 * @param {String} path - source path
 * @param {Object} data - surface data
 * @param {Float32Array} data.position - surface positions
 * @param {Int32Array} data.index - surface indices
 * @param {Float32Array} data.normal - surface normals
 * @param {Float32Array} data.color - surface colors
 * @param {Int32Array} data.atomindex - atom indices
 * @param {boolean} data.contour - contour mode flag
 */
function Surface( name, path, data ){

    this.name = name;
    this.path = path;
    this.info = {};

    this.center = new Vector3();
    this.boundingBox = new Box3();

    if( data instanceof Geometry ||
        data instanceof BufferGeometry ||
        data instanceof Group
    ){

        // to be removed
        this.fromGeometry( data );

    }else if( data ){

        this.set(
            data.position,
            data.index,
            data.normal,
            data.color,
            data.atomindex,
            data.contour
        );

        this.boundingBox.setFromArray( data.position );
        this.boundingBox.center( this.center );

    }

}

Surface.prototype = {

    constructor: Surface,
    type: "Surface",

    /**
     * set surface data
     * @param {Float32Array} position - surface positions
     * @param {Int32Array} index - surface indices
     * @param {Float32Array} normal - surface normals
     * @param {Float32Array} color - surface colors
     * @param {Int32Array} atomindex - atom indices
     * @param {boolean} contour - contour mode flag
     * @return {undefined}
     */
    set: function( position, index, normal, color, atomindex, contour ){

        this.position = position;
        this.index = index;
        this.normal = normal;
        this.color = color;
        this.atomindex = atomindex;

        this.size = position.length / 3;
        this.contour = contour;

    },

    fromGeometry: function( geometry ){

        if( Debug ) Log.time( "GeometrySurface.fromGeometry" );

        var geo;

        if( geometry instanceof Geometry ){
            geometry.computeVertexNormals( true );
            geo = new BufferGeometry().fromGeometry( geometry );
        }else if( geometry instanceof BufferGeometry ){
            geo = geometry;
        }else{
            geo = geometry[ 0 ];
        }

        if( !geo.boundingBox ) geo.computeBoundingBox();

        this.boundingBox.copy( geo.boundingBox );
        this.boundingBox.center( this.center );

        var position, color, index, normal;

        if( geo instanceof BufferGeometry ){

            var attr = geo.attributes;
            var an = attr.normal ? attr.normal.array : false;

            // assume there are no normals if the first is zero
{'fraction_non_alphanumeric': 0.11693230235127032, 'fraction_numerical': 0.008836989111566988, 'mean_word_length': 2.275452196382429, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4190341', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1715, 'n_words': 519}