Advertisement
gr4ph0s

Untitled

Dec 8th, 2017
355
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. BoundingBox Helper::GetBoundingBox(BaseBitmap* bmp, maxon::BaseArray<Vertex>& Vertices)
  2. {
  3. if (Vertices.GetCount() != 3)
  4. return BoundingBox();
  5.  
  6. Float xmax = maxon::Max(Vertices[0].GetX(), maxon::Max(Vertices[1].GetX(), Vertices[2].GetX()));
  7. Float xmin = maxon::Min(Vertices[0].GetX(), maxon::Min(Vertices[1].GetX(), Vertices[2].GetX()));
  8.  
  9. Float ymax = maxon::Max(Vertices[0].GetY(), maxon::Max(Vertices[1].GetY(), Vertices[2].GetY()));
  10. Float ymin = maxon::Min(Vertices[0].GetY(), maxon::Min(Vertices[1].GetY(), Vertices[2].GetY()));
  11.  
  12. if (xmax >= bmp->GetBw())
  13. xmax = bmp->GetBw();
  14.  
  15. if (ymax >= bmp->GetBh())
  16. ymax = bmp->GetBh();
  17.  
  18. return BoundingBox(ymin, xmin, ymax, xmax);
  19. }
  20.  
  21. Bool Helper::Intersect2D(const Vector& p1, const Vector& p2, const Vector& q1, const Vector& q2, Vector& out)
  22. {
  23. Float pa = p1.y - p2.y;
  24. Float pb = p2.x - p1.x;
  25. Float pc = p2.x * p1.y - p1.x * p2.y;
  26.  
  27. Float qa = q1.y - q2.y;
  28. Float qb = q2.x - q1.x;
  29. Float qc = q2.x * q1.y - q1.x * q2.y;
  30.  
  31. Float d = pa * qb - pb * qa;
  32. Float dx = pc * qb - pb * qc;
  33. Float dy = pa * qc - pc * qa;
  34.  
  35. // No Intersection
  36. if (d == 0)
  37. return false;
  38.  
  39. out = Vector(dx / d, dy / d, 0);
  40. return true;
  41. };
  42.  
  43. Bool Helper::IsPointInPath(const Float x, const Float y, maxon::BaseArray<Vertex>& V)
  44. {
  45. if (V.GetCount() != 3)
  46. return false;
  47.  
  48. Int i, j;
  49. Bool c = false;
  50.  
  51. for (Int i = 0, j = V.GetCount() - 1; i < V.GetCount(); j = i++)
  52. {
  53. if ((((V[i].GetY() <= y) && (y < V[j].GetY())) ||
  54. ((V[j].GetY() <= y) && (y < V[i].GetY()))) &&
  55. (x < (V[j].GetX() - V[i].GetX()) * (y - V[i].GetY()) / (V[j].GetY() - V[i].GetY()) + V[i].GetX()))
  56. c = !c;
  57. }
  58. return c;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement