<commit_before>#pragma once
#include <cstdint>
#include <nlohmann/json.hpp>
#include <vector>

#include "DatatypeEnum.hpp"
#include "RawBuffer.hpp"
#include "RawImgFrame.hpp"

namespace dai {

// TODO move to common
struct Rect {
   public:
    Rect(float xmin, float ymin, float xmax, float ymax) {
        setRect(xmin, ymin, xmax, ymax);
    };
    Rect(){};

    void setRect(float xmin, float ymin, float xmax, float ymax) {
#ifdef __cpp_exceptions
        if(xmin < 0 || xmin > 1) throw std::out_of_range("xmin out of range [0,1]");
        if(xmax < 0 || xmax > 1) throw std::out_of_range("xmax out of range [0,1]");
        if(ymin < 0 || ymin > 1) throw std::out_of_range("ymin out of range [0,1]");
        if(ymax < 0 || ymax > 1) throw std::out_of_range("ymax out of range [0,1]");
        if(xmin >= xmax) throw std::out_of_range("xmin should be less than xmax");
        if(ymin >= ymax) throw std::out_of_range("ymin should be less than ymax");
#endif
        this->xmin = xmin;
        this->xmax = xmax;
        this->ymin = ymin;
        this->ymax = ymax;
    }

    // Normalized range 0-1
    float xmin = 0.0f, ymin = 0.0f, xmax = 0.0f, ymax = 0.0f;
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Rect, xmin, ymin, xmax, ymax);

struct DepthCalculatorConfigData {
    // Normalized range 0-1
    Rect roi;
    uint32_t lower_threshold = 0;
    uint32_t upper_threshold = 65000;
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(DepthCalculatorConfigData, roi, lower_threshold, upper_threshold);

struct RawDepthCalculatorConfig : public RawBuffer {
    std::vector<DepthCalculatorConfigData> config;

    void serialize(std::vector<std::uint8_t>& metadata, DatatypeEnum& datatype) override {
        nlohmann::json j = *this;
        metadata = nlohmann::json::to_msgpack(j);
        datatype = DatatypeEnum::DepthCalculatorConfig;
    };

    NLOHMANN_DEFINE_TYPE_INTRUSIVE(RawDepthCalculatorConfig, config);
};

}  // namespace dai<commit_msg>Add validation check in Rect data type<commit_after>#pragma once
#include <cstdint>
#include <nlohmann/json.hpp>
#include <vector>

#include "DatatypeEnum.hpp"
#include "RawBuffer.hpp"
#include "RawImgFrame.hpp"

namespace dai {

// TODO move to common
struct Rect {
   public:
    Rect(float xmin, float ymin, float xmax, float ymax) {
        set(xmin, ymin, xmax, ymax);
    };
    Rect(){};

    void set(float xmin, float ymin, float xmax, float ymax) {
        this->xmin = xmin;
        this->xmax = xmax;
        this->ymin = ymin;
        this->ymax = ymax;
    }

    bool valid() {
        if(xmin < 0 || xmin > 1) return false;
        if(xmax < 0 || xmax > 1) return false;
        if(ymin < 0 || ymin > 1) return false;
        if(ymax < 0 || ymax > 1) return false;
        if(xmin >= xmax) return false;
        if(ymin >= ymax) return false;
        return true;
    }

    // Normalized range 0-1
    float xmin = 0.0f, ymin = 0.0f, xmax = 0.0f, ymax = 0.0f;
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Rect, xmin, ymin, xmax, ymax);

struct DepthCalculatorConfigData {
    // Normalized range 0-1
    Rect roi;
    uint32_t lower_threshold = 0;
    uint32_t upper_threshold = 65000;
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(DepthCalculatorConfigData, roi, lower_threshold, upper_threshold);

struct RawDepthCalculatorConfig : public RawBuffer {
    std::vector<DepthCalculatorConfigData> config;

    void serialize(std::vector<std::uint8_t>& metadata, DatatypeEnum& datatype) override {
        nlohmann::json j = *this;
        metadata = nlohmann::json::to_msgpack(j);
        datatype = DatatypeEnum::DepthCalculatorConfig;
    };

    NLOHMANN_DEFINE_TYPE_INTRUSIVE(RawDepthCalculatorConfig, config);
};

}  // namespace dai
{'fraction_non_alphanumeric': 0.12347354138398914, 'fraction_numerical': 0.018995929443690638, 'mean_word_length': 3.3313748531139837, 'pattern_counts': {'":': 0, '<': 21, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3631185', 'n_tokens_mistral': 1385, 'n_tokens_neox': 1313, 'n_words': 322}