<commit_before>#include <UtH/Engine/TMX/Object.hpp>

#include <tinyxml2.h>

#include <cstdlib>
#include <sstream>

using namespace uth;
using namespace TMX;

Object::Object(tinyxml2::XMLElement* objectElement)
{
    parseObject(objectElement);
}

Object::~Object()
{ }


// Public

const umath::rectangle& Object::GetRectangle() const
{
	return m_rectangle;
}

const std::vector<umath::vector2>& Object::GetPoints() const
{
	return m_points;
}

const umath::vector2 Object::GetPosition() const
{
	return umath::vector2(m_rectangle.x, m_rectangle.y);
}

std::string Object::GetProperty(const std::string& name) const
{
	auto prop = m_properties.find(name);
	if(prop != m_properties.end())
		return prop->second;

	return std::string();
}

const std::string& Object::GetName() const
{
	return m_name;
}

const std::string& Object::GetType() const
{
	return m_typeString;
}

// Private

void Object::parseObject(tinyxml2::XMLElement* element)
{
    // Parse properties
	m_name = element->Attribute("name");
	m_typeString = element->Attribute("type");

    auto properties = element->FirstChildElement("properties");
    if(properties != 0)
    {
        parseProperties(properties);
    }

    // Parse actual object
	m_rectangle.x = element->FloatAttribute("x");
	m_rectangle.y = element->FloatAttribute("y");

	// There are only 3 possibilities here but use else if for future compability
	if(element->UnsignedAttribute("width") != 0)
	{
		// Rectangle
		m_type = RECTANGLE;
		m_rectangle.width = element->FloatAttribute("width");
		m_rectangle.height = element->FloatAttribute("height");

		m_points.push_back(umath::vector2(m_rectangle.x, m_rectangle.y));
		m_points.push_back(umath::vector2(m_rectangle.x, m_rectangle.y));
		m_points.push_back(umath::vector2(m_rectangle.x, m_rectangle.y));
		m_points.push_back(umath::vector2(m_rectangle.x, m_rectangle.y));
	}
	else if(element->FirstChildElement("polygon") != 0)
	{
		// Polygon
		m_type = POLYGON;
		std::string points = element->FirstChildElement("polygon")->Attribute("points");
		parsePoints(points);
	}
	else if(element->FirstChildElement("polyline") != 0)
	{
		// Line
		m_type = LINE;
		std::string points = element->FirstChildElement("polyline")->Attribute("points");
		parsePoints(points);
	}
}

void Object::parseProperties(tinyxml2::XMLElement* element)
{
    auto p = element->FirstChildElement("property");
	while(p != 0)
	{
		std::pair<std::string, std::string> tmp;
		tmp.first = p->Attribute("name");
		tmp.second = p->Attribute("value");

		m_properties.insert(tmp);
<commit_msg>Fix points of a rectangle<commit_after>#include <UtH/Engine/TMX/Object.hpp>

#include <tinyxml2.h>

#include <cstdlib>
#include <sstream>

using namespace uth;
using namespace TMX;

Object::Object(tinyxml2::XMLElement* objectElement)
{
    parseObject(objectElement);
}

Object::~Object()
{ }


// Public

const umath::rectangle& Object::GetRectangle() const
{
	return m_rectangle;
}

const std::vector<umath::vector2>& Object::GetPoints() const
{
	return m_points;
}

const umath::vector2 Object::GetPosition() const
{
	return umath::vector2(m_rectangle.x, m_rectangle.y);
}

std::string Object::GetProperty(const std::string& name) const
{
	auto prop = m_properties.find(name);
	if(prop != m_properties.end())
		return prop->second;

	return std::string();
}

const std::string& Object::GetName() const
{
	return m_name;
}

const std::string& Object::GetType() const
{
	return m_typeString;
}

// Private

void Object::parseObject(tinyxml2::XMLElement* element)
{
    // Parse properties
	m_name = element->Attribute("name");
	m_typeString = element->Attribute("type");

    auto properties = element->FirstChildElement("properties");
    if(properties != 0)
    {
        parseProperties(properties);
    }

    // Parse actual object
	m_rectangle.x = element->FloatAttribute("x");
	m_rectangle.y = element->FloatAttribute("y");

	// There are only 3 possibilities here but use else if for future compability
	if(element->UnsignedAttribute("width") != 0)
	{
		// Rectangle
		m_type = RECTANGLE;
		m_rectangle.width = element->FloatAttribute("width");
		m_rectangle.height = element->FloatAttribute("height");

		m_points.push_back(umath::vector2(m_rectangle.x, m_rectangle.y));
		m_points.push_back(umath::vector2(m_rectangle.x, m_rectangle.y-m_rectangle.height));
		m_points.push_back(umath::vector2(m_rectangle.x+m_rectangle.width, m_rectangle.y-m_rectangle.height));
		m_points.push_back(umath::vector2(m_rectangle.x+m_rectangle.width, m_rectangle.y));
	}
	else if(element->FirstChildElement("polygon") != 0)
	{
		// Polygon
		m_type = POLYGON;
		std::string points = element->FirstChildElement("polygon")->Attribute("points");
		parsePoints(points);
	}
	else if(element->FirstChildElement("polyline") != 0)
	{
		// Line
		m_type = LINE;
		std::string points = element->FirstChildElement("polyline")->Attribute("points");
		parsePoints(points);
	}
}

void Object::parseProperties(tinyxml2::XMLElement* element)
{
    auto p = element->FirstChildElement("property");
	while(p != 0)
	{
		std::pair<std::string, std::string> tmp;
		tmp.first = p->Attribute("name");
		tmp.second = p->Attribute("value");

		m_properties.insert(tmp);

{'fraction_non_alphanumeric': 0.15696104897801774, 'fraction_numerical': 0.006556112610875434, 'mean_word_length': 5.380073800738008, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, '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': '5292944', 'n_tokens_mistral': 1851, 'n_tokens_neox': 1778, 'n_words': 310}