mirror of
https://github.com/Ladebeze66/cpp-partie-1.git
synced 2026-11-09 13:17:15 +01:00
ccp
This commit is contained in:
18
cpp02/ex03/.vscode/c_cpp_properties.json
vendored
Normal file
18
cpp02/ex03/.vscode/c_cpp_properties.json
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"configurations": [
|
||||
{
|
||||
"name": "linux-gcc-x64",
|
||||
"includePath": [
|
||||
"${workspaceFolder}/**"
|
||||
],
|
||||
"compilerPath": "/usr/bin/gcc",
|
||||
"cStandard": "${default}",
|
||||
"cppStandard": "${default}",
|
||||
"intelliSenseMode": "linux-gcc-x64",
|
||||
"compilerArgs": [
|
||||
""
|
||||
]
|
||||
}
|
||||
],
|
||||
"version": 4
|
||||
}
|
||||
24
cpp02/ex03/.vscode/launch.json
vendored
Normal file
24
cpp02/ex03/.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "C/C++ Runner: Debug Session",
|
||||
"type": "cppdbg",
|
||||
"request": "launch",
|
||||
"args": [],
|
||||
"stopAtEntry": false,
|
||||
"externalConsole": false,
|
||||
"cwd": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp02/ex03",
|
||||
"program": "/home/fgras-ca/Bureau/fgras-ca/CPP/cpp02/ex03/build/Debug/outDebug",
|
||||
"MIMode": "gdb",
|
||||
"miDebuggerPath": "gdb",
|
||||
"setupCommands": [
|
||||
{
|
||||
"description": "Enable pretty-printing for gdb",
|
||||
"text": "-enable-pretty-printing",
|
||||
"ignoreFailures": true
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
59
cpp02/ex03/.vscode/settings.json
vendored
Normal file
59
cpp02/ex03/.vscode/settings.json
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
{
|
||||
"C_Cpp_Runner.cCompilerPath": "gcc",
|
||||
"C_Cpp_Runner.cppCompilerPath": "g++",
|
||||
"C_Cpp_Runner.debuggerPath": "gdb",
|
||||
"C_Cpp_Runner.cStandard": "",
|
||||
"C_Cpp_Runner.cppStandard": "",
|
||||
"C_Cpp_Runner.msvcBatchPath": "",
|
||||
"C_Cpp_Runner.useMsvc": false,
|
||||
"C_Cpp_Runner.warnings": [
|
||||
"-Wall",
|
||||
"-Wextra",
|
||||
"-Wpedantic",
|
||||
"-Wshadow",
|
||||
"-Wformat=2",
|
||||
"-Wcast-align",
|
||||
"-Wconversion",
|
||||
"-Wsign-conversion",
|
||||
"-Wnull-dereference"
|
||||
],
|
||||
"C_Cpp_Runner.msvcWarnings": [
|
||||
"/W4",
|
||||
"/permissive-",
|
||||
"/w14242",
|
||||
"/w14287",
|
||||
"/w14296",
|
||||
"/w14311",
|
||||
"/w14826",
|
||||
"/w44062",
|
||||
"/w44242",
|
||||
"/w14905",
|
||||
"/w14906",
|
||||
"/w14263",
|
||||
"/w44265",
|
||||
"/w14928"
|
||||
],
|
||||
"C_Cpp_Runner.enableWarnings": true,
|
||||
"C_Cpp_Runner.warningsAsError": false,
|
||||
"C_Cpp_Runner.compilerArgs": [],
|
||||
"C_Cpp_Runner.linkerArgs": [],
|
||||
"C_Cpp_Runner.includePaths": [],
|
||||
"C_Cpp_Runner.includeSearch": [
|
||||
"*",
|
||||
"**/*"
|
||||
],
|
||||
"C_Cpp_Runner.excludeSearch": [
|
||||
"**/build",
|
||||
"**/build/**",
|
||||
"**/.*",
|
||||
"**/.*/**",
|
||||
"**/.vscode",
|
||||
"**/.vscode/**"
|
||||
],
|
||||
"C_Cpp_Runner.useAddressSanitizer": false,
|
||||
"C_Cpp_Runner.useUndefinedSanitizer": false,
|
||||
"C_Cpp_Runner.useLeakSanitizer": false,
|
||||
"C_Cpp_Runner.showCompilationTime": false,
|
||||
"C_Cpp_Runner.useLinkTimeOptimization": false,
|
||||
"C_Cpp_Runner.msvcSecureNoWarnings": false
|
||||
}
|
||||
171
cpp02/ex03/Fixed.cpp
Normal file
171
cpp02/ex03/Fixed.cpp
Normal file
@@ -0,0 +1,171 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Fixed.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/27 20:32:07 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/27 22:42:03 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Fixed.hpp"
|
||||
|
||||
#define RESET "\033[0m"
|
||||
#define RED "\033[31m"
|
||||
#define GREEN "\033[32m"
|
||||
#define YELLOW "\033[33m"
|
||||
#define CYAN "\033[36m"
|
||||
#define BLUE "\033[34m"
|
||||
|
||||
// Constructeur par défaut
|
||||
Fixed::Fixed() : value(0)
|
||||
{
|
||||
std::cout << GREEN << "Default constructor called" << RESET << std::endl;
|
||||
}
|
||||
|
||||
// Constructeur avec un entier
|
||||
Fixed::Fixed(const int intValue) : value(intValue << fractionalBits)
|
||||
{
|
||||
std::cout << CYAN << "Int constructor called" << RESET << std::endl;
|
||||
}
|
||||
|
||||
// Constructeur avec un flottant
|
||||
Fixed::Fixed(const float floatValue) : value(roundf(floatValue * (1 << fractionalBits))) {}
|
||||
|
||||
// Constructeur de recopie
|
||||
Fixed::Fixed(const Fixed &other) : value(other.value) {}
|
||||
|
||||
// Opérateur d'affectation
|
||||
Fixed &Fixed::operator=(const Fixed &other)
|
||||
{
|
||||
std::cout << YELLOW << "Copy assignment operator called" << RESET << std::endl;
|
||||
if (this != &other)
|
||||
{
|
||||
this->value = other.value;
|
||||
}
|
||||
return (*this);
|
||||
}
|
||||
|
||||
// Destructeur
|
||||
Fixed::~Fixed() {}
|
||||
|
||||
// Conversion en flottant
|
||||
float Fixed::toFloat(void) const
|
||||
{
|
||||
return ((float)value / (float)(1 << fractionalBits));
|
||||
}
|
||||
|
||||
// Conversion en entier
|
||||
int Fixed::toInt(void) const
|
||||
{
|
||||
return (value >> fractionalBits);
|
||||
}
|
||||
|
||||
// Opérateur de sortie
|
||||
std::ostream &operator<<(std::ostream &stream, const Fixed &fixed)
|
||||
{
|
||||
stream << fixed.toFloat();
|
||||
return (stream);
|
||||
}
|
||||
|
||||
// Opérateurs de comparaison
|
||||
bool Fixed::operator>(const Fixed &other) const
|
||||
{
|
||||
return (this->value > other.value);
|
||||
}
|
||||
|
||||
bool Fixed::operator<(const Fixed &other) const
|
||||
{
|
||||
return (this->value < other.value);
|
||||
}
|
||||
|
||||
bool Fixed::operator<=(const Fixed &other) const
|
||||
{
|
||||
return (this->value <= other.value);
|
||||
}
|
||||
|
||||
bool Fixed::operator>=(const Fixed &other) const
|
||||
{
|
||||
return (this->value >= other.value);
|
||||
}
|
||||
|
||||
bool Fixed::operator==(const Fixed &other) const
|
||||
{
|
||||
return (this->value == other.value);
|
||||
}
|
||||
|
||||
bool Fixed::operator!=(const Fixed &other) const
|
||||
{
|
||||
return (this->value != other.value);
|
||||
}
|
||||
|
||||
// Opérateurs arithmétiques (exemple avec +, -, *, /)
|
||||
Fixed Fixed::operator+(const Fixed &other) const
|
||||
{
|
||||
return (Fixed(this->toFloat() + other.toFloat()));
|
||||
}
|
||||
|
||||
Fixed Fixed::operator-(const Fixed &other) const
|
||||
{
|
||||
return (Fixed(this->toFloat() - other.toFloat()));
|
||||
}
|
||||
|
||||
Fixed Fixed::operator*(const Fixed &other) const
|
||||
{
|
||||
return (Fixed(this->toFloat() * other.toFloat()));
|
||||
}
|
||||
|
||||
Fixed Fixed::operator/(const Fixed &other) const
|
||||
{
|
||||
return (Fixed(this->toFloat() / other.toFloat()));
|
||||
}
|
||||
|
||||
// Opérateurs d'incrémentation et de décrémentation
|
||||
Fixed Fixed::operator++()
|
||||
{
|
||||
this->value++;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Fixed Fixed::operator++(int)
|
||||
{
|
||||
Fixed temp = *this;
|
||||
++(*this);
|
||||
return (temp);
|
||||
}
|
||||
|
||||
Fixed Fixed::operator--()
|
||||
{
|
||||
this->value--;
|
||||
return (*this);
|
||||
}
|
||||
|
||||
Fixed Fixed::operator--(int)
|
||||
{
|
||||
Fixed temp = *this;
|
||||
--(*this);
|
||||
return (temp);
|
||||
}
|
||||
|
||||
// Fonctions membres statiques min/max
|
||||
Fixed &Fixed::min(Fixed &a, Fixed &b)
|
||||
{
|
||||
return ((a < b) ? a : b);
|
||||
}
|
||||
|
||||
const Fixed &Fixed::min(const Fixed &a, const Fixed &b)
|
||||
{
|
||||
return ((a < b) ? a : b);
|
||||
}
|
||||
|
||||
Fixed &Fixed::max(Fixed &a, Fixed &b)
|
||||
{
|
||||
return ((a > b) ? a : b);
|
||||
}
|
||||
|
||||
const Fixed &Fixed::max(const Fixed &a, const Fixed &b)
|
||||
{
|
||||
return ((a > b) ? a : b);
|
||||
}
|
||||
64
cpp02/ex03/Fixed.hpp
Normal file
64
cpp02/ex03/Fixed.hpp
Normal file
@@ -0,0 +1,64 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Fixed.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/27 20:12:09 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/27 21:26:38 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef FIXED_H
|
||||
#define FIXED_H
|
||||
|
||||
#include <iostream>
|
||||
#include <cmath> // Pour roundf
|
||||
|
||||
class Fixed
|
||||
{
|
||||
public:
|
||||
Fixed(); // Constructeur par défaut
|
||||
Fixed(const int intValue); // Constructeur avec un entier
|
||||
Fixed(const float floatValue); // Constructeur avec un flottant
|
||||
Fixed(const Fixed &other); // Constructeur de recopie
|
||||
Fixed &operator=(const Fixed &other); // Opérateur d'affectation
|
||||
~Fixed(); // Destructeur
|
||||
|
||||
float toFloat(void) const; // Convertit en flottant
|
||||
int toInt(void) const; // Convertit en entier
|
||||
// Surcharge des opérateurs de comparaison
|
||||
bool operator>(const Fixed &other) const;
|
||||
bool operator<(const Fixed &other) const;
|
||||
bool operator<=(const Fixed &other) const;
|
||||
bool operator>=(const Fixed &other) const;
|
||||
bool operator==(const Fixed &other) const;
|
||||
bool operator!=(const Fixed &other) const;
|
||||
|
||||
// Surcharge des opérateurs arithmétiques
|
||||
Fixed operator+(const Fixed &other) const;
|
||||
Fixed operator-(const Fixed &other) const;
|
||||
Fixed operator*(const Fixed &other) const;
|
||||
Fixed operator/(const Fixed &other) const;
|
||||
|
||||
// Surcharge des opérateurs d'incrémentation et de décrémentation
|
||||
Fixed operator++(); // Pré-incrémentation
|
||||
Fixed operator++(int); // Post-incrémentation
|
||||
Fixed operator--(int);
|
||||
Fixed operator--();
|
||||
|
||||
// Fonctions membres statiques
|
||||
static Fixed &min(Fixed &a, Fixed &b);
|
||||
static const Fixed &min(const Fixed &a, const Fixed &b);
|
||||
static Fixed &max(Fixed &a, Fixed &b);
|
||||
static const Fixed &max(const Fixed &a, const Fixed &b);
|
||||
|
||||
private:
|
||||
int value; // Valeur du nombre à virgule fixe
|
||||
static const int fractionalBits = 8; // Nombre de bits de la partie fractionnaire
|
||||
};
|
||||
|
||||
std::ostream &operator<<(std::ostream &stream, const Fixed &fixed); // Surcharge de l'opérateur d’insertion << ésentation en virgule flottante du nombre à virgule fixe dans le flux de sortie (objet output stream)
|
||||
|
||||
#endif
|
||||
BIN
cpp02/ex03/Fixed.o
Normal file
BIN
cpp02/ex03/Fixed.o
Normal file
Binary file not shown.
64
cpp02/ex03/Makefile
Normal file
64
cpp02/ex03/Makefile
Normal file
@@ -0,0 +1,64 @@
|
||||
# **************************************************************************** #
|
||||
# #
|
||||
# ::: :::::::: #
|
||||
# Makefile :+: :+: :+: #
|
||||
# +:+ +:+ +:+ #
|
||||
# By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ #
|
||||
# +#+#+#+#+#+ +#+ #
|
||||
# Created: 2023/12/27 20:57:42 by fgras-ca #+# #+# #
|
||||
# Updated: 2023/12/27 22:09:54 by fgras-ca ### ########.fr #
|
||||
# #
|
||||
# **************************************************************************** #
|
||||
|
||||
LOGO = @echo " __, ____, ____, ____, ____ ____, ___, ____,";\
|
||||
echo "(-| (-/_| (-| \ (-|_, (-|__) (-|_, (- / (-|_,";\
|
||||
echo " _|__, _/ |, _|__/ _|__, _|__) _|__, _/__, _|__,";\
|
||||
echo "( ( ( ( ( ( ( ("
|
||||
|
||||
DEF_COLOR = \033[0m
|
||||
GRAY = \033[0;90m
|
||||
RED = \033[0;91m
|
||||
GREEN = \033[0;92m
|
||||
YELLOW = \033[0;93m
|
||||
BLUE = \033[0;94m
|
||||
MAGENTA = \033[0;95m
|
||||
CYAN = \033[0;96m
|
||||
WHITE = \033[0;97m
|
||||
ORANGE = \033[38;5;214m
|
||||
|
||||
NAME = bsp
|
||||
|
||||
SRC = Fixed.cpp \
|
||||
bsp.cpp \
|
||||
Point.cpp \
|
||||
main.cpp \
|
||||
|
||||
OBJS = ${SRC:.cpp=.o}
|
||||
|
||||
CC = c++
|
||||
CFLAGS = -Wall -Werror -Wextra -std=c++98
|
||||
RM = rm -f
|
||||
|
||||
all : $(NAME)
|
||||
|
||||
$(NAME) : $(OBJS)
|
||||
@echo "$(RED)Compilation fixed... $(DEF_COLOR)"
|
||||
$(CC) $(CFLAGS) $(OBJS) -g -o $(NAME)
|
||||
@echo "$(GREEN)Compilation complete. $(ORANGE)Type "./bsp" to execute the program!!$(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
clean :
|
||||
@echo "$(RED)Deleating files objects... $(DEF_COLOR)"
|
||||
$(RM) $(OBJS)
|
||||
@echo "$(GREEN)files deleted!! $(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
fclean : clean
|
||||
@echo "$(RED)Delete program name... $(DEF_COLOR)"
|
||||
$(RM) $(NAME)
|
||||
@echo "$(GREEN)File program deleted!! $(DEF_COLOR)"
|
||||
$(LOGO)
|
||||
|
||||
re : fclean all
|
||||
|
||||
.PHONY : all clean fclean re
|
||||
63
cpp02/ex03/Point.cpp
Normal file
63
cpp02/ex03/Point.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Point.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/27 22:06:12 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/27 22:38:12 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Point.hpp"
|
||||
|
||||
// Définitions de couleur pour les logs
|
||||
#define RESET "\033[0m"
|
||||
#define RED "\033[31m"
|
||||
#define GREEN "\033[32m"
|
||||
#define YELLOW "\033[33m"
|
||||
#define CYAN "\033[36m"
|
||||
|
||||
// Constructeur par défaut
|
||||
Point::Point() : x(0), y(0)
|
||||
{
|
||||
std::cout << GREEN << "Default constructor called (Point):\n x(0), y(0)" << RESET << std::endl;
|
||||
}
|
||||
|
||||
// Constructeur qui initialise x et y avec des flottants
|
||||
Point::Point(float const xVal, float const yVal) : x(xVal), y(yVal)
|
||||
{
|
||||
std::cout << CYAN << "Float constructor called (Point):\n x(" << xVal << "), y(" << yVal << ")" << RESET << std::endl;
|
||||
}
|
||||
|
||||
// Constructeur de recopie
|
||||
Point::Point(Point const &other) : x(other.getX()), y(other.getY())
|
||||
{
|
||||
std::cout << YELLOW << "Copy constructor called (Point):\n x(" << other.getX() << "), y(" << other.getY() << ")" << RESET << std::endl;
|
||||
}
|
||||
|
||||
// Opérateur d'affectation
|
||||
Point &Point::operator=(Point const &other)
|
||||
{
|
||||
// Comme x et y sont constants, ils ne peuvent être réaffectés.
|
||||
std::cout << RED << "Attempt to use copy assignment operator on Point, which is not allowed due to const members." << RESET << std::endl;
|
||||
return (*this); // Retourne une référence à l'instance actuelle
|
||||
}
|
||||
|
||||
// Destructeur
|
||||
Point::~Point()
|
||||
{
|
||||
std::cout << RED << "Destructor called (Point):\n x(" << this->x << "), y(" << this->y << ")" << RESET << std::endl;
|
||||
}
|
||||
|
||||
// Getters pour accéder aux coordonnées x et y
|
||||
Fixed Point::getX() const
|
||||
{
|
||||
return (this->x);
|
||||
}
|
||||
|
||||
Fixed Point::getY() const
|
||||
{
|
||||
return (this->y);
|
||||
}
|
||||
36
cpp02/ex03/Point.hpp
Normal file
36
cpp02/ex03/Point.hpp
Normal file
@@ -0,0 +1,36 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* Point.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/27 21:52:45 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/27 22:23:40 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef POINT_HPP
|
||||
#define POINT_HPP
|
||||
|
||||
#include "Fixed.hpp"
|
||||
|
||||
class Point
|
||||
{
|
||||
public:
|
||||
Point(); // Constructeur par défaut
|
||||
Point(float const x, float const y); // Constructeur avec deux flottants
|
||||
Point(Point const &other); // Constructeur de recopie
|
||||
Point &operator=(Point const &other); // Opérateur d'affectation
|
||||
~Point(); // Destructeur
|
||||
|
||||
// Getters pour accéder aux coordonnées x et y
|
||||
Fixed getX() const;
|
||||
Fixed getY() const;
|
||||
|
||||
private:
|
||||
Fixed const x; // Coordonnée x du point
|
||||
Fixed const y; // Coordonnée y du point
|
||||
};
|
||||
|
||||
#endif
|
||||
BIN
cpp02/ex03/Point.o
Normal file
BIN
cpp02/ex03/Point.o
Normal file
Binary file not shown.
BIN
cpp02/ex03/bsp
Executable file
BIN
cpp02/ex03/bsp
Executable file
Binary file not shown.
34
cpp02/ex03/bsp.cpp
Normal file
34
cpp02/ex03/bsp.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* bsp.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/27 21:59:43 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/27 22:22:35 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "bsp.hpp"
|
||||
|
||||
float sign(Point p1, Point p2, Point p3)
|
||||
{
|
||||
Fixed result = (p1.getX() - p3.getX()) * (p2.getY() - p3.getY()) - (p2.getX() - p3.getX()) * (p1.getY() - p3.getY());
|
||||
return (result.toFloat()); // Convertit le résultat Fixed en float
|
||||
}
|
||||
|
||||
bool bsp(Point const a, Point const b, Point const c, Point const point)
|
||||
{
|
||||
float d1, d2, d3;
|
||||
bool has_neg, has_pos;
|
||||
|
||||
d1 = sign(point, a, b);
|
||||
d2 = sign(point, b, c);
|
||||
d3 = sign(point, c, a);
|
||||
|
||||
has_neg = (d1 < 0) || (d2 < 0) || (d3 < 0);
|
||||
has_pos = (d1 > 0) || (d2 > 0) || (d3 > 0);
|
||||
|
||||
return (!(has_neg && has_pos));
|
||||
}
|
||||
21
cpp02/ex03/bsp.hpp
Normal file
21
cpp02/ex03/bsp.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* bsp.hpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/27 22:15:54 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/27 22:17:48 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#ifndef BSP_HPP
|
||||
# define BSP_HPP
|
||||
|
||||
#include "Point.hpp"
|
||||
|
||||
float sign(Point p1, Point p2, Point p3);
|
||||
bool bsp(Point const a, Point const b, Point const c, Point const point);
|
||||
|
||||
#endif
|
||||
BIN
cpp02/ex03/bsp.o
Normal file
BIN
cpp02/ex03/bsp.o
Normal file
Binary file not shown.
49
cpp02/ex03/main.cpp
Normal file
49
cpp02/ex03/main.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* main.cpp :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: fgras-ca <fgras-ca@student.42.fr> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/12/27 22:11:13 by fgras-ca #+# #+# */
|
||||
/* Updated: 2023/12/27 22:42:40 by fgras-ca ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "Point.hpp"
|
||||
#include "bsp.hpp"
|
||||
|
||||
// Fonction pour demander un point à l'utilisateur
|
||||
Point demanderPoint(const std::string &nomPoint)
|
||||
{
|
||||
float x, y;
|
||||
std::cout << "Entrez la coordonnée x de " << nomPoint << ": ";
|
||||
std::cin >> x;
|
||||
std::cout << "Entrez la coordonnée y de " << nomPoint << ": ";
|
||||
std::cin >> y;
|
||||
return (Point(x, y));
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
// Test fixe : Créer un triangle et un point, puis tester avec la fonction bsp
|
||||
Point a(0.0f, 0.0f);
|
||||
Point b(1.0f, 0.0f);
|
||||
Point c(0.5f, 1.0f);
|
||||
Point pointFixe(0.5f, 0.5f);
|
||||
|
||||
std::cout << "Test fixe:" << std::endl;
|
||||
std::cout << "Point à l'intérieur du triangle (0.5, 0.5) : \n" << (bsp(a, b, c, pointFixe) ? "Oui" : "Non") << std::endl;
|
||||
|
||||
// Test dynamique : Demander à l'utilisateur de saisir les points
|
||||
std::cout << "\nTest dynamique:" << std::endl;
|
||||
Point aUser = demanderPoint("A");
|
||||
Point bUser = demanderPoint("B");
|
||||
Point cUser = demanderPoint("C");
|
||||
Point pointUser = demanderPoint("Point à tester");
|
||||
|
||||
// Afficher si le point est à l'intérieur du triangle ou non
|
||||
std::cout << "Le point est à l'intérieur du triangle : " << (bsp(aUser, bUser, cUser, pointUser) ? "Oui" : "Non") << std::endl;
|
||||
|
||||
return (0);
|
||||
}
|
||||
BIN
cpp02/ex03/main.o
Normal file
BIN
cpp02/ex03/main.o
Normal file
Binary file not shown.
Reference in New Issue
Block a user