<commit_before>import Vector3 from "../math/Vector3.js";

export default class Particle {
  constructor({x = 0, y = 0, z = 0, life = Infinity} = {}) {
    this.position = new Vector3();
    this.velocity = new Vector3();
    this.reset({x, y, z, life});
    return this;
  }

  set ({x = this.x, y = this.y, z = this.z, life = this.life} = {}) {
    this.position.set(x, y, z);
    this.life = life;
    return this;
  }

  reset ({x, y, z, life} = {}) {
    this.set({x, y, z, life});
    this.currentLife = this.life;
    this.dead = false;
    return this;
  }

  copy (particle) {
    this.position.copy(particle.position);
    this.velocity.copy(particle.velocity);
    this.life = particle.life;
    this.currentLife = particle.currentLife;
    this.dead = particle.dead;
  }

  update () {
    if (this.dead) {
      return this;
    }
    this.position.add(this.velocity);
    this.currentLife--;
    if(this.currentLife < 1) {
      this.dead = true;
    }
    return this;
  }<commit_msg>update Particle to allow 2D and 3D<commit_after>import Vector2 from "../math/Vector2.js";
import Vector3 from "../math/Vector3.js";

export default class Particle {
  constructor(position = new Vector3(), {life = Infinity} = {}) {
    this.position = position;
    this.velocity = this.position instanceof Vector2 ? new Vector2() : new Vector3();
    this.life = life;
    this.reset();
    return this;
  }

  get x() {
    return this.position.x;
  }

  set x(value) {
    this.position.x = value;
  }

  get y() {
    return this.position.y;
  }

  set y(value) {
    this.position.y = value;
  }

  get z() {
    return this.position.z;
  }

  set z(value) {
    this.position.z = value;
  }

  set({position = this.position, life = this.life} = {}) {
    this.position.copy(position);
    this.life = life;
    return this;
  }

  reset({position, life} = {}) {
    this.set({
      position,
      life
    });
    this.currentLife = this.life;
    this.dead = false;
    return this;
  }

  copy(particle) {
    this.position.copy(particle.position);
    this.velocity.copy(particle.velocity);
    this.life = particle.life;
    this.currentLife = particle.currentLife;
    this.dead = particle.dead;
  }

  update() {
    if (this.dead) {
      return this;
    }
    this.position.add(this.velocity);
    this.currentLife--;
    if (this.currentLife < 1) {
      this.dead = true;
    }
    return this;
  }
{'fraction_non_alphanumeric': 0.15410107705053852, 'fraction_numerical': 0.007870753935376968, 'mean_word_length': 2.406205923836389, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '4781344', 'n_tokens_mistral': 860, 'n_tokens_neox': 829, 'n_words': 187}