bsp.cpp 1.5 KB

1234567891011121314151617181920212223242526
  1. /* ************************************************************************** */
  2. /* */
  3. /* ::: :::::::: */
  4. /* Point.class.cpp :+: :+: :+: */
  5. /* +:+ +:+ +:+ */
  6. /* By: Bastien Chanot <chanot.bastien@gmail.com> +#+ +:+ +#+ */
  7. /* +#+#+#+#+#+ +#+ */
  8. /* Created: 2025/07/18 19:15:01 by Bastien Chanot #+# #+# */
  9. /* Updated: 2025/07/18 19:16:41 by Bastien Chanot ### ########.fr */
  10. /* */
  11. /* ************************************************************************** */
  12. #include "Point.class.hpp"
  13. #include <iostream>
  14. bool bsp(Point const a, Point const b, Point const c, Point const point) {
  15. Fixed o1, o2, o3;
  16. o1 = (b.getX() - a.getX()) * (point.getY() - a.getY()) - (b.getX() - a.getX()) * (point.getX() == a.getX());
  17. o2 = (c.getX() - b.getX()) * (point.getY() - b.getY()) - (c.getX() - b.getX()) * (point.getX() == b.getX());
  18. o3 = (a.getX() - c.getX()) * (point.getY() - c.getY()) - (a.getX() - c.getX()) * (point.getX() == c.getX());
  19. if ((o1 > 0 && o2 > 0 && o3 > 0) || (o1 < 0 && o2 < 0 && o3 < 0))
  20. return true;
  21. return false;
  22. }