style: aplicar fixes de clang-tidy (todo excepto uppercase-literal-suffix)
Corregidos ~2570 issues automáticamente con clang-tidy --fix-errors más ajustes manuales posteriores: - modernize: designated-initializers, trailing-return-type, use-auto, avoid-c-arrays (→ std::array<>), use-ranges, use-emplace, deprecated-headers, use-equals-default, pass-by-value, return-braced-init-list, use-default-member-init - readability: math-missing-parentheses, implicit-bool-conversion, braces-around-statements, isolate-declaration, use-std-min-max, identifier-naming, else-after-return, redundant-casting, convert-member-functions-to-static, make-member-function-const, static-accessed-through-instance - performance: avoid-endl, unnecessary-value-param, type-promotion, inefficient-vector-operation - dead code: XOR_KEY (orphan tras eliminar encryptData/decryptData), dead stores en engine.cpp y png_shape.cpp - NOLINT justificado en 10 funciones con alta complejidad cognitiva (initialize, render, main, processEvents, update×3, performDemoAction, randomizeOnDemoStart, renderDebugHUD, AppLogo::update) Compilación: gcc -Wall sin warnings. clang-tidy: 0 issues. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
#include "png_shape.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
#include "defines.hpp"
|
||||
#include "external/stb_image.h"
|
||||
#include "resource_manager.hpp"
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
|
||||
PNGShape::PNGShape(const char* png_path) {
|
||||
// Cargar PNG desde path
|
||||
if (!loadPNG(png_path)) {
|
||||
std::cerr << "[PNGShape] Usando fallback 10x10" << std::endl;
|
||||
std::cerr << "[PNGShape] Usando fallback 10x10" << '\n';
|
||||
// Fallback: generar un cuadrado simple si falla la carga
|
||||
image_width_ = 10;
|
||||
image_height_ = 10;
|
||||
@@ -21,7 +23,7 @@ PNGShape::PNGShape(const char* png_path) {
|
||||
next_idle_time_ = PNG_IDLE_TIME_MIN + (rand() % 1000) / 1000.0f * (PNG_IDLE_TIME_MAX - PNG_IDLE_TIME_MIN);
|
||||
}
|
||||
|
||||
bool PNGShape::loadPNG(const char* resource_key) {
|
||||
auto PNGShape::loadPNG(const char* resource_key) -> bool {
|
||||
{
|
||||
std::string fn = std::string(resource_key);
|
||||
fn = fn.substr(fn.find_last_of("\\/") + 1);
|
||||
@@ -30,15 +32,16 @@ bool PNGShape::loadPNG(const char* resource_key) {
|
||||
unsigned char* file_data = nullptr;
|
||||
size_t file_size = 0;
|
||||
if (!ResourceManager::loadResource(resource_key, file_data, file_size)) {
|
||||
std::cerr << "[PNGShape] ERROR: recurso no encontrado: " << resource_key << std::endl;
|
||||
std::cerr << "[PNGShape] ERROR: recurso no encontrado: " << resource_key << '\n';
|
||||
return false;
|
||||
}
|
||||
int width, height, channels;
|
||||
unsigned char* pixels = stbi_load_from_memory(file_data, static_cast<int>(file_size),
|
||||
&width, &height, &channels, 1);
|
||||
int width;
|
||||
int height;
|
||||
int channels;
|
||||
unsigned char* pixels = stbi_load_from_memory(file_data, static_cast<int>(file_size), &width, &height, &channels, 1);
|
||||
delete[] file_data;
|
||||
if (!pixels) {
|
||||
std::cerr << "[PNGShape] ERROR al decodificar PNG: " << stbi_failure_reason() << std::endl;
|
||||
if (pixels == nullptr) {
|
||||
std::cerr << "[PNGShape] ERROR al decodificar PNG: " << stbi_failure_reason() << '\n';
|
||||
return false;
|
||||
}
|
||||
image_width_ = width;
|
||||
@@ -57,9 +60,11 @@ void PNGShape::detectEdges() {
|
||||
// Detectar píxeles del contorno (píxeles blancos con al menos un vecino negro)
|
||||
for (int y = 0; y < image_height_; y++) {
|
||||
for (int x = 0; x < image_width_; x++) {
|
||||
int idx = y * image_width_ + x;
|
||||
int idx = (y * image_width_) + x;
|
||||
|
||||
if (!pixel_data_[idx]) continue; // Solo píxeles blancos
|
||||
if (!pixel_data_[idx]) {
|
||||
continue; // Solo píxeles blancos
|
||||
}
|
||||
|
||||
// Verificar vecinos (arriba, abajo, izq, der)
|
||||
bool is_edge = false;
|
||||
@@ -68,10 +73,10 @@ void PNGShape::detectEdges() {
|
||||
is_edge = true; // Bordes de la imagen
|
||||
} else {
|
||||
// Verificar 4 vecinos
|
||||
if (!pixel_data_[idx - 1] || // Izquierda
|
||||
!pixel_data_[idx + 1] || // Derecha
|
||||
!pixel_data_[idx - image_width_] || // Arriba
|
||||
!pixel_data_[idx + image_width_]) { // Abajo
|
||||
if (!pixel_data_[idx - 1] || // Izquierda
|
||||
!pixel_data_[idx + 1] || // Derecha
|
||||
!pixel_data_[idx - image_width_] || // Arriba
|
||||
!pixel_data_[idx + image_width_]) { // Abajo
|
||||
is_edge = true;
|
||||
}
|
||||
}
|
||||
@@ -90,7 +95,7 @@ void PNGShape::floodFill() {
|
||||
|
||||
for (int y = 0; y < image_height_; y++) {
|
||||
for (int x = 0; x < image_width_; x++) {
|
||||
int idx = y * image_width_ + x;
|
||||
int idx = (y * image_width_) + x;
|
||||
if (pixel_data_[idx]) {
|
||||
filled_points_.push_back({static_cast<float>(x), static_cast<float>(y)});
|
||||
}
|
||||
@@ -114,8 +119,8 @@ void PNGShape::generatePoints(int num_points, float screen_width, float screen_h
|
||||
num_layers_ = PNG_NUM_EXTRUSION_LAYERS;
|
||||
|
||||
// Generar AMBOS conjuntos de puntos (relleno Y bordes)
|
||||
floodFill(); // Generar filled_points_
|
||||
detectEdges(); // Generar edge_points_
|
||||
floodFill(); // Generar filled_points_
|
||||
detectEdges(); // Generar edge_points_
|
||||
|
||||
// Guardar copias originales (las funciones de filtrado modifican los vectores)
|
||||
std::vector<Point2D> filled_points_original = filled_points_;
|
||||
@@ -123,7 +128,7 @@ void PNGShape::generatePoints(int num_points, float screen_width, float screen_h
|
||||
|
||||
// Conjunto de puntos ACTIVO (será modificado por filtros)
|
||||
std::vector<Point2D> active_points_data;
|
||||
std::string mode_name = "";
|
||||
std::string mode_name;
|
||||
|
||||
// === SISTEMA DE DISTRIBUCIÓN ADAPTATIVA ===
|
||||
// Estrategia: Optimizar según número de pelotas disponibles
|
||||
@@ -196,8 +201,6 @@ void PNGShape::generatePoints(int num_points, float screen_width, float screen_h
|
||||
std::vector<Point2D> vertices = extractCornerVertices(source_for_vertices);
|
||||
if (!vertices.empty() && vertices.size() < active_points_data.size()) {
|
||||
active_points_data = vertices;
|
||||
num_2d_points = active_points_data.size();
|
||||
total_3d_points = num_2d_points * num_layers_;
|
||||
mode_name = "VÉRTICES";
|
||||
}
|
||||
}
|
||||
@@ -216,7 +219,7 @@ void PNGShape::generatePoints(int num_points, float screen_width, float screen_h
|
||||
|
||||
// Extraer filas alternas de puntos (FUNCIÓN PURA: no modifica parámetros)
|
||||
// Recibe vector original y devuelve nuevo vector filtrado
|
||||
std::vector<PNGShape::Point2D> PNGShape::extractAlternateRows(const std::vector<Point2D>& source, int row_skip) {
|
||||
auto PNGShape::extractAlternateRows(const std::vector<Point2D>& source, int row_skip) -> std::vector<PNGShape::Point2D> {
|
||||
std::vector<Point2D> result;
|
||||
|
||||
if (row_skip <= 1 || source.empty()) {
|
||||
@@ -243,7 +246,7 @@ std::vector<PNGShape::Point2D> PNGShape::extractAlternateRows(const std::vector<
|
||||
}
|
||||
|
||||
// Extraer vértices y esquinas (FUNCIÓN PURA: devuelve nuevo vector)
|
||||
std::vector<PNGShape::Point2D> PNGShape::extractCornerVertices(const std::vector<Point2D>& source) {
|
||||
auto PNGShape::extractCornerVertices(const std::vector<Point2D>& source) -> std::vector<PNGShape::Point2D> {
|
||||
std::vector<Point2D> result;
|
||||
|
||||
if (source.empty()) {
|
||||
@@ -267,9 +270,9 @@ std::vector<PNGShape::Point2D> PNGShape::extractCornerVertices(const std::vector
|
||||
|
||||
// Generar puntos en extremos de cada fila
|
||||
for (const auto& [row_y, extremes] : row_extremes) {
|
||||
result.push_back({extremes.first, static_cast<float>(row_y)}); // Extremo izquierdo
|
||||
if (extremes.second != extremes.first) { // Solo añadir derecho si es diferente
|
||||
result.push_back({extremes.second, static_cast<float>(row_y)}); // Extremo derecho
|
||||
result.push_back({extremes.first, static_cast<float>(row_y)}); // Extremo izquierdo
|
||||
if (extremes.second != extremes.first) { // Solo añadir derecho si es diferente
|
||||
result.push_back({extremes.second, static_cast<float>(row_y)}); // Extremo derecho
|
||||
}
|
||||
}
|
||||
|
||||
@@ -376,8 +379,8 @@ void PNGShape::getPoint3D(int index, float& x, float& y, float& z) const {
|
||||
float v = y_base / (logo_size * 0.5f);
|
||||
|
||||
// Calcular pivoteo (amplitudes más grandes)
|
||||
float tilt_amount_x = sinf(tilt_x_) * 0.15f; // 15%
|
||||
float tilt_amount_y = sinf(tilt_y_) * 0.1f; // 10%
|
||||
float tilt_amount_x = sinf(tilt_x_) * 0.15f; // 15%
|
||||
float tilt_amount_y = sinf(tilt_y_) * 0.1f; // 10%
|
||||
|
||||
// Aplicar pivoteo proporcional al tamaño del logo
|
||||
float z_tilt = (u * tilt_amount_y + v * tilt_amount_x) * logo_size;
|
||||
@@ -386,14 +389,14 @@ void PNGShape::getPoint3D(int index, float& x, float& y, float& z) const {
|
||||
// Aplicar rotación en eje Y (horizontal)
|
||||
float cos_y = cosf(angle_y_);
|
||||
float sin_y = sinf(angle_y_);
|
||||
float x_rot_y = x_base * cos_y - z_base * sin_y;
|
||||
float z_rot_y = x_base * sin_y + z_base * cos_y;
|
||||
float x_rot_y = (x_base * cos_y) - (z_base * sin_y);
|
||||
float z_rot_y = (x_base * sin_y) + (z_base * cos_y);
|
||||
|
||||
// Aplicar rotación en eje X (vertical)
|
||||
float cos_x = cosf(angle_x_);
|
||||
float sin_x = sinf(angle_x_);
|
||||
float y_rot = y_base * cos_x - z_rot_y * sin_x;
|
||||
float z_rot = y_base * sin_x + z_rot_y * cos_x;
|
||||
float y_rot = (y_base * cos_x) - (z_rot_y * sin_x);
|
||||
float z_rot = (y_base * sin_x) + (z_rot_y * cos_x);
|
||||
|
||||
// Retornar coordenadas finales
|
||||
x = x_rot_y;
|
||||
@@ -408,7 +411,7 @@ void PNGShape::getPoint3D(int index, float& x, float& y, float& z) const {
|
||||
}
|
||||
}
|
||||
|
||||
float PNGShape::getScaleFactor(float screen_height) const {
|
||||
auto PNGShape::getScaleFactor(float screen_height) const -> float {
|
||||
// Escala dinámica según resolución
|
||||
return PNG_SIZE_FACTOR;
|
||||
}
|
||||
@@ -432,7 +435,7 @@ void PNGShape::setConvergence(float convergence) {
|
||||
}
|
||||
|
||||
// Obtener progreso del flip actual (0.0 = inicio del flip, 1.0 = fin del flip)
|
||||
float PNGShape::getFlipProgress() const {
|
||||
auto PNGShape::getFlipProgress() const -> float {
|
||||
if (!is_flipping_) {
|
||||
return 0.0f; // No está flipping, progreso = 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user