gitignore no ha deixat versionar cap fitxer de core
afegida gestió de ratolí
This commit is contained in:
64
source/core/graphics/shape.hpp
Normal file
64
source/core/graphics/shape.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
// shape.hpp - Sistema de formes vectorials
|
||||
// © 2025 Port a C++20 amb SDL3
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "core/types.hpp"
|
||||
|
||||
namespace Graphics {
|
||||
|
||||
// Tipus de primitiva dins d'una forma
|
||||
enum class PrimitiveType {
|
||||
POLYLINE, // Seqüència de punts connectats
|
||||
LINE // Línia individual (2 punts)
|
||||
};
|
||||
|
||||
// Primitiva individual (polyline o line)
|
||||
struct ShapePrimitive {
|
||||
PrimitiveType type;
|
||||
std::vector<Punt> points; // 2+ punts per polyline, exactament 2 per line
|
||||
};
|
||||
|
||||
// Classe Shape - representa una forma vectorial carregada des de .shp
|
||||
class Shape {
|
||||
public:
|
||||
// Constructors
|
||||
Shape() = default;
|
||||
explicit Shape(const std::string& filepath);
|
||||
|
||||
// Carregar forma des de fitxer .shp
|
||||
bool carregar(const std::string& filepath);
|
||||
|
||||
// Getters
|
||||
const std::vector<ShapePrimitive>& get_primitives() const {
|
||||
return primitives_;
|
||||
}
|
||||
const Punt& get_centre() const { return centre_; }
|
||||
float get_escala_defecte() const { return escala_defecte_; }
|
||||
bool es_valida() const { return !primitives_.empty(); }
|
||||
|
||||
// Info de depuració
|
||||
std::string get_nom() const { return nom_; }
|
||||
size_t get_num_primitives() const { return primitives_.size(); }
|
||||
|
||||
private:
|
||||
std::vector<ShapePrimitive> primitives_;
|
||||
Punt centre_; // Centre/origen de la forma
|
||||
float escala_defecte_; // Escala per defecte (normalment 1.0)
|
||||
std::string nom_; // Nom de la forma (per depuració)
|
||||
|
||||
// Parsejador del fitxer
|
||||
bool parsejar_fitxer(const std::string& contingut);
|
||||
|
||||
// Helpers privats per parsejar
|
||||
std::string trim(const std::string& str) const;
|
||||
bool starts_with(const std::string& str, const std::string& prefix) const;
|
||||
std::string extract_value(const std::string& line) const;
|
||||
void parse_center(const std::string& value);
|
||||
std::vector<Punt> parse_points(const std::string& str) const;
|
||||
};
|
||||
|
||||
} // namespace Graphics
|
||||
Reference in New Issue
Block a user