1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38<snippet>
<content><![CDATA[
// Given three collinear points p, q, r, the function checks if point q lies on line segment 'pr'
bool onsegment(pair<int, int> p, pair<int, int> q, pair<int, int> r)
{
if (q.first <= max(p.second, r.first) && q.first >= min(p.first, r.first) &&
q.second <= max(p.second, r.second) && q.second >= min(p.second, r.second))
return true;
return false;
}
// To find orientation of ordered triplet (p, q, r). // The function returns following values
// 0 --> p, q and r are collinear
// 1 --> Clockwise
// 2 --> Counterclockwise
int orientation(pair<int, int> p, pair<int, int> q, pair<int, int> r)
{
int val = (q.second - p.second) * (r.first - q.first) -
(q.first - p.first) * (r.second - q.second);
if (val == 0) return 0; // collinear
return (val > 0) ? 1 : 2; // clock or counterclock wise
}
]]></content>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<tabTrigger>geometry</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.c++</scope>
</snippet>