<commit_before>import { AbstractFractal } from '../abstract'

export class TreeFractal extends AbstractFractal {

  constructor ({
    scale,
    epsilon, // TODO: set default to .5 for bifurcation
    offset,
    width,
    height,
    depth
  }) {
    super(...arguments)

    this.points = [{}]
    this.angles = [
      -Math.PI / 4,
      Math.PI / 4
    ]

    this.context.lineWidth = 2
  }

  randomize (delta = 2) {
    this.angles = [
      -Math.PI / delta * Math.random(),
       Math.PI / delta * Math.random()
    ]
  }

  scaleUnit (depth, size) {
    return -size * (1 - this.epsilon)
  }

  // moveUnit (depth, size, angle) {
  //   this.context.moveTo(0, 0)
  //   this.context.lineTo(0, -size / 2)
  // }

  renderUnit (depth, size, angle) {
    this.context.save();
    this.context.rotate(angle);
    this.context.beginPath();
    this.context.moveTo(0, 0);
    this.context.lineTo(0, -size / 2)

    this.context.stroke()
    this.context.translate(0, this.scaleUnit(depth, size))

    console.log('\n4. drawing tree (depth, size, angle, translation)', depth, size, angle, this.scaleUnit(depth, size), this.context)

    if (depth === 0) {
      console.log('--- depth is 0')
      // done. draw branches.
      this.drawBranch(depth, size * this.epsilon, this.angles[0])
      this.drawBranch(depth, size * this.epsilon, this.angles[1])
    } else {
      console.log('--- depth > 0', depth)
      // more. draw two mini trees instead of branches.
      // this.drawUnit(depth - 1, size * this.epsilon, this.angles[0]) // FIXME: context is messed up, something along the way
      // this.drawUnit(depth - 1, size * this.epsilon, this.angles[1])

      this.renderUnit(depth - 1, size * this.epsilon, this.angles[0]) // so close... but shit
      this.renderUnit(depth - 1, size * this.epsilon, this.angles[1])
    }

    this.exitUnit()
  }

  drawBranch (depth, size, angle) {
    // this.setupUnit()
    // this.directUnit()
    // this.context.moveTo(0, 0)
    // this.context.lineTo(0, -size)
    // this.context.stroke()
    // this.exitUnit()
 
    console.log('drawing branch (size, angle): ', size, angle)
    this.context.save();
    this.context.rotate(angle);
    this.context.beginPath();
    console.log('branch position lineto', -size)
    this.context.moveTo(0, 0);
    this.context.lineTo(0, -size);
    this.context.stroke();
    this.context.restore();
    console.log('done with branch')
  }

  draw () { // TODO: make this redundant
    this.clear()
    this.translate(0.5, 0.9)<commit_msg>:sparkles: work towards tree cleanup<commit_after>import { AbstractFractal } from '../abstract'

export class TreeFractal extends AbstractFractal {

  constructor ({
    scale,
    epsilon, // TODO: set default to .5 for bifurcation
    offset,
    width,
    height,
    depth
  }) {
    super(...arguments)

    this.points = [{}]
    this.angles = [
      -Math.PI / 4,
      Math.PI / 4
    ]

    this.context.lineWidth = 2
  }

  randomize (delta = 2) {
    this.angles = [
      -Math.PI / delta * Math.random(),
       Math.PI / delta * Math.random()
    ]
  }

  scaleUnit (depth, size) {
    return -size * (1 - this.epsilon)
  }

  renderUnit (depth, size, angle) {
    this.context.stroke()
    this.context.translate(0, this.scaleUnit(depth, size))

    if (depth === 0) {
      console.log('--- depth is 0')
      // done. draw branches.
      this.drawBranch(depth, size * this.epsilon, this.angles[0])
      this.drawBranch(depth, size * this.epsilon, this.angles[1])
    } else {
      console.log('--- depth > 0', depth)
      // more. draw two mini trees instead of branches.
      this.drawUnit(depth - 1, size * this.epsilon, this.angles[0]) // FIXME: context is messed up, something along the way
      this.drawUnit(depth - 1, size * this.epsilon, this.angles[1])
    }
  }

  drawBranch (depth, size, angle) {
    // this.setupUnit()
    // this.directUnit()
    // this.context.moveTo(0, 0)
    // this.context.lineTo(0, -size)
    // this.context.stroke()
    // this.exitUnit()
 
    console.log('drawing branch (size, angle): ', size, angle)
    this.context.save();
    this.context.rotate(angle);
    this.context.beginPath();
    console.log('branch position lineto', -size)
    this.context.moveTo(0, 0);
    this.context.lineTo(0, -size);
    this.context.stroke();
    this.context.restore();
    console.log('done with branch')
  }

  draw () { // TODO: make this redundant
    this.clear()
    this.translate(0.5, 0.9)
{'fraction_non_alphanumeric': 0.15953654188948307, 'fraction_numerical': 0.014483065953654188, 'mean_word_length': 2.3879245283018866, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '4355053', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1476, 'n_words': 346}