PeriDyno 1.0.0
Loading...
Searching...
No Matches
STLMacro.h
Go to the documentation of this file.
1#ifndef MACRO_H
2#define MACRO_H
3
4#include "Platform.h"
5
6namespace dyno
7{
8 #define INVALID -1
9
21 template<typename T>
22 DYN_FUNC int leftBound(T target, T* startLoc, uint maxSize)
23 {
24 int left = 0;
25 int right = (int)maxSize;
26
27 while (left < right) {
28 int mid = (left + right) / 2;
29 if (startLoc[mid] == target) {
30 right = mid;
31 }
32 else if (startLoc[mid] < target) {
33 left = mid + 1;
34 }
35 else if (startLoc[mid] > target) {
36 right = mid;
37 }
38 }
39 return left;
40 }
41
53 template<typename T>
54 DYN_FUNC int rightBound(T target, T* startLoc, uint maxSize)
55 {
56 if (maxSize == 0) return -1;
57 int left = 0, right = (int)maxSize;
58
59 while (left < right) {
60 int mid = (left + right) / 2;
61 if (startLoc[mid] == target) {
62 left = mid + 1;
63 }
64 else if (startLoc[mid] < target) {
65 left = mid + 1;
66 }
67 else if (startLoc[mid] > target) {
68 right = mid;
69 }
70 }
71 return left - 1;
72 }
73}
74#endif // MACRO_H
#define T(t)
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25
DYN_FUNC int leftBound(T target, T *startLoc, uint maxSize)
Find the left bound of a target with a binary search algorithm.
Definition STLMacro.h:22
unsigned int uint
Definition VkProgram.h:14
DYN_FUNC int rightBound(T target, T *startLoc, uint maxSize)
Find the right bound of a target with a binary search algorithm.
Definition STLMacro.h:54