3a507ddb |
1 | // Created on: 2016-04-13 |
3c4e78f2 |
2 | // Created by: Denis BOGOLEPOV |
3a507ddb |
3 | // Copyright (c) 2013-2016 OPEN CASCADE SAS |
3c4e78f2 |
4 | // |
5 | // This file is part of Open CASCADE Technology software library. |
6 | // |
d5f74e42 |
7 | // This library is free software; you can redistribute it and/or modify it under |
8 | // the terms of the GNU Lesser General Public License version 2.1 as published |
3c4e78f2 |
9 | // by the Free Software Foundation, with special exception defined in the file |
10 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
11 | // distribution for complete text of the license and disclaimer of any warranty. |
12 | // |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
15 | |
16 | // ======================================================================= |
17 | // function : Perform |
18 | // purpose : |
19 | // ======================================================================= |
20 | template<class T, int N> |
3a507ddb |
21 | void BVH_QuickSorter<T, N>::Perform (BVH_Set<T, N>* theSet) |
3c4e78f2 |
22 | { |
3a507ddb |
23 | Perform (theSet, 0, theSet->Size() - 1); |
3c4e78f2 |
24 | } |
25 | |
26 | // ======================================================================= |
27 | // function : Perform |
28 | // purpose : |
29 | // ======================================================================= |
30 | template<class T, int N> |
3a507ddb |
31 | void BVH_QuickSorter<T, N>::Perform (BVH_Set<T, N>* theSet, const Standard_Integer theStart, const Standard_Integer theFinal) |
3c4e78f2 |
32 | { |
3a507ddb |
33 | Standard_Integer aLft = theStart; |
34 | Standard_Integer aRgh = theFinal; |
3c4e78f2 |
35 | |
3a507ddb |
36 | T aPivot = theSet->Center ((aRgh + aLft) / 2, myAxis); |
3c4e78f2 |
37 | |
38 | while (aLft < aRgh) |
39 | { |
3a507ddb |
40 | while (theSet->Center (aLft, myAxis) < aPivot && aLft < theFinal) |
3c4e78f2 |
41 | { |
42 | ++aLft; |
43 | } |
44 | |
3a507ddb |
45 | while (theSet->Center (aRgh, myAxis) > aPivot && aRgh > theStart) |
3c4e78f2 |
46 | { |
47 | --aRgh; |
48 | } |
49 | |
50 | if (aLft <= aRgh) |
51 | { |
52 | if (aLft != aRgh) |
53 | { |
54 | theSet->Swap (aLft, aRgh); |
55 | } |
56 | |
57 | ++aLft; |
58 | --aRgh; |
59 | } |
60 | } |
61 | |
3a507ddb |
62 | if (aRgh > theStart) |
3c4e78f2 |
63 | { |
3a507ddb |
64 | Perform (theSet, theStart, aRgh); |
3c4e78f2 |
65 | } |
66 | |
3a507ddb |
67 | if (aLft < theFinal) |
3c4e78f2 |
68 | { |
3a507ddb |
69 | Perform (theSet, aLft, theFinal); |
3c4e78f2 |
70 | } |
71 | } |