<commit_before>#pragma once

#include "Shape.hpp"
#include "Point.hpp"

namespace Geometry2d {
class Segment;

/// Represents a rectangle by storing two opposite corners.  They may be upper-
/// left and lower-right or any other pair of diagonal corners.
class Rect : public Shape {
private:
    int CohenSutherlandOutCode(const Point& other) const;
public:
    Rect() {}

    Rect(Point p1) { pt[0] = pt[1] = p1; }

    Rect(Point p1, Point p2) {
        pt[0] = p1;
        pt[1] = p2;
    }

    Rect(const Rect& other) {
        pt[0] = other.pt[0];
        pt[1] = other.pt[1];
    }

    Shape* clone() const override;

    Rect& operator+=(Point offset) {
        pt[0] += offset;
        pt[1] += offset;

        return *this;
    }

    Rect& operator-=(Point offset) {
        pt[0] -= offset;
        pt[1] -= offset;

        return *this;
    }

    Rect operator+(Point offset) {
        return Rect(pt[0] + offset, pt[1] + offset);
    }

    Rect operator*(float s) { return Rect(pt[0] * s, pt[1] * s); }

    Rect& operator*=(float s) {
        pt[0] *= s;
        pt[1] *= s;

        return *this;
    }

    bool containsRect(const Rect& other) const;

    bool containsPoint(Point other) const override;

    bool hit(Point pt) const override;

    bool hit(const Segment& seg) const override;

    Point center() const { return (pt[0] + pt[1]) / 2; }

    /*
    * The expand function will make the rectangle larger to include
    * the given point (just large enough)
    */
    void expand(Point pt);
    
    /*
    * The expand function will make the rectangle larger to include
    * the given rectangle (just large enough)
    */
    void expand(const Rect& rect);

    /*
    * Makes the rectangle bigger in all direction by the padding amount
    * especially useful around the goalboxes to movement
    */
    void pad(float padding);

    float minx() const { return std::min(pt[0].x(), pt[1].x()); }
    float miny() const { return std::min(pt[0].y(), pt[1].y()); }
    float maxx() const { return std::max(pt[0].x(), pt[1].x()); }
    float maxy() const { return std::max(pt[0].y(), pt[1].y()); }
<commit_msg>Added comments on the Rect hpp for pad and expand<commit_after>#pragma once

#include "Shape.hpp"
#include "Point.hpp"

namespace Geometry2d {
class Segment;

/// Represents a rectangle by storing two opposite corners.  They may be upper-
/// left and lower-right or any other pair of diagonal corners.
class Rect : public Shape {
private:
    int CohenSutherlandOutCode(const Point& other) const;
public:
    Rect() {}

    Rect(Point p1) { pt[0] = pt[1] = p1; }

    Rect(Point p1, Point p2) {
        pt[0] = p1;
        pt[1] = p2;
    }

    Rect(const Rect& other) {
        pt[0] = other.pt[0];
        pt[1] = other.pt[1];
    }

    Shape* clone() const override;

    Rect& operator+=(Point offset) {
        pt[0] += offset;
        pt[1] += offset;

        return *this;
    }

    Rect& operator-=(Point offset) {
        pt[0] -= offset;
        pt[1] -= offset;

        return *this;
    }

    Rect operator+(Point offset) {
        return Rect(pt[0] + offset, pt[1] + offset);
    }

    Rect operator*(float s) { return Rect(pt[0] * s, pt[1] * s); }

    Rect& operator*=(float s) {
        pt[0] *= s;
        pt[1] *= s;

        return *this;
    }

    bool containsRect(const Rect& other) const;

    bool containsPoint(Point other) const override;

    bool hit(Point pt) const override;

    bool hit(const Segment& seg) const override;

    Point center() const { return (pt[0] + pt[1]) / 2; }

    /*
    * The expand function will make the rectangle larger to include
    * the given point (just large enough) 
    * This function will alter the points defining the rect to the bottom left
    * and the top right
    */
    void expand(Point pt);
    
    /*
    * The expand function will make the rectangle larger to include
    * the given rectangle (just large enough)
    * This function will alter the points defining the rect to the bottom left
    * and the top right
    */
    void expand(const Rect& rect);

    /*
    * Makes the rectangle bigger in all direction by the padding amount
    * especially useful around the goalboxes to movement
    * This function will alter the points defining the rect to the bottom left
    * and the top right
    */
    void pad(float padding);

    float minx() const { return std::min(pt[0].x(), pt[1].x()); }
    float miny() const { return std::min(pt[0].y(), pt[1].y()); }
    float maxx() const { return std::max(pt[0].x(), pt[1].x()); }
    float maxy() const { return std::max(pt[0].y(), pt[1].y()); }

{'fraction_non_alphanumeric': 0.13465688390159689, 'fraction_numerical': 0.015537332757876565, 'mean_word_length': 2.469311377245509, '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': '5293705', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1447, 'n_words': 506}