123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- #pragma once
- #include <Mathematics/IntrLine2Line2.h>
- #include <Mathematics/Segment.h>
- namespace WwiseGTE
- {
- template <typename Real>
- class TIQuery<Real, Line2<Real>, Segment2<Real>>
- {
- public:
- struct Result
- {
- bool intersect;
-
-
-
- int numIntersections;
- };
- Result operator()(Line2<Real> const& line, Segment2<Real> const& segment)
- {
- Result result;
- Vector2<Real> segOrigin, segDirection;
- Real segExtent;
- segment.GetCenteredForm(segOrigin, segDirection, segExtent);
- FIQuery<Real, Line2<Real>, Line2<Real>> llQuery;
- auto llResult = llQuery(line, Line2<Real>(segOrigin, segDirection));
- if (llResult.numIntersections == 1)
- {
-
- if (std::fabs(llResult.line1Parameter[0]) <= segExtent)
- {
- result.intersect = true;
- result.numIntersections = 1;
- }
- else
- {
- result.intersect = false;
- result.numIntersections = 0;
- }
- }
- else
- {
- result.intersect = llResult.intersect;
- result.numIntersections = llResult.numIntersections;
- }
- return result;
- }
- };
- template <typename Real>
- class FIQuery<Real, Line2<Real>, Segment2<Real>>
- {
- public:
- struct Result
- {
- bool intersect;
-
-
-
- int numIntersections;
-
-
-
-
-
-
-
-
- Real lineParameter[2], segmentParameter[2];
- Vector2<Real> point;
- };
- Result operator()(Line2<Real> const& line, Segment2<Real> const& segment)
- {
- Result result;
- Vector2<Real> segOrigin, segDirection;
- Real segExtent;
- segment.GetCenteredForm(segOrigin, segDirection, segExtent);
- FIQuery<Real, Line2<Real>, Line2<Real>> llQuery;
- auto llResult = llQuery(line, Line2<Real>(segOrigin, segDirection));
- if (llResult.numIntersections == 1)
- {
-
- if (std::fabs(llResult.line1Parameter[0]) <= segExtent)
- {
- result.intersect = true;
- result.numIntersections = 1;
- result.lineParameter[0] = llResult.line0Parameter[0];
- result.segmentParameter[0] = llResult.line1Parameter[0];
- result.point = llResult.point;
- }
- else
- {
- result.intersect = false;
- result.numIntersections = 0;
- }
- }
- else if (llResult.numIntersections == std::numeric_limits<int>::max())
- {
- result.intersect = true;
- result.numIntersections = std::numeric_limits<int>::max();
- Real maxReal = std::numeric_limits<Real>::max();
- result.lineParameter[0] = -maxReal;
- result.lineParameter[1] = +maxReal;
- result.segmentParameter[0] = -segExtent;
- result.segmentParameter[1] = +segExtent;
- }
- else
- {
- result.intersect = false;
- result.numIntersections = 0;
- }
- return result;
- }
- };
- }
|