<commit_before>use gemlab::geometry::is_point_inside_triangle;
use gemlab::util::GridSearchCell;
use gemlab::StrError;
use plotpy::{Canvas, Plot, PolyCode, Text};
use std::fs::File;
use std::io::{BufRead, BufReader};

fn brute_force_search(triangles: &Vec<Vec<Vec<f64>>>, x: &[f64]) -> Option<usize> {
    for i in 0..triangles.len() {
        let t = &triangles[i];
        if is_point_inside_triangle(&t[0], &t[1], &t[2], x) {
            return Some(i);
        }
    }
    None
}

fn main() -> Result<(), StrError> {
    // select mesh for testing
    let num_triangle = 20000;
    let path = format!("data/triangles/example_grid_search_gen_triangles_{}.dat", num_triangle);
    let tris = read_data(path.as_str())?;

    // closure that returns the number of nodes of a cell `t`
    let get_nnode = |_t| Ok(3);

    // closure that returns the coordinates of point `m` of cell `t`
    let get_x = |t: usize, m: usize| Ok(&tris[t][m][..]);

    // allocate grid search tool
    let ndim = 2;
    let grid = GridSearchCell::new(ndim, tris.len(), get_nnode, get_x, None, None)?;
<commit_msg>Use smaller mesh in example<commit_after>use gemlab::geometry::is_point_inside_triangle;
use gemlab::util::GridSearchCell;
use gemlab::StrError;
use plotpy::{Canvas, Plot, PolyCode, Text};
use std::fs::File;
use std::io::{BufRead, BufReader};

fn brute_force_search(triangles: &Vec<Vec<Vec<f64>>>, x: &[f64]) -> Option<usize> {
    for i in 0..triangles.len() {
        let t = &triangles[i];
        if is_point_inside_triangle(&t[0], &t[1], &t[2], x) {
            return Some(i);
        }
    }
    None
}

fn main() -> Result<(), StrError> {
    // select mesh for testing
    let num_triangle = 200;
    let path = format!("data/triangles/example_grid_search_gen_triangles_{}.dat", num_triangle);
    let tris = read_data(path.as_str())?;

    // closure that returns the number of nodes of a cell `t`
    let get_nnode = |_t| Ok(3);

    // closure that returns the coordinates of point `m` of cell `t`
    let get_x = |t: usize, m: usize| Ok(&tris[t][m][..]);

    // allocate grid search tool
    let ndim = 2;
    let grid = GridSearchCell::new(ndim, tris.len(), get_nnode, get_x, None, None)?;

{'fraction_non_alphanumeric': 0.1610555050045496, 'fraction_numerical': 0.012738853503184714, 'mean_word_length': 3.515400410677618, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 17, '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': '4246608', 'n_tokens_mistral': 809, 'n_tokens_neox': 785, 'n_words': 210}