<commit_before>#include <protobuf/LogFrame.pb.h>
#include <Geometry2d/Line.hpp>
#include <Geometry2d/Polygon.hpp>
#include <LogUtils.hpp>
#include <Robot.hpp>
#include <RobotConfig.hpp>
#include <SystemState.hpp>
#include "planning/Path.hpp"

using namespace Packet;
using namespace std;
using namespace Planning;
using namespace Geometry2d;
using Planning::MotionInstant;

class BallPath : public Planning::Path {
public:
    BallPath(const Ball& ball) : ball(ball){};

    virtual bool hit(const Geometry2d::ShapeSet& obstacles,
                     RJ::Seconds startTimeIntoPath,
                     RJ::Seconds* hitTime) const {
        throw new std::runtime_error("Unsupported Opperation");
    }

    virtual void draw(SystemState* const state, const QColor& color = Qt::black,
                      const QString& layer = "Motion") const {
        throw new std::runtime_error("Unsupported Opperation");
    }

    virtual RJ::Seconds getDuration() const { return RJ::Seconds::max(); }

    virtual std::unique_ptr<Path> subPath(RJ::Seconds startTime,
                                          RJ::Seconds endTime) const {
        throw new std::runtime_error("Unsupported Opperation");
    }

    virtual RobotInstant start() const {
        return RobotInstant(ball.predict(startTime()));
    }
    virtual RobotInstant end() const {
        throw new std::runtime_error("Unsupported Opperation");
    }

    virtual std::unique_ptr<Path> clone() const {
        return std::make_unique<BallPath>(*this);
    }

protected:
    virtual boost::optional<RobotInstant> eval(RJ::Seconds t) const {
        return RobotInstant(ball.predict(startTime() + t));
    }

private:
    const Ball& ball;
};

std::unique_ptr<Planning::Path> Ball::path(RJ::Time startTime) const {
    auto path = std::make_unique<BallPath>(*this);
    path->setStartTime(startTime);
    return std::move(path);
}

constexpr auto ballDecayConstant = 0.275;

Planning::MotionInstant Ball::predict(RJ::Time estimateTime) const {
    if (estimateTime < time) {
        // debugThrow("Estimated Time can't be before observation time.");
        std::cout
            << "CRITICAL ERROR: Estimated Time can't be before observation time"
            << std::endl;
        std::cout << "estimateTime: " << RJ::timestamp(estimateTime)
                  << std::endl;
        std::cout << "actualTime: " << RJ::timestamp(time) << std::endl;
        estimateTime = time;

        // return MotionInstant();
    }

    MotionInstant instant;
    auto t = RJ::Seconds(estimateTime - time);

    const auto s0 = vel.mag();

    const auto decayConstant = 0.2647655;

    double speed = 0;
    double distance = 0;
    if (s0 != 0) {
        auto maxTime = s0 / decayConstant;
        if (t.count() >= maxTime) {
            speed = 0;
            distance = s0 * maxTime - pow(maxTime, 2) / 2.0 * decayConstant;
        } else {
            speed = s0 - (t.count() * decayConstant);
            distance = s0 * t.count() - pow(t.count(), 2) / 2.0 * decayConstant;
        }
    } else {
        speed = 0;<commit_msg>Remove extra decayConstant variable<commit_after>#include <protobuf/LogFrame.pb.h>
#include <Geometry2d/Line.hpp>
#include <Geometry2d/Polygon.hpp>
#include <LogUtils.hpp>
#include <Robot.hpp>
#include <RobotConfig.hpp>
#include <SystemState.hpp>
#include "planning/Path.hpp"

using namespace Packet;
using namespace std;
using namespace Planning;
using namespace Geometry2d;
using Planning::MotionInstant;

class BallPath : public Planning::Path {
public:
    BallPath(const Ball& ball) : ball(ball){};

    virtual bool hit(const Geometry2d::ShapeSet& obstacles,
                     RJ::Seconds startTimeIntoPath,
                     RJ::Seconds* hitTime) const {
        throw new std::runtime_error("Unsupported Opperation");
    }

    virtual void draw(SystemState* const state, const QColor& color = Qt::black,
                      const QString& layer = "Motion") const {
        throw new std::runtime_error("Unsupported Opperation");
    }

    virtual RJ::Seconds getDuration() const { return RJ::Seconds::max(); }

    virtual std::unique_ptr<Path> subPath(RJ::Seconds startTime,
                                          RJ::Seconds endTime) const {
        throw new std::runtime_error("Unsupported Opperation");
    }

    virtual RobotInstant start() const {
        return RobotInstant(ball.predict(startTime()));
    }
    virtual RobotInstant end() const {
        throw new std::runtime_error("Unsupported Opperation");
    }

    virtual std::unique_ptr<Path> clone() const {
        return std::make_unique<BallPath>(*this);
    }

protected:
    virtual boost::optional<RobotInstant> eval(RJ::Seconds t) const {
        return RobotInstant(ball.predict(startTime() + t));
    }

private:
    const Ball& ball;
};

std::unique_ptr<Planning::Path> Ball::path(RJ::Time startTime) const {
    auto path = std::make_unique<BallPath>(*this);
    path->setStartTime(startTime);
    return std::move(path);
}

constexpr auto ballDecayConstant = 0.275;

Planning::MotionInstant Ball::predict(RJ::Time estimateTime) const {
    if (estimateTime < time) {
        // debugThrow("Estimated Time can't be before observation time.");
        std::cout
            << "CRITICAL ERROR: Estimated Time can't be before observation time"
            << std::endl;
        std::cout << "estimateTime: " << RJ::timestamp(estimateTime)
                  << std::endl;
        std::cout << "actualTime: " << RJ::timestamp(time) << std::endl;
        estimateTime = time;

        // return MotionInstant();
    }

    MotionInstant instant;
    auto t = RJ::Seconds(estimateTime - time);

    const auto s0 = vel.mag();

    double speed = 0;
    double distance = 0;
    if (s0 != 0) {
        auto maxTime = s0 / ballDecayConstant;
        if (t.count() >= maxTime) {
            speed = 0;
            distance = s0 * maxTime - pow(maxTime, 2) / 2.0 * ballDecayConstant;
        } else {
            speed = s0 - (t.count() * ballDecayConstant);
            distance = s0 * t.count() - pow(t.count(), 2) / 2.0 * ballDecayConstant;
        }
    } else {
        speed = 0;
{'fraction_non_alphanumeric': 0.12806362603473462, 'fraction_numerical': 0.009414056159714333, 'mean_word_length': 2.792, 'pattern_counts': {'":': 0, '<': 63, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5487588', 'n_tokens_mistral': 1898, 'n_tokens_neox': 1814, 'n_words': 450}