<commit_before>//Copyright (c) 2021 <NAME>.V.
//CuraEngine is released under the terms of the AGPLv3 or higher.

#ifndef LIGHTNING_LAYER_H
#define LIGHTNING_LAYER_H

#include "../utils/polygonUtils.h"
#include "../utils/SquareGrid.h"

#include <memory>
#include <vector>
#include <list>
#include <unordered_map>

namespace cura
{
class LightningTreeNode;

class LightningDistanceField
{
public:
    /*!
     * constructor
     */
    LightningDistanceField
    (
        const coord_t& radius,
     const Polygons& current_outline,
     const Polygons& current_overhang,
     const std::vector<std::shared_ptr<LightningTreeNode>>& initial_trees
    );
    
    /*!
     * Gets the next unsupported location to be supported by a new branch.
     *
     * Returns false if there are no more points to consider
     */
    bool tryGetNextPoint(Point* p) const;

    /*! update the distance field with a newly added branch
     * TODO: check whether this explanation is correct
     */
    void update(const Point& to_node, const Point& added_leaf);

    Point getNearbyUnsupportedPoint(const Point p, const Point fall_back, coord_t supporting_radius, coord_t total_radius) const;
protected:
    using GridPoint = SquareGrid::GridPoint;
    coord_t cell_size;
    SquareGrid grid;
    coord_t supporting_radius; //!< The radius of the area of the layer above supported by a point on a branch of a tree
    
    
    const Polygons& current_outline;
    const Polygons& current_overhang;
    
    
    struct UnsupCell
    {
        UnsupCell(SquareGrid::GridPoint loc, coord_t dist_to_boundary)
        : loc(loc)
        , dist_to_boundary(dist_to_boundary)
        {}
        Point loc;
        coord_t dist_to_boundary;
    };
    std::list<UnsupCell> unsupported_points;
    std::unordered_map<SquareGrid::GridPoint, std::list<UnsupCell>::iterator> unsupported_points_grid;
};<commit_msg>lil doc<commit_after>//Copyright (c) 2021 <NAME>.V.
//CuraEngine is released under the terms of the AGPLv3 or higher.

#ifndef LIGHTNING_LAYER_H
#define LIGHTNING_LAYER_H

#include "../utils/polygonUtils.h"
#include "../utils/SquareGrid.h"

#include <memory>
#include <vector>
#include <list>
#include <unordered_map>

namespace cura
{
class LightningTreeNode;

class LightningDistanceField
{
public:
    /*!
     * constructor
     */
    LightningDistanceField
    (
        const coord_t& radius,
     const Polygons& current_outline,
     const Polygons& current_overhang,
     const std::vector<std::shared_ptr<LightningTreeNode>>& initial_trees
    );
    
    /*!
     * Gets the next unsupported location to be supported by a new branch.
     *
     * Returns false if there are no more points to consider
     */
    bool tryGetNextPoint(Point* p) const;

    /*! update the distance field with a newly added branch
     * TODO: check whether this explanation is correct
     */
    void update(const Point& to_node, const Point& added_leaf);

    /*!
     * Get a new unsupported point, close the already known \p fall_back, which is also close to the nearby tree branch location \p p.
     * 
     * Gets a random point on the boundary of the unsupported cells near \p fall_back,
     * and takes an offset to as far away as \p total_radius,
     * and returns the cell point at that location.
     *    .  .  .  .  .     . = unsupported cell point
     *    .  .  o  .  .     o = offsetted point at total radius; the returned point.
     *    .  .  .  .  .
     *    .  .  .  .  .
     *    .  r  .  .  .     r = random point at the boundary of the unsupported, but close enough to f as \p supporting_radius.
     *          .  .  .
     *             f        f = \p fall_back.
     *    p                 p = \p p.
     * 
     * If nothing is found, return \p fall_back instead.
     */
    Point getNearbyUnsupportedPoint(const Point p, const Point fall_back, coord_t supporting_radius, coord_t total_radius) const;
protected:
    using GridPoint = SquareGrid::GridPoint;
    coord_t cell_size;
    SquareGrid grid;
    coord_t supporting_radius; //!< The radius of the area of the layer above supported by a point on a branch of a tree
    
    
    const Polygons& current_outline;
    const Polygons& current_overhang;
    
    
    struct UnsupCell
    {
        UnsupCell(SquareGrid::GridPoint loc, coord_t dist_to_boundary)
        : loc(loc)
        , dist_to_boundary(dist_to_boundary)
        {}
        Point loc;
        coord_t dist_to_boundary;
    };
    std::list<UnsupCell> unsupported_points;
    std::unordered_map<SquareGrid::GridPoint, std::list<UnsupCell>::iterator> unsupported_points_grid;
};
{'fraction_non_alphanumeric': 0.08486685429746699, 'fraction_numerical': 0.002164970772894566, 'mean_word_length': 2.6900958466453675, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 23, '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': '3598522', 'n_tokens_mistral': 1431, 'n_tokens_neox': 1398, 'n_words': 434}