-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinearity.c
102 lines (75 loc) · 2.92 KB
/
linearity.c
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
// linearity.c
/***************************************************
hinge までの結合が直線か否かを判定する関数
直線ならば TRUE 直線でないならば FALSE
***************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "main_canost.h"
// #define TEST_LINEARITY 1
// #define TEST_LINEARITY_SECOND 1
extern struct atom *a1st;
extern int *relative_parent;
extern int *relation;
int linearity( int hinge, int parent, int child ){
int linear_or_broken;
#ifdef TEST_LINEARITY
printf("linearity: hinge %d parent %d child %d \n", hinge, parent, child);
#endif
#ifdef TEST_LINEARITY_SECOND
printf("relation of %d is %d \n",hinge,relation[ hinge ]);
printf("relation of %d is %d \n",parent,relation[ parent ]);
printf("relation of %d is %d \n",child,relation[ child ]);
#endif
if( ( relation[ parent ] == TRIPLE && relation[ child ] == SINGLE ) ||
( relation[ parent ] == SINGLE && relation[ child ] == TRIPLE ) ){ // #(parent)-(child)
relative_parent[ child ] = relative_parent[ parent ];
child = parent;
parent = relative_parent[ parent ];
if( parent != hinge ){
linear_or_broken = linearity( hinge,parent,child );
#ifdef TEST_LINEARITY
printf("parent %d child %d linear_or_broken %d (1)\n",parent,child,linear_or_broken);
#endif
return linear_or_broken;
}else{ // parent == hinge hingeまで一直線
return TRUE;
}
}else if( relation[ child ] == DOUBLE && relation[ parent ] == DOUBLE ){ // =(parent)=(child)
relative_parent[ child ] = relative_parent[ parent ];
child = parent;
parent = relative_parent[ parent ];
if( parent != hinge ){
linear_or_broken = linearity( hinge,parent,child );
#ifdef TEST_LINEARITY
printf("parent %d child %d linear_or_broken %d (2)\n",parent,child,linear_or_broken);
#endif
return linear_or_broken;
}else{ // parent == hinge hingeまで一直線
return TRUE;
}
}else if( strcmp(a1st[ parent ].code,"T") == 0 || // -C#(child)
strcmp(a1st[ parent ].code,"T1") == 0 || // H-C#(child) #C-H(child)
strcmp(a1st[ parent ].code,"DD") == 0 || // =C=(child)
strcmp(a1st[ parent ].code,"VD") == 0 ){ // =C=O(child) O=C=(child)
relative_parent[ child ] = relative_parent[ parent ];
child = parent;
parent = relative_parent[ parent ];
if( parent != hinge ){
linear_or_broken = linearity( hinge,parent,child );
#ifdef TEST_LINEARITY
printf("parent %d child %d linear_or_broken %d (3)\n",parent,child,linear_or_broken);
#endif
return linear_or_broken;
}else{ // parent == hinge hingeまで一直線
return TRUE;
}
}else{
linear_or_broken = FALSE;
#ifdef TEST_LINEARITY
printf("parent %d child %d linear_or_broken %d (4)\n",parent,child,linear_or_broken);
#endif
return linear_or_broken;
}
}