libatomprobe
Library for Atom Probe Tomography (APT) computation
millerIndex.cpp
Go to the documentation of this file.
1 /* millterIndex.cpp : Miller index sequence generation
2  * Copyright (C) 2017 Daniel Haley
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
19 
20 #include <algorithm>
21 
22 
23 namespace AtomProbe
24 {
25 
26 using std::vector;
27 
28 int gcd(int a, int b)
29 {
30  //a and b need to be nonzero
31  if(!a || !b)
32  return 0;
33 
34  //make a and b positive
35  a=abs(a);
36  b=abs(b);
37 
38  //make a >=b
39  if(b>a)
40  std::swap(a,b);
41 
42  //repeatedly take the modulus of a with smaller b
43  while(b)
44  {
45  int t;
46  t=b;
47  b=a%b;
48  a=t;
49  }
50 
51  return a;
52 
53 }
54 
55 MILLER_TRIPLET::MILLER_TRIPLET(int a, int b, int c)
56 {
57  idx[0]=a;
58  idx[1]=b;
59  idx[2]=c;
60 }
61 
62 int MILLER_TRIPLET::h() const
63 {
64  return idx[0];
65 }
66 
67 int MILLER_TRIPLET::k() const
68 {
69  return idx[1];
70 }
71 
72 int MILLER_TRIPLET::l() const
73 {
74  return idx[2];
75 }
76 
78 {
79  int gcdAll;
80  gcdAll = gcd( gcd(idx[0],idx[1]),idx[2]);
81 
82  idx[0]/=gcdAll;
83  idx[1]/=gcdAll;
84  idx[2]/=gcdAll;
85 }
86 
87 
89 {
90  return (m.idx[0] == idx[0] && m.idx[1]==idx[1] && m.idx[2]==idx[2]);
91 }
92 
93 #ifdef DEBUG
94 bool testMillerTriplets();
95 
96 bool millerTest()
97 {
98  if(!testMillerTriplets())
99  return false;
100 
101  return true;
102 }
103 
104 bool testMillerTriplets()
105 {
106 
107  MILLER_TRIPLET m(4,6,2);
108  m.simplify();
109 
110  TEST( (m == MILLER_TRIPLET(2,3,1)) , "Index simplification");
111 
112 
113 
114  return true;
115 
116 }
117 #endif
118 }
bool operator==(const MILLER_TRIPLET &m) const
Definition: millerIndex.cpp:88
MILLER_TRIPLET(int a, int b, int c)
Definition: millerIndex.cpp:55
int gcd(int a, int b)
Definition: millerIndex.cpp:28
#define TEST(f, g)
Definition: aptAssert.h:49