<commit_before>/*

Copyright (c) 2018, <NAME>. (<EMAIL>)
All rights reserved.

This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
Dynacoe was released under the MIT License, as detailed below.



Permission is hereby granted, free of charge, to any person obtaining a copy 
of this software and associated documentation files (the "Software"), to deal 
in the Software without restriction, including without limitation the rights 
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
copies of the Software, and to permit persons to whom the Software is furnished 
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall
be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
DEALINGS IN THE SOFTWARE.



*/

#ifndef H_OBJECT2D_INCLUDED
#define H_OBJECT2D_INCLUDED

#include <Dynacoe/Component.h>
#include <Dynacoe/Color.h>





namespace Dynacoe {

class CollisionManager; 
/// \ingroup Components
/// \{

/// \brief A component that gives movement and collision-detection
/// related attributes to an Entity in 2D space
///
/// Known events:
/// "on-move" - called BEFORE applying the new position of the Entity.
/// "on-collide" - source will always be what caused the collision
class Object2D : public Component {
    public:
        
        /// \brief Defines a collidable region.
        ///
        class ContactPoly {
            public:
                /// \brief Returns the number of points that make up the polygon.
                ///
                int GetNumVectors() const;
        
                /// \brief Returns the i'th point.
                ///
                Dynacoe::Vector GetVector(int i) const;

                /// \brief Updates the value of the i'th point.
                ///
                void SetVector(int, const Dynacoe::Vector &);

                
                ContactPoly(int i) : numPts(i) {pts = new Dynacoe::Vector[i];}
                ~ContactPoly() { delete[] pts;}

            private:
                friend Object2D;
                friend CollisionManager;
                Dynacoe::Vector * pts;
                int numPts;

        };


 



        Object2D();
        ~Object2D();
    
        void OnAttach();

        void OnStep();

        /// \brief Compounds a velocity vector with the current velocity
        ///
        /// @param factor The velocity amount to add. Can be negative.
        /// @param direction The direction to apply the velocity in degrees.
        void AddVelocity(double factor, double direction);
        void AddVelocityTowards(double factor, const Dynacoe::Vector &);


        /// \brief Sets the velocity vector of an object.
        /// <commit_msg>dev: Added proposed interface for collider as a part of Object2d<commit_after>/*

Copyright (c) 2018, <NAME>. (<EMAIL>)
All rights reserved.

This file is part of the Dynacoe project (https://github.com/jcorks/Dynacoe)
Dynacoe was released under the MIT License, as detailed below.



Permission is hereby granted, free of charge, to any person obtaining a copy 
of this software and associated documentation files (the "Software"), to deal 
in the Software without restriction, including without limitation the rights 
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
copies of the Software, and to permit persons to whom the Software is furnished 
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall
be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
DEALINGS IN THE SOFTWARE.



*/

#ifndef H_OBJECT2D_INCLUDED
#define H_OBJECT2D_INCLUDED

#include <Dynacoe/Component.h>
#include <Dynacoe/Color.h>





namespace Dynacoe {

class CollisionManager; 
/// \ingroup Components
/// \{

/// \brief A component that gives movement and collision-detection
/// related attributes to an Entity in 2D space
///
/// Known events:
/// "on-move" - called BEFORE applying the new position of the Entity.
/// "on-collide" - source will always be what caused the collision
class Object2D : public Component {
    public:
        
        /// \brief Defines a collidable region.
        ///
        class ContactPoly {
            public:
                /// \brief Returns the number of points that make up the polygon.
                ///
                int GetNumVectors() const;
        
                /// \brief Returns the i'th point.
                ///
                Dynacoe::Vector GetVector(int i) const;

                /// \brief Updates the value of the i'th point.
                ///
                void SetVector(int, const Dynacoe::Vector &);

                
                ContactPoly(int i) : numPts(i) {pts = new Dynacoe::Vector[i];}
                ~ContactPoly() { delete[] pts;}

            private:
                friend Object2D;
                friend CollisionManager;
                Dynacoe::Vector * pts;
                int numPts;

        };


 
        class Collider {
          public:

            void FromRectangle(const Dynacoe::Vector & p0, const Dynacoe::Vector & p1,
                               const Dynacoe::Vector & p2, const Dynacoe::Vector & p3);
                               
            void FromPolygon(const std::vector<Dynacoe::Vector> &);
            
            void FromCircle(float radius, uint32_t numPoints=8);
            
            
            const std::vector<Dynacoe::Vector> & GetSmear(const Dynacoe::Vector & before, const Dynacoe::Vector & after);
            const std::vector<Dynacoe::Vector> & GetBoundingBox();
            
            
        }


        Object2D();
        ~Object2D();
    
        void OnAttach();

        void OnStep();

        /// \brief Compounds a velocity vector with the current velocity
        ///
        /// @param factor The velocity amount to add. Can be negative.
        /// @param direction The direction to apply the velocity in degrees.
        void AddVelocity(double factor, double direction);
        void AddVelocityTowards(double factor, const Dynacoe::Vector &);


        /// \brief Sets the velocity vector of an object.
        /// 
{'fraction_non_alphanumeric': 0.07917723302338688, 'fraction_numerical': 0.00422654268808115, 'mean_word_length': 2.167782240071397, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 2, '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': '5706662', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1794, 'n_words': 765}