Exemple #1
0
 def arrangeEdges(self, edges):
     # index of the middle part of the node if it's of T-type
     middleIndex = -1
     cos01 = edges[0][0].dot(edges[1][0])
     cos02 = edges[0][0].dot(edges[2][0])
     if is90degrees(cos01):
         if is90degrees(cos02):
             middleIndex = 0
         elif is180degrees(cos02):
             middleIndex = 1
     elif is90degrees(cos02):
         if is90degrees(cos01):
             middleIndex = 0
         elif is180degrees(cos01):
             middleIndex = 2
     if middleIndex < 0:
         return None
     self.baseEdgeIndex = middleIndex
     return super().arrangeEdges(edges)
Exemple #2
0
 def arrangeEdges(self, edges):
     # index of the middle part of the node if it's of T-type
     middleIndex = -1
     cos01 = edges[0][0].dot(edges[1][0])
     cos02 = edges[0][0].dot(edges[2][0])
     if is90degrees(cos01):
         if is90degrees(cos02):
             middleIndex = 0
         elif is180degrees(cos02):
             middleIndex = 1
     elif is90degrees(cos02):
         if is90degrees(cos01):
             middleIndex = 0
         elif is180degrees(cos01):
             middleIndex = 2
     if middleIndex < 0:
         return None
     self.baseEdgeIndex = middleIndex
     return super().arrangeEdges(edges)
Exemple #3
0
 def arrangeEdges(self, edges):
     """
     Arrange input <edges> in the following way.
     
     The edge with the index zero is always the base edge.
     The other edges are arranged in the counterclockwise order starting from the base edge.
     
     Returns:
         A tuple of arranged edges
     """
     from operator import itemgetter
     # Add two extra elements to each entry of <edges> to perform one-line sorting
     # So the forth element with the index 3 is cosine of the angle between the edge and the base edge
     # The third element with the index 2 indicates in which circle half the edge is located:
     # True: the edge is located in the first circle half going counterclockwise from the base edge
     # False: the edge is located in the second circle half going counterclockwise from the base edge
     baseEdgeIndex = self.baseEdgeIndex
     baseVec = edges[baseEdgeIndex][0]
     for i, e in enumerate(edges):
         e.append(True)
         if i == baseEdgeIndex:
             # ensure that the base edge will be the first one after sorting of <edges>
             e.append(1.)
         else:
             cos = baseVec.dot(e[0])
             # check if the angle between the edge and the base edge is 180 degrees
             if is180degrees(cos):
                 e.append(-1.)
             else:
                 if self.n.dot(baseVec.cross(e[0])) < 0.:
                     e[2] = False
                     # negate <cos> to have correct sorting
                     cos = -cos
                 e.append(cos)
     edges.sort(key=itemgetter(2, 3), reverse=True)
     # restore the true value of cosine for the second circle half
     for i in range(len(edges) - 1, -1, -1):
         if edges[i][2]:
             # reached the first circle half
             break
         else:
             edges[i][3] = -edges[i][3]
     return edges
Exemple #4
0
 def arrangeEdges(self, edges):
     """
     Arrange input <edges> in the following way.
     
     The edge with the index zero is always the base edge.
     The other edges are arranged in the counterclockwise order starting from the base edge.
     
     Returns:
         A tuple of arranged edges
     """
     from operator import itemgetter
     # Add two extra elements to each entry of <edges> to perform one-line sorting
     # So the forth element with the index 3 is cosine of the angle between the edge and the base edge
     # The third element with the index 2 indicates in which circle half the edge is located:
     # True: the edge is located in the first circle half going counterclockwise from the base edge
     # False: the edge is located in the second circle half going counterclockwise from the base edge
     baseEdgeIndex = self.baseEdgeIndex
     baseVec = edges[baseEdgeIndex][0]
     for i,e in enumerate(edges):
         e.append(True)
         if i == baseEdgeIndex:
             # ensure that the base edge will be the first one after sorting of <edges>
             e.append(1.)
         else:
             cos = baseVec.dot(e[0])
             # check if the angle between the edge and the base edge is 180 degrees
             if is180degrees(cos):
                 e.append(-1.)
             else:
                 if self.n.dot( baseVec.cross(e[0])) < 0.:
                     e[2] = False
                     # negate <cos> to have correct sorting
                     cos = -cos
                 e.append(cos)
     edges.sort(key=itemgetter(2,3), reverse=True)
     # restore the true value of cosine for the second circle half
     for i in range(len(edges)-1, -1, -1):
         if edges[i][2]:
             # reached the first circle half
             break
         else:
             edges[i][3] = -edges[i][3]
     return edges