|
@@ -1,24 +1,28 @@
|
|
|
/* ************************************************************************** */
|
|
/* ************************************************************************** */
|
|
|
/* */
|
|
/* */
|
|
|
/* ::: :::::::: */
|
|
/* ::: :::::::: */
|
|
|
-/* Point.class.cpp :+: :+: :+: */
|
|
|
|
|
|
|
+/* bsp.cpp :+: :+: :+: */
|
|
|
/* +:+ +:+ +:+ */
|
|
/* +:+ +:+ +:+ */
|
|
|
-/* By: Bastien Chanot <chanot.bastien@gmail.com> +#+ +:+ +#+ */
|
|
|
|
|
|
|
+/* By: bchanot <bchanot@42.fr> +#+ +:+ +#+ */
|
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
|
-/* Created: 2025/07/18 19:15:01 by Bastien Chanot #+# #+# */
|
|
|
|
|
-/* Updated: 2025/07/18 19:16:41 by Bastien Chanot ### ########.fr */
|
|
|
|
|
|
|
+/* Created: 2025/07/18 19:15:01 by Bastien Cha #+# #+# */
|
|
|
|
|
+/* Updated: 2025/12/18 13:11:51 by bchanot ### ########.fr */
|
|
|
/* */
|
|
/* */
|
|
|
/* ************************************************************************** */
|
|
/* ************************************************************************** */
|
|
|
|
|
|
|
|
#include "Point.class.hpp"
|
|
#include "Point.class.hpp"
|
|
|
#include <iostream>
|
|
#include <iostream>
|
|
|
|
|
|
|
|
-bool bsp(Point const a, Point const b, Point const c, Point const point) {
|
|
|
|
|
|
|
+Fixed orient(Point const & a, Point const & b, Point const & p) {
|
|
|
|
|
+ return (b.getX() - a.getX()) * (p.getY() - a.getY()) - (b.getY() - a.getY()) * (p.getX() - a.getX());
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool bsp(Point const & a, Point const & b, Point const & c, Point const & point) {
|
|
|
Fixed o1, o2, o3;
|
|
Fixed o1, o2, o3;
|
|
|
|
|
|
|
|
- o1 = (b.getX() - a.getX()) * (point.getY() - a.getY()) - (b.getX() - a.getX()) * (point.getX() == a.getX());
|
|
|
|
|
- o2 = (c.getX() - b.getX()) * (point.getY() - b.getY()) - (c.getX() - b.getX()) * (point.getX() == b.getX());
|
|
|
|
|
- o3 = (a.getX() - c.getX()) * (point.getY() - c.getY()) - (a.getX() - c.getX()) * (point.getX() == c.getX());
|
|
|
|
|
|
|
+ o1 = orient(a, b, point);
|
|
|
|
|
+ o2 = orient(b, c, point);
|
|
|
|
|
+ o3 = orient(c, a, point);
|
|
|
|
|
|
|
|
if ((o1 > 0 && o2 > 0 && o3 > 0) || (o1 < 0 && o2 < 0 && o3 < 0))
|
|
if ((o1 > 0 && o2 > 0 && o3 > 0) || (o1 < 0 && o2 < 0 && o3 < 0))
|
|
|
return true;
|
|
return true;
|