<commit_before>/* Copyright 2015 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

const d3 = require('d3');
const register = require('register');
const ModuleInterface = require('lib/module_interface');
const globalWallGeometry = require('globalWallGeometry');
const wallGeometry = require('wallGeometry');
const network = require('network');

const ForecastGrid = require('demo_modules/wind/forecast_grid');
const VectorField = require('demo_modules/wind/vector_field');
const ParticleField = require('demo_modules/wind/particle_field');

const ROTATEX = 100;
const ROTATEY = -400;

function loadJson(file) {
  return new Promise((resolve, reject) => {
    const asset = require('client/asset/asset');
    d3.json(asset(file))
      .get((err, data) => {
        if (err) {
          return reject(err);
        } else {
          return resolve(data);
        }
      });
  });
}

function ensureNumber(num, fallback) {
  return _.isFinite(num) || num === Infinity || num === -Infinity ? num : fallback;
}

/**
 * @param bounds the projection bounds: [[x0, y0], [x1, y1]]
 * @param width
 * @param height
 * @returns {Object} the projection bounds clamped to the specified view.
 */
function clampedBounds(bounds, width, height) {
  const upperLeft = bounds[0];
  const lowerRight = bounds[1];
  const x = Math.max(Math.floor(ensureNumber(upperLeft[0], 0)), 0);
  const y = Math.max(Math.floor(ensureNumber(upperLeft[1], 0)), 0);
  const xMax = Math.min(Math.ceil(ensureNumber(lowerRight[0], width)), width - 1);
  const yMax = Math.min(Math.ceil(ensureNumber(lowerRight[1], height)), height - 1);
  return {x: x, y: y, xMax: xMax, yMax: yMax, width: xMax - x + 1, height: yMax - y + 1};
}

class WindServer extends ModuleInterface.Server {
  willBeShownSoon(container, deadline) {
    return Promise.resolve();
  }
}

class WindClient extends ModuleInterface.Client {
  finishFadeOut() {
    this.mapSurface.destroy();
    this.overlaySurface.destroy();
    this.animationSurface.destroy();
  }

  willBeShownSoon(container, deadline) {
    const CanvasSurface = require('client/surface/canvas_surface');
    this.mapSurface = new CanvasSurface(container, wallGeometry);<commit_msg>Use short form for object literal.<commit_after>/* Copyright 2015 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

const d3 = require('d3');
const register = require('register');
const ModuleInterface = require('lib/module_interface');
const globalWallGeometry = require('globalWallGeometry');
const wallGeometry = require('wallGeometry');
const network = require('network');

const ForecastGrid = require('demo_modules/wind/forecast_grid');
const VectorField = require('demo_modules/wind/vector_field');
const ParticleField = require('demo_modules/wind/particle_field');

const ROTATEX = 100;
const ROTATEY = -400;

function loadJson(file) {
  return new Promise((resolve, reject) => {
    const asset = require('client/asset/asset');
    d3.json(asset(file))
      .get((err, data) => {
        if (err) {
          return reject(err);
        } else {
          return resolve(data);
        }
      });
  });
}

function ensureNumber(num, fallback) {
  return _.isFinite(num) || num === Infinity || num === -Infinity ? num : fallback;
}

/**
 * @param bounds the projection bounds: [[x0, y0], [x1, y1]]
 * @param width
 * @param height
 * @returns {Object} the projection bounds clamped to the specified view.
 */
function clampedBounds(bounds, width, height) {
  const upperLeft = bounds[0];
  const lowerRight = bounds[1];
  const x = Math.max(Math.floor(ensureNumber(upperLeft[0], 0)), 0);
  const y = Math.max(Math.floor(ensureNumber(upperLeft[1], 0)), 0);
  const xMax = Math.min(Math.ceil(ensureNumber(lowerRight[0], width)), width - 1);
  const yMax = Math.min(Math.ceil(ensureNumber(lowerRight[1], height)), height - 1);
  return {x, y, xMax, yMax, width: xMax - x + 1, height: yMax - y + 1};
}

class WindServer extends ModuleInterface.Server {
  willBeShownSoon(container, deadline) {
    return Promise.resolve();
  }
}

class WindClient extends ModuleInterface.Client {
  finishFadeOut() {
    this.mapSurface.destroy();
    this.overlaySurface.destroy();
    this.animationSurface.destroy();
  }

  willBeShownSoon(container, deadline) {
    const CanvasSurface = require('client/surface/canvas_surface');
    this.mapSurface = new CanvasSurface(container, wallGeometry);
{'fraction_non_alphanumeric': 0.14923492349234924, 'fraction_numerical': 0.012601260126012601, 'mean_word_length': 4.4955489614243325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5597626', 'n_tokens_mistral': 1626, 'n_tokens_neox': 1563, 'n_words': 492}