<commit_before>/** Copyright (C) 2015 Ultimaker - Released under terms of the AGPLv3 License */
#ifndef UTILS_POLYGON_UTILS_H
#define UTILS_POLYGON_UTILS_H

#include "polygon.h"

namespace cura 
{

/*!
 * Result of finding the closest point to a given within a set of polygons, with extra information on where the point is.
 */
struct ClosestPolygonPoint
{
    Point location; //!< Result location
    PolygonRef poly; //!< Polygon in which the result was found
    int pos; //!< Index to the first point in the polygon of the line segment on which the result was found
    ClosestPolygonPoint(Point p, int pos, PolygonRef poly) :  location(p), poly(poly), pos(pos) {};
    ClosestPolygonPoint(int pos, PolygonRef poly) : poly(poly), pos(pos) {};
    ClosestPolygonPoint(PolygonRef poly) : poly(poly), pos(-1) {};
};

/*!
 * A point within a polygon and the index of which segment in the polygon the point lies on.
 */
struct GivenDistPoint
{
    Point location; //!< Result location
    int pos; //!< Index to the first point in the polygon of the line segment on which the result was found
};
    
class PolygonUtils 
{
public:
    //! performs an offset compared to an adjacent inset/outset and also computes the area created by gaps between the two consecutive insets/outsets
    static void offsetExtrusionWidth(Polygons& poly, bool inward, int extrusionWidth, Polygons& result, Polygons* in_between, bool removeOverlappingPerimeters);

    /*!
    * performs an offset compared to an adjacent inset/outset and also computes the area created by gaps between the two consecutive insets/outsets.
    * This function allows for different extrusion widths between the two insets.
    */
    static void offsetSafe(Polygons& poly, int distance, int offset_first_boundary, int extrusion_width, Polygons& result, Polygons* in_between, bool removeOverlappingPerimeters);

    //! performs an offset and makes sure the lines don't overlap (ignores any area between the original poly and the resulting poly)
    static void offsetSafe(Polygons& poly, int distance, int extrusionWidth, Polygons& result, bool removeOverlappingPerimeters);

    //! performs offsets to make sure the lines don't overlap (ignores any area between the original poly and the resulting poly)
    static void removeOverlapping(Polygons& poly, int extrusionWidth, Polygons& result);

    /*!
    * Get a point from the \p poly with a given \p offset.
    * 
    * \param poly The polygon.
    * \param point_idx The index of the point in the polygon.
    * \param offset The distance the point has to be moved outward from the polygon.
    * \return A point at the given distance inward from the point on the boundary polygon.
    */
    static Point getBoundaryPointWithOffset(PolygonRef poly, unsigned int point_idx, int64_t offset);

    /*!
    * Moves the point \p from onto the nearest polygon or leaves the point as-is, when the comb boundary is not within \p distance.
    * Given a \p distance more than zero, the point will end up inside, and conversely outside.
    * When the point is already in/outside by more than \p distance, \p from is unaltered, but the polygon is returned.
    * When the point is in/outside by less than \p distance, \p from is moved to the correct place.
    * 
    * \param polygons The polygons onto which to move the point
    * \param from The point to move.
    * \param distance The distance by which to move the point.
    * \param maxDist2 The squared maximal allowed distance from the point to the nearest polygon.
    * \return The index to the polygon onto which we have moved the point.
    */
    static unsigned int moveInside(Polygons& polygons, Point& from, int distance = 0, int64_t maxDist2 = std::numeric_limits<int64_t>::min());

    /*!
    * Find the two points in two polygons with the smallest distance.
    * <commit_msg>bugfix: moveInside didn't want to move inside by default<commit_after>/** Copyright (C) 2015 Ultimaker - Released under terms of the AGPLv3 License */
#ifndef UTILS_POLYGON_UTILS_H
#define UTILS_POLYGON_UTILS_H

#include "polygon.h"

namespace cura 
{

/*!
 * Result of finding the closest point to a given within a set of polygons, with extra information on where the point is.
 */
struct ClosestPolygonPoint
{
    Point location; //!< Result location
    PolygonRef poly; //!< Polygon in which the result was found
    int pos; //!< Index to the first point in the polygon of the line segment on which the result was found
    ClosestPolygonPoint(Point p, int pos, PolygonRef poly) :  location(p), poly(poly), pos(pos) {};
    ClosestPolygonPoint(int pos, PolygonRef poly) : poly(poly), pos(pos) {};
    ClosestPolygonPoint(PolygonRef poly) : poly(poly), pos(-1) {};
};

/*!
 * A point within a polygon and the index of which segment in the polygon the point lies on.
 */
struct GivenDistPoint
{
    Point location; //!< Result location
    int pos; //!< Index to the first point in the polygon of the line segment on which the result was found
};
    
class PolygonUtils 
{
public:
    //! performs an offset compared to an adjacent inset/outset and also computes the area created by gaps between the two consecutive insets/outsets
    static void offsetExtrusionWidth(Polygons& poly, bool inward, int extrusionWidth, Polygons& result, Polygons* in_between, bool removeOverlappingPerimeters);

    /*!
    * performs an offset compared to an adjacent inset/outset and also computes the area created by gaps between the two consecutive insets/outsets.
    * This function allows for different extrusion widths between the two insets.
    */
    static void offsetSafe(Polygons& poly, int distance, int offset_first_boundary, int extrusion_width, Polygons& result, Polygons* in_between, bool removeOverlappingPerimeters);

    //! performs an offset and makes sure the lines don't overlap (ignores any area between the original poly and the resulting poly)
    static void offsetSafe(Polygons& poly, int distance, int extrusionWidth, Polygons& result, bool removeOverlappingPerimeters);

    //! performs offsets to make sure the lines don't overlap (ignores any area between the original poly and the resulting poly)
    static void removeOverlapping(Polygons& poly, int extrusionWidth, Polygons& result);

    /*!
    * Get a point from the \p poly with a given \p offset.
    * 
    * \param poly The polygon.
    * \param point_idx The index of the point in the polygon.
    * \param offset The distance the point has to be moved outward from the polygon.
    * \return A point at the given distance inward from the point on the boundary polygon.
    */
    static Point getBoundaryPointWithOffset(PolygonRef poly, unsigned int point_idx, int64_t offset);

    /*!
    * Moves the point \p from onto the nearest polygon or leaves the point as-is, when the comb boundary is not within \p distance.
    * Given a \p distance more than zero, the point will end up inside, and conversely outside.
    * When the point is already in/outside by more than \p distance, \p from is unaltered, but the polygon is returned.
    * When the point is in/outside by less than \p distance, \p from is moved to the correct place.
    * 
    * \param polygons The polygons onto which to move the point
    * \param from The point to move.
    * \param distance The distance by which to move the point.
    * \param maxDist2 The squared maximal allowed distance from the point to the nearest polygon.
    * \return The index to the polygon onto which we have moved the point.
    */
    static unsigned int moveInside(Polygons& polygons, Point& from, int distance = 0, int64_t maxDist2 = std::numeric_limits<int64_t>::max());

    /*!
    * Find the two points in two polygons with the smallest distance.
    * 
{'fraction_non_alphanumeric': 0.06941039865823764, 'fraction_numerical': 0.003870468326667527, 'mean_word_length': 3.606060606060606, 'pattern_counts': {'":': 0, '<': 15, '<?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': '324027', 'n_tokens_mistral': 2198, 'n_tokens_neox': 2077, 'n_words': 1018}