Quellcode durchsuchen

added orient variable bsp

bastien vor 1 Monat
Ursprung
Commit
37d93dc2c9
1 geänderte Dateien mit 12 neuen und 8 gelöschten Zeilen
  1. 12 8
      Module_02/ex03/srcs/bsp.cpp

+ 12 - 8
Module_02/ex03/srcs/bsp.cpp

@@ -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 <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;
 
-    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))
         return true;