<commit_before><commit_msg>Eraser tool<commit_after>/* eslint class-methods-use-this: 0 */
/* eslint no-underscore-dangle: 0 */
import external from './../externalModules.js';
import baseTool from './../base/baseTool.js';
import {
  getToolState,
  removeToolState
} from './../stateManagement/toolState.js';
import { state } from './../store/index.js';

const cornerstone = external.cornerstone;

export default class extends baseTool {
  constructor (name = 'eraser') {
    super({
      name,
      supportedInteractionTypes: ['mouse', 'touch']
    });

    this.preMouseDownCallback = this._deleteAllNearbyTools.bind(this);
    this.preTouchStartCallback = this._deleteAllNearbyTools.bind(this);
  }

  _deleteAllNearbyTools (evt) {
    const coords = evt.detail.currentPoints.canvas;
    const element = evt.detail.element;

    state.tools.forEach(function (tool) {
      const toolState = getToolState(element, tool.name);

      if (toolState) {
        // Modifying in a foreach? Probably not ideal
        toolState.data.forEach(function (data) {
          if (
            typeof tool.pointNearTool === 'function' &&
            tool.pointNearTool(element, data, coords)
          ) {
            removeToolState(element, tool.name, data);
            cornerstone.updateImage(element);
          }
        });
      }
    });

    const consumeEvent = true;

    return consumeEvent;
  }
}
{'fraction_non_alphanumeric': 0.12785714285714286, 'fraction_numerical': 0.0014285714285714286, 'mean_word_length': 2.7661290322580645, 'pattern_counts': {'":': 0, '<': 3, '<?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': '4414436', 'n_tokens_mistral': 419, 'n_tokens_neox': 407, 'n_words': 86}