File: ConvexClipper.cpp

package info (click to toggle)
libwildmagic 5.17%2Bcleaned1-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye
  • size: 90,112 kB
  • sloc: cpp: 215,940; csh: 637; sh: 91; makefile: 39
file content (730 lines) | stat: -rw-r--r-- 23,862 bytes parent folder | download | duplicates (3)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
// Geometric Tools, LLC
// Copyright (c) 1998-2014
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
//
// File Version: 5.0.1 (2012/07/08)

#include "ConvexClipper.h"
#include "ConvexPolyhedron.h"

//----------------------------------------------------------------------------
template <typename Real>
ConvexClipper<Real>::ConvexClipper (const ConvexPolyhedron<Real>& polyhedron,
    Real epsilon)
    :
    mEpsilon(epsilon)
{
    const std::vector<Vector3<Real> >& points = polyhedron.GetPoints();
    int numVertices = polyhedron.GetNumVertices();
    mVertices.resize(numVertices);
    for (int v = 0; v < numVertices; ++v)
    {
        mVertices[v].Point = points[v];
    }

    int numEdges = polyhedron.GetNumEdges();
    mEdges.resize(numEdges);
    for (int e = 0; e < numEdges; ++e)
    {
        const MTEdge& edge = polyhedron.GetEdge(e);
        for (int i = 0; i < 2; ++i)
        {
            mEdges[e].Vertex[i] = polyhedron.GetVLabel(edge.GetVertex(i));
            mEdges[e].Face[i] = edge.GetTriangle(i);
        }
    }

    int numTriangles = polyhedron.GetNumTriangles();
    mFaces.resize(numTriangles);
    for (int t = 0; t < numTriangles; ++t)
    {
        mFaces[t].Plane = polyhedron.GetPlane(t);
        const MTTriangle& triangle = polyhedron.GetTriangle(t);
        for (int i = 0; i < 3; ++i)
        {
            mFaces[t].Edges.insert(triangle.GetEdge(i));
        }
    }
}
//----------------------------------------------------------------------------
template <typename Real>
int ConvexClipper<Real>::Clip (const Plane3<Real>& plane)
{
    // Compute signed distances from vertices to plane.
    int numPositive = 0, numNegative = 0, numZero = 0;
    const int numVertices = (int)mVertices.size();
    for (int v = 0; v < numVertices; ++v)
    {
        Vertex& vertex = mVertices[v];
        if (vertex.Visible)
        {
            vertex.Distance = plane.DistanceTo(vertex.Point);
            if (vertex.Distance > mEpsilon)
            {
                ++numPositive;
            }
            else if (vertex.Distance < -mEpsilon)
            {
                ++numNegative;
                vertex.Visible = false;
            }
            else
            {
                // The point is on the plane (within floating point
                // tolerance).
                ++numZero;
                vertex.Distance = (Real)0;
            }
        }
    }

    if (numPositive == 0)
    {
        // Mesh is in negative half-space, fully clipped.
        return -1;
    }

    if (numNegative == 0)
    {
        // Mesh is in positive half-space, fully visible.
        return +1;
    }

    // Clip the visible edges.
    const int numEdges = (int)mEdges.size();
    for (int e = 0; e < numEdges; ++e)
    {
        Edge& edge = mEdges[e];
        if (edge.Visible)
        {
            int v0 = edge.Vertex[0];
            int v1 = edge.Vertex[1];
            int f0 = edge.Face[0];
            int f1 = edge.Face[1];
            Face& face0 = mFaces[f0];
            Face& face1 = mFaces[f1];
            Real d0 = mVertices[v0].Distance;
            Real d1 = mVertices[v1].Distance;

            if (d0 <= (Real)0 && d1 <= (Real)0)
            {
                // The edge is culled.  If the edge is exactly on the clip
                // plane, it is possible that a visible triangle shares it.
                // The edge will be re-added during the face loop.
                face0.Edges.erase(e);
                if (face0.Edges.empty())
                {
                    face0.Visible = false;
                }

                face1.Edges.erase(e);
                if (face1.Edges.empty())
                {
                    face1.Visible = false;
                }

                edge.Visible = false;
                continue;
            }

            if (d0 >= (Real)0 && d1 >= (Real)0)
            {
                // Face retains the edge.
                continue;
            }

            // The edge is split by the plane.  Compute the point of
            // intersection.  If the old edge is <V0,V1> and I is the
            // intersection point, the new edge is <V0,I> when d0 > 0 or
            // <I,V1> when d1 > 0.
            int vNew = (int)mVertices.size();
            mVertices.push_back(Vertex());
            Vertex& vertexNew = mVertices[vNew];

            Vector3<Real>& point0 = mVertices[v0].Point;
            Vector3<Real>& point1 = mVertices[v1].Point;
            vertexNew.Point = point0 + (d0/(d0 - d1))*(point1 - point0);

            if (d0 > (Real)0)
            {
                edge.Vertex[1] = vNew;
            }
            else
            {
                edge.Vertex[0] = vNew;
            }
        }
    }

    // The mesh straddles the plane.  A new convex polygonal face will be
    // generated.  Add it now and insert edges when they are visited.
    int fNew = (int)mFaces.size();
    mFaces.push_back(Face());
    Face& faceNew = mFaces[fNew];
    faceNew.Plane = plane;

    // Process the faces.
    for (int f = 0; f < fNew; ++f)
    {
        Face& face = mFaces[f];
        if (face.Visible)
        {
            // Determine if the face is on the negative side, the positive
            // side, or split by the clipping plane.  The Occurs members
            // are set to zero to help find the end points of the polyline
            // that results from clipping a face.
            assertion(face.Edges.size() >= 2, "Unexpected condition.\n");
            std::set<int>::iterator iter = face.Edges.begin();
            std::set<int>::iterator end = face.Edges.end();
            while (iter != end)
            {
                int e = *iter++;
                Edge& edge = mEdges[e];
                assertion(edge.Visible, "Unexpected condition.\n");
                mVertices[edge.Vertex[0]].Occurs = 0;
                mVertices[edge.Vertex[1]].Occurs = 0;
            }

            int vStart, vFinal;
            if (GetOpenPolyline(face, vStart, vFinal))
            {
                // Polyline is open, close it up.
                int eNew = (int)mEdges.size();
                mEdges.push_back(Edge());
                Edge& edgeNew = mEdges[eNew];

                edgeNew.Vertex[0] = vStart;
                edgeNew.Vertex[1] = vFinal;
                edgeNew.Face[0] = f;
                edgeNew.Face[1] = fNew;

                // Add new edge to polygons.
                face.Edges.insert(eNew);
                faceNew.Edges.insert(eNew);
            }
        }
    }

    // Process 'faceNew' to make sure it is a simple polygon (theoretically
    // convex, but numerically may be slightly not convex).  Floating-point
    // round-off errors can cause the new face from the last loop to be
    // needle-like with a collapse of two edges into a single edge.  This
    // block guarantees the invariant "face always a simple polygon".
    Postprocess(fNew, faceNew);
    if (faceNew.Edges.size() < 3)
    {
        // Face is completely degenerate, remove it from mesh.
        mFaces.pop_back();
    }

    return 0;
}
//----------------------------------------------------------------------------
template <typename Real>
void ConvexClipper<Real>::Convert (ConvexPolyhedron<Real>& polyhedron)
{
    // Get visible vertices.
    int numVertices = (int)mVertices.size();
    std::vector<Vector3<Real> > points;
    int* vMap = new1<int>(numVertices);
    memset(vMap, 0xFF, numVertices*sizeof(int));
    for (int v = 0; v < numVertices; ++v)
    {
        const Vertex& vertex = mVertices[v];
        if (vertex.Visible)
        {
            vMap[v] = (int)points.size();
            points.push_back(vertex.Point);
        }
    }

    std::vector<int> indices;
    std::vector<Plane3<Real> > planes;
    GetTriangles(indices, planes);

    // Reorder the indices.
    for (int c = 0; c < (int)indices.size(); ++c)
    {
        int oldC = indices[c];
        assertion(0 <= oldC && oldC < numVertices, "Index out of range.\n");
        int newC = vMap[oldC];
        assertion(0 <= newC && newC < (int)points.size(),
            "Index out of range.\n");
        indices[c] = newC;
    }

    delete1(vMap);

    polyhedron.Create(points, indices, planes);
}
//----------------------------------------------------------------------------
template <typename Real>
bool ConvexClipper<Real>::Print (const char* filename) const
{
    std::ofstream outFile(filename);
    if (!outFile)
    {
        return false;
    }

    const int numVertices = (int)mVertices.size();
    const int numEdges = (int)mEdges.size();
    const int numFaces = (int)mFaces.size();
    const int vDigits = (int)(ceil(log10((double)numVertices)));
    const int eDigits = (int)(ceil(log10((double)numEdges)));
    const int fDigits = (int)(ceil(log10((double)numFaces)));
    char message[1024];

    outFile << numVertices << " vertices" << std::endl;
    for (int v = 0; v < numVertices; ++v)
    {
        const Vertex& vertex = mVertices[v];
        sprintf(message, "v<%*d> %c: (%f,%f,%f)",
            vDigits, v, (vertex.Visible ? 'T' : 'F'), vertex.Point.X(),
            vertex.Point.Y(), vertex.Point.Z());
        outFile << message << std::endl;
    }
    outFile << std::endl;

    outFile << numEdges << " edges" << std::endl;
    for (int e = 0; e < numEdges; ++e)
    {
        const Edge& edge = mEdges[e];
        sprintf(message, "e<%*d> %c: v[%*d,%*d], t[%*d,%*d]",
            eDigits, e, (edge.Visible ? 'T' : 'F'), vDigits, edge.Vertex[0],
            vDigits, edge.Vertex[1], fDigits, edge.Face[0], fDigits,
            edge.Face[1]);
        outFile << message << std::endl;
    }
    outFile << std::endl;

    outFile << numFaces << " faces" << std::endl;
    for (int f = 0; f < numFaces; ++f)
    {
        const Face& face = mFaces[f];
        sprintf(message, "t<%*d> %d: e = ",
            fDigits, f, (face.Visible ? 'T' : 'F'));
        outFile << message;

        std::set<int>::const_iterator iter = face.Edges.begin();
        std::set<int>::const_iterator end = face.Edges.end();
        while (iter != end)
        {
            outFile << *iter << ' ';
            iter++;
        }
        outFile << std::endl;
    }

    return true;
}
//----------------------------------------------------------------------------
template <typename Real>
void ConvexClipper<Real>::Postprocess (int fNew, Face& faceNew)
{
    const int numEdges = (int)faceNew.Edges.size();
    std::vector<EdgePlus> edges(numEdges);
    std::set<int>::iterator iter = faceNew.Edges.begin();
    std::set<int>::iterator end = faceNew.Edges.end();
    int i = 0;
    while (iter != end)
    {
        int e = *iter++;
        edges[i++] = EdgePlus(e, mEdges[e]);
    }
    std::sort(edges.begin(), edges.end());

    // Process duplicate edges.
    for (int i0 = 0, i1 = 1; i1 < numEdges; i0 = i1++)
    {
        if (edges[i0] == edges[i1])
        {
            // Found two equivalent edges (same vertex end points).
#ifdef _DEBUG
            int i2 = i1 + 1;
            if (i2 < numEdges)
            {
                // Make sure an edge occurs at most twice.  If not, then
                // algorithm needs to be modified to handle it.
                assertion(edges[i1] != edges[i2], "Unexpected condition.\n");
            }
#endif
            // Edge E0 has vertices V0, V1 and faces F0, NF.  Edge E1 has
            // vertices V0, V1 and faces F1, NF.
            int e0 = edges[i0].E;
            int e1 = edges[i1].E;
            Edge& edge0 = mEdges[e0];
            Edge& edge1 = mEdges[e1];

            // Remove E0 and E1 from faceNew.
            faceNew.Edges.erase(e0);
            faceNew.Edges.erase(e1);

            // Remove faceNew from E0.
            if (edge0.Face[0] == fNew)
            {
                edge0.Face[0] = edge0.Face[1];
            }
            else
            {
                assertion(edge0.Face[1] == fNew, "Unexpected condition.\n");
            }
            edge0.Face[1] = -1;

            // Remove faceNew from E1.
            if (edge1.Face[0] == fNew)
            {
                edge1.Face[0] = edge1.Face[1];
            }
            else
            {
                assertion(edge1.Face[1] == fNew, "Unexpected condition.\n");
            }
            edge1.Face[1] = -1;

            // E2 is being booted from the system.  Update the face F1 that
            // shares it.  Update E1 to share F1.
            int f1 = edge1.Face[0];
            Face& face1 = mFaces[f1];
            face1.Edges.erase(e1);
            face1.Edges.insert(e0);
            edge0.Face[1] = f1;
            edge1.Visible = false;
        }
    }
}
//----------------------------------------------------------------------------
template <typename Real>
bool ConvexClipper<Real>::GetOpenPolyline (Face& face, int& vStart,
    int& vFinal)
{
    // Count the number of occurrences of each vertex in the polyline.
    bool okay = true;
    std::set<int>::iterator iter = face.Edges.begin();
    std::set<int>::iterator end = face.Edges.end();
    while (iter != end)
    {
        int e = *iter++;
        Edge& edge = mEdges[e];

        int v0 = edge.Vertex[0];
        ++mVertices[v0].Occurs;
        if (mVertices[v0].Occurs > 2)
        {
            okay = false;
        }

        int v1 = edge.Vertex[1];
        ++mVertices[v1].Occurs;
        if (mVertices[v1].Occurs > 2)
        {
            okay = false;
        }
    }

    if (!okay)
    {
#ifdef _DEBUG
        // If you reach this block, there is a good chance that floating
        // point round-off error had caused this face to be needle-like and
        // what was theoretically a narrow V-shaped portion (a vertex shared
        // by two edges forming a small angle) has collapsed into a single
        // line segment.
        //
        // NOTE.  Once I added Postprocess, I have not gotten to this block.
        std::ofstream outFile("error.txt");
        iter = face.Edges.begin();
        end = face.Edges.end();
        while (iter != end)
        {
            int e = *iter++;
            Edge& edge = mEdges[e];
            outFile << "e<" << e << "> = <" << edge.Vertex[0] << ","
                  << edge.Vertex[1] << "|" << edge.Face[0] << ","
                  << edge.Face[1] << "> ";
            if (edge.Visible)
            {
                outFile << "T" << std::endl;
            }
            else
            {
                outFile << "F" << std::endl;
            }
        }
        outFile.close();

        assertion(false, "Probable numerical round-off errors.\n");
#else
        return false;
#endif
    }

    // Determine whether the polyline is open.
    iter = face.Edges.begin();
    end = face.Edges.end();
    vStart = -1;
    vFinal = -1;
    while (iter != end)
    {
        int e = *iter++;
        Edge& edge = mEdges[e];

        int v0 = edge.Vertex[0];
        if (mVertices[v0].Occurs == 1)
        {
            if (vStart == -1)
            {
                vStart = v0;
            }
            else if (vFinal == -1)
            {
                vFinal = v0;
            }
            else
            {
                // If you reach this assert, there is a good chance that the
                // polyhedron is not convex.  To check this, use the function
                // ValidateHalfSpaceProperty() on your polyhedron right after
                // you construct it.
                assertion(false, "Polyhedron might not be convex.\n");
            }
        }

        int v1 = edge.Vertex[1];
        if (mVertices[v1].Occurs == 1)
        {
            if (vStart == -1)
            {
                vStart = v1;
            }
            else if (vFinal == -1)
            {
                vFinal = v1;
            }
            else
            {
                // If you reach this assert, there is a good chance that the
                // polyhedron is not convex.  To check this, use the function
                // ValidateHalfSpaceProperty() on your polyhedron right after
                // you construct it.
                assertion(false, "Polyhedron might not be convex.\n");
            }
        }
    }

    assertion((vStart == -1 && vFinal == -1)
        || (vStart != -1 && vFinal != -1), "Unexpected condition.\n");

    return vStart != -1;
}
//----------------------------------------------------------------------------
template <typename Real>
void ConvexClipper<Real>::OrderVertices (Face& face,
    std::vector<int>& vOrdered)
{
    // Copy edge indices into contiguous memory.
    const int numEdges = (int)face.Edges.size();
    std::vector<int> eOrdered(numEdges);
    std::set<int>::iterator iter = face.Edges.begin();
    std::set<int>::iterator end = face.Edges.end();
    int i = 0;
    while (iter != end)
    {
        eOrdered[i++] = *iter++;
    }

    // Bubble sort (yes, it is...).
    for (int i0 = 0, i1 = 1, choice = 1; i1 < numEdges - 1; i0 = i1++)
    {
        Edge& edgeCurr = mEdges[eOrdered[i0]];
        int j, curr = edgeCurr.Vertex[choice];
        for (j = i1; j < numEdges; ++j)
        {
            Edge& edgeTemp = mEdges[eOrdered[j]];
            int save;
            if (edgeTemp.Vertex[0] == curr)
            {
                save = eOrdered[i1];
                eOrdered[i1] = eOrdered[j];
                eOrdered[j] = save;
                choice = 1;
                break;
            }
            if (edgeTemp.Vertex[1] == curr)
            {
                save = eOrdered[i1];
                eOrdered[i1] = eOrdered[j];
                eOrdered[j] = save;
                choice = 0;
                break;
            }
        }
        assertion(j < numEdges, "Unexpected condition.\n");
    }

    vOrdered[0] = mEdges[eOrdered[0]].Vertex[0];
    vOrdered[1] = mEdges[eOrdered[0]].Vertex[1];
    for (i = 1; i < numEdges; ++i)
    {
        Edge& edge = mEdges[eOrdered[i]];
        if (edge.Vertex[0] == vOrdered[i])
        {
            vOrdered[i + 1] = edge.Vertex[1];
        }
        else
        {
            vOrdered[i + 1] = edge.Vertex[0];
        }
    }
}
//----------------------------------------------------------------------------
template <typename Real>
void ConvexClipper<Real>::GetTriangles (std::vector<int>& indices,
    std::vector<Plane3<Real> >& planes)
{
    const int numFaces = (int)mFaces.size();
    for (int f = 0; f < numFaces; ++f)
    {
        Face& face = mFaces[f];
        if (face.Visible)
        {
            const int numEdges = (int)face.Edges.size();
            assertion(numEdges >= 3, "Unexpected condition.\n");
            std::vector<int> vOrdered(numEdges + 1);
            OrderVertices(face, vOrdered);

            int v0 = vOrdered[0];
            int v2 = vOrdered[numEdges - 1];
            int v1 = vOrdered[(numEdges - 1) >> 1];
            Vector3<Real> diff1 = mVertices[v1].Point - mVertices[v0].Point;
            Vector3<Real> diff2 = mVertices[v2].Point - mVertices[v0].Point;
            Real sgnVolume = face.Plane.Normal.Dot(diff1.Cross(diff2));
            if (sgnVolume > (Real)0)
            {
                // Clockwise, need to swap.
                for (int i = 1; i + 1 < numEdges; ++i)
                {
                    indices.push_back(v0);
                    indices.push_back(vOrdered[i + 1]);
                    indices.push_back(vOrdered[i]);
                    planes.push_back(face.Plane);
                }
            }
            else
            {
                // Counterclockwise.
                for (int i = 1; i + 1 < numEdges; ++i)
                {
                    indices.push_back(v0);
                    indices.push_back(vOrdered[i]);
                    indices.push_back(vOrdered[i + 1]);
                    planes.push_back(face.Plane);
                }
            }
        }
    }
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// ConvexClipper::Vertex
//----------------------------------------------------------------------------
template <typename Real>
ConvexClipper<Real>::Vertex::Vertex ()
    :
    Distance((Real)0),
    Visible(true)
{
    // Point and Occurs are uninitialized.
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// ConvexClipper::Edge
//----------------------------------------------------------------------------
template <typename Real>
ConvexClipper<Real>::Edge::Edge ()
    :
    Visible(true)
{
    // Vertex[] and Face[] are uninitialized.
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// ConvexClipper::Face
//----------------------------------------------------------------------------
template <typename Real>
ConvexClipper<Real>::Face::Face ()
    :
    Visible(true)
{
    // Plane is uninitialized, Edges is empty.
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// ConvexClipper::EdgePlus
//----------------------------------------------------------------------------
template <typename Real>
ConvexClipper<Real>::EdgePlus::EdgePlus ()
{
}
//----------------------------------------------------------------------------
template <typename Real>
ConvexClipper<Real>::EdgePlus::EdgePlus (int e, const Edge& edge)
    :
    E(e)
{
    F0 = edge.Face[0];
    F1 = edge.Face[1];

    if (edge.Vertex[0] < edge.Vertex[1])
    {
        V0 = edge.Vertex[0];
        V1 = edge.Vertex[1];
    }
    else
    {
        V0 = edge.Vertex[1];
        V1 = edge.Vertex[0];
    }
}
//----------------------------------------------------------------------------
template <typename Real>
bool ConvexClipper<Real>::EdgePlus::operator< (const EdgePlus& edge) const
{
    if (V1 < edge.V1)
    {
        return true;
    }

    if (V1 == edge.V1)
    {
        return V0 < edge.V0;
    }

    return false;
}
//----------------------------------------------------------------------------
template <typename Real>
bool ConvexClipper<Real>::EdgePlus::operator== (const EdgePlus& edge) const
{
    return V0 == edge.V0 && V1 == edge.V1;
}
//----------------------------------------------------------------------------
template <typename Real>
bool ConvexClipper<Real>::EdgePlus::operator!= (const EdgePlus& edge) const
{
    return V0 != edge.V0 || V1 != edge.V1;
}
//----------------------------------------------------------------------------

//----------------------------------------------------------------------------
// Explicit instantiation.
//----------------------------------------------------------------------------
template class ConvexClipper<float>;
template class ConvexClipper<double>;
//----------------------------------------------------------------------------