<commit_before>import * as turf from "@turf/turf";

import {Fix} from "../../read-flight";
import Task from "../task";
import AreaShape from "../shapes/area";

const convexHull = require('convex-hull');

export default class AreaTaskSolver {
  task: Task;

  private _lastFix: Fix | undefined = undefined;
  private _areas: Array<Fix[]> = [];

  constructor(task: Task) {
    this.task = task;

    for (let i = 1; i < this.task.points.length - 1; i++) {
      this._areas[i] = [];
    }
  }

  consume(fixes: Fix[]) {
    fixes.forEach(fix => this.update(fix));
  }

  update(fix: Fix) {
    if (this._lastFix) {
      this._update(fix, this._lastFix);
    }
    this._lastFix = fix;
  }

  _update(fix: Fix, lastFix: Fix) {
    for (let i = 1; i < this.task.points.length - 1; i++) {
      let tp = this.task.points[i];
      if (tp.shape instanceof AreaShape && tp.shape.isInside(fix.coordinate)) {
        this._areas[i].push(fix);
      }
    }
  }

  get thinnedAreas(): Array<Fix[]> {
    return this._areas.map(fixes => {
      let coords = fixes.map(fix => fix.coordinate);
      let hull = convexHull(coords);<commit_msg>AreaTaskSolver: Include intersection points in areas<commit_after>import * as turf from "@turf/turf";

import {Fix} from "../../read-flight";
import Task from "../task";
import AreaShape from "../shapes/area";
import {interpolateFix} from "../../utils/interpolate-fix";

const convexHull = require('convex-hull');

export default class AreaTaskSolver {
  task: Task;

  private _lastFix: Fix | undefined = undefined;
  private _areas: Array<Fix[]> = [];

  constructor(task: Task) {
    this.task = task;

    for (let i = 1; i < this.task.points.length - 1; i++) {
      this._areas[i] = [];
    }
  }

  consume(fixes: Fix[]) {
    fixes.forEach(fix => this.update(fix));
  }

  update(fix: Fix) {
    if (this._lastFix) {
      this._update(fix, this._lastFix);
    }
    this._lastFix = fix;
  }

  _update(fix: Fix, lastFix: Fix) {
    for (let i = 1; i < this.task.points.length - 1; i++) {
      let tp = this.task.points[i];
      if (tp.shape instanceof AreaShape) {
        if (tp.shape.isInside(fix.coordinate)) {
          this._areas[i].push(fix);
        }

        let intersections = tp.shape.findIntersections(lastFix.coordinate, fix.coordinate);
        this._areas[i].push(...intersections.map(fraction => interpolateFix(lastFix, fix, fraction)));
      }
    }
  }

  get thinnedAreas(): Array<Fix[]> {
    return this._areas.map(fixes => {
      let coords = fixes.map(fix => fix.coordinate);
      let hull = convexHull(coords);
{'fraction_non_alphanumeric': 0.1666020922123208, 'fraction_numerical': 0.0030995738086013174, 'mean_word_length': 2.813884785819793, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 14, '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': '7040944', 'n_tokens_mistral': 925, 'n_tokens_neox': 882, 'n_words': 201}