Fix erreur de calculs de pointeurs

This commit is contained in:
Timothée Leclaire-Fournier 2024-01-22 20:10:37 -05:00
parent b9d1d04462
commit 3451a57bcf
3 changed files with 6 additions and 9 deletions

View File

@ -1,9 +1,7 @@
#pragma once #pragma once
#include <string> #include <string>
#include <array>
#include <optional> #include <optional>
#include <bitset>
#include <GOL.h> #include <GOL.h>
#include "GridTeamH.h" #include "GridTeamH.h"

View File

@ -1,6 +1,6 @@
#include "GridTeamH.h" #include "GridTeamH.h"
#include "GOL.h" #include "GOL.h"
#include <iostream> #include <algorithm>
// Constructeur Grid par défaut // Constructeur Grid par défaut
GridTeamH::GridTeamH() GridTeamH::GridTeamH()
@ -25,8 +25,8 @@ void GridTeamH::resize(size_t width, size_t height, CellType initValue)
{ {
mWidth = width; mWidth = width;
mHeight = height; mHeight = height;
mData.resize((width * height) + width); mData.resize(width * height);
mIntermediateData.resize((width * height) + width); mIntermediateData.resize(width * height);
fill(initValue, false); fill(initValue, false);
} }
@ -170,21 +170,21 @@ void GridTeamH::fillBorder(CellType value)
} }
// DROITE // DROITE
e_ptr += mWidth * mHeight; e_ptr += mWidth * (mHeight - 1);
while (ptr < e_ptr) { while (ptr < e_ptr) {
*ptr = value; *ptr = value;
ptr += mWidth; ptr += mWidth;
} }
// DESSOUS // DESSOUS
e_ptr -= mWidth; e_ptr -= (mWidth - 1);
while (ptr > e_ptr) { while (ptr > e_ptr) {
*ptr = value; *ptr = value;
ptr--; ptr--;
} }
// GAUCHE // GAUCHE
e_ptr -= mWidth * mHeight; e_ptr -= mWidth * (mHeight - 1);
while (ptr > e_ptr) { while (ptr > e_ptr) {
*ptr = value; *ptr = value;
ptr -= mWidth; ptr -= mWidth;

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include <algorithm>
#include <vector> #include <vector>
#include <random> #include <random>
#include "GOL.h" #include "GOL.h"