Fase 1a: Punt -> Vec2 amb operadors moderns
Primera sub-fase del naming sweep. Punt era un struct sense
operacions, conservat per compatibilitat amb el Pascal original.
Substituit per Vec2, un aggregate amb operadors aritmetics, dot,
length, normalized i length_squared (camelBack: lengthSquared)
seguint les regles del .clang-tidy del projecte.
Canvis:
- core/types.hpp reescrit: nou struct Vec2 amb +=,-=,*=,/=,
unary -, ==, dot, length, lengthSquared, normalized
- Operadors fora de la classe: +, -, *, / (amb float per ambdues
bandes), - unari, ==
- Vec2 segueix sent aggregate (sense constructors definits):
els 'designated initializers' del codi existent funcionen igual:
Vec2{.x = ..., .y = ...}
- Sed global sobre 35 fitxers: tots els 'Punt' -> 'Vec2'
Net: 35 fitxers tocats, +180 / -114. Compila i enllaça.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -134,8 +134,8 @@ void Shape::parse_center(const std::string& value) {
|
||||
}
|
||||
|
||||
// Helper: parse points "x1,y1 x2,y2 x3,y3"
|
||||
std::vector<Punt> Shape::parse_points(const std::string& str) const {
|
||||
std::vector<Punt> points;
|
||||
std::vector<Vec2> Shape::parse_points(const std::string& str) const {
|
||||
std::vector<Vec2> points;
|
||||
std::istringstream iss(trim(str));
|
||||
std::string pair;
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ enum class PrimitiveType {
|
||||
// Primitiva individual (polyline o line)
|
||||
struct ShapePrimitive {
|
||||
PrimitiveType type;
|
||||
std::vector<Punt> points; // 2+ punts per polyline, exactament 2 per line
|
||||
std::vector<Vec2> points; // 2+ punts per polyline, exactament 2 per line
|
||||
};
|
||||
|
||||
// Classe Shape - representa una forma vectorial carregada des de .shp
|
||||
@@ -39,7 +39,7 @@ class Shape {
|
||||
[[nodiscard]] const std::vector<ShapePrimitive>& get_primitives() const {
|
||||
return primitives_;
|
||||
}
|
||||
[[nodiscard]] const Punt& get_centre() const { return centre_; }
|
||||
[[nodiscard]] const Vec2& get_centre() const { return centre_; }
|
||||
[[nodiscard]] float get_escala_defecte() const { return escala_defecte_; }
|
||||
[[nodiscard]] bool es_valida() const { return !primitives_.empty(); }
|
||||
|
||||
@@ -49,7 +49,7 @@ class Shape {
|
||||
|
||||
private:
|
||||
std::vector<ShapePrimitive> primitives_;
|
||||
Punt centre_; // Centre/origen de la forma
|
||||
Vec2 centre_; // Centre/origen de la forma
|
||||
float escala_defecte_; // Escala per defecte (normalment 1.0)
|
||||
std::string nom_; // Nom de la forma (per depuració)
|
||||
|
||||
@@ -58,7 +58,7 @@ class Shape {
|
||||
[[nodiscard]] bool starts_with(const std::string& str, const std::string& prefix) const;
|
||||
[[nodiscard]] std::string extract_value(const std::string& line) const;
|
||||
void parse_center(const std::string& value);
|
||||
[[nodiscard]] std::vector<Punt> parse_points(const std::string& str) const;
|
||||
[[nodiscard]] std::vector<Vec2> parse_points(const std::string& str) const;
|
||||
};
|
||||
|
||||
} // namespace Graphics
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace Graphics {
|
||||
|
||||
// Constructor
|
||||
Starfield::Starfield(SDL_Renderer* renderer,
|
||||
const Punt& punt_fuga,
|
||||
const Vec2& punt_fuga,
|
||||
const SDL_FRect& area,
|
||||
int densitat)
|
||||
: renderer_(renderer),
|
||||
|
||||
@@ -30,7 +30,7 @@ class Starfield {
|
||||
// - area: rectangle on actuen les estrelles (SDL_FRect)
|
||||
// - densitat: nombre total d'estrelles (es divideix entre capes)
|
||||
Starfield(SDL_Renderer* renderer,
|
||||
const Punt& punt_fuga,
|
||||
const Vec2& punt_fuga,
|
||||
const SDL_FRect& area,
|
||||
int densitat = 150);
|
||||
|
||||
@@ -41,13 +41,13 @@ class Starfield {
|
||||
void dibuixar();
|
||||
|
||||
// Setters per ajustar paràmetres en temps real
|
||||
void set_punt_fuga(const Punt& punt) { punt_fuga_ = punt; }
|
||||
void set_punt_fuga(const Vec2& punt) { punt_fuga_ = punt; }
|
||||
void set_brightness(float multiplier);
|
||||
|
||||
private:
|
||||
// Estructura interna per cada estrella
|
||||
struct Estrella {
|
||||
Punt posicio; // Posició actual
|
||||
Vec2 posicio; // Posició actual
|
||||
float angle; // Angle de moviment (radians)
|
||||
float distancia_centre; // Distància normalitzada del centre (0.0-1.0)
|
||||
int capa; // Índex de capa (0=lluny, 1=mitjà, 2=prop)
|
||||
@@ -72,7 +72,7 @@ class Starfield {
|
||||
SDL_Renderer* renderer_;
|
||||
|
||||
// Configuració
|
||||
Punt punt_fuga_; // Punt d'origen de les estrelles
|
||||
Vec2 punt_fuga_; // Vec2 d'origen de les estrelles
|
||||
SDL_FRect area_; // Àrea activa
|
||||
float radi_max_; // Distància màxima del centre al límit de pantalla
|
||||
int densitat_; // Nombre total d'estrelles
|
||||
|
||||
@@ -182,7 +182,7 @@ bool VectorText::is_supported(char c) const {
|
||||
return chars_.contains(c);
|
||||
}
|
||||
|
||||
void VectorText::render(const std::string& text, const Punt& posicio, float escala, float spacing, float brightness) const {
|
||||
void VectorText::render(const std::string& text, const Vec2& posicio, float escala, float spacing, float brightness) const {
|
||||
if (renderer_ == nullptr) {
|
||||
return;
|
||||
}
|
||||
@@ -223,7 +223,7 @@ void VectorText::render(const std::string& text, const Punt& posicio, float esca
|
||||
// Renderizar carácter
|
||||
// Ajustar X e Y para que posicio represente esquina superior izquierda
|
||||
// (render_shape espera el centro, así que sumamos la mitad de ancho y altura)
|
||||
Punt char_pos = {.x = current_x + (char_width_scaled / 2.0F), .y = posicio.y + (char_height_scaled / 2.0F)};
|
||||
Vec2 char_pos = {.x = current_x + (char_width_scaled / 2.0F), .y = posicio.y + (char_height_scaled / 2.0F)};
|
||||
Rendering::render_shape(renderer_, it->second, char_pos, 0.0F, escala, 1.0F, brightness);
|
||||
|
||||
// Avanzar posición
|
||||
@@ -237,14 +237,14 @@ void VectorText::render(const std::string& text, const Punt& posicio, float esca
|
||||
}
|
||||
}
|
||||
|
||||
void VectorText::render_centered(const std::string& text, const Punt& centre_punt, float escala, float spacing, float brightness) const {
|
||||
void VectorText::render_centered(const std::string& text, const Vec2& centre_punt, float escala, float spacing, float brightness) const {
|
||||
// Calcular dimensions del text
|
||||
float text_width = get_text_width(text, escala, spacing);
|
||||
float text_height = get_text_height(escala);
|
||||
|
||||
// Calcular posició de l'esquina superior esquerra
|
||||
// restant la meitat de les dimensions del punt central
|
||||
Punt posicio_esquerra = {
|
||||
Vec2 posicio_esquerra = {
|
||||
.x = centre_punt.x - (text_width / 2.0F),
|
||||
.y = centre_punt.y - (text_height / 2.0F)};
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ class VectorText {
|
||||
// - escala: factor de escala (1.0 = 20×40 px por carácter)
|
||||
// - spacing: espacio entre caracteres en píxeles (a escala 1.0)
|
||||
// - brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor)
|
||||
void render(const std::string& text, const Punt& posicio, float escala = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const;
|
||||
void render(const std::string& text, const Vec2& posicio, float escala = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const;
|
||||
|
||||
// Renderizar string centrado en un punto
|
||||
// - text: cadena a renderizar
|
||||
@@ -33,7 +33,7 @@ class VectorText {
|
||||
// - escala: factor de escala (1.0 = 20×40 px por carácter)
|
||||
// - spacing: espacio entre caracteres en píxeles (a escala 1.0)
|
||||
// - brightness: factor de brillantor (0.0-1.0, default 1.0 = màxima brillantor)
|
||||
void render_centered(const std::string& text, const Punt& centre_punt, float escala = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const;
|
||||
void render_centered(const std::string& text, const Vec2& centre_punt, float escala = 1.0F, float spacing = 2.0F, float brightness = 1.0F) const;
|
||||
|
||||
// Calcular ancho total de un string (útil para centrado)
|
||||
[[nodiscard]] float get_text_width(const std::string& text, float escala = 1.0F, float spacing = 2.0F) const;
|
||||
|
||||
Reference in New Issue
Block a user