MCPcopy Create free account
hub / github.com/vispy/vispy / _generate_vertices

Method _generate_vertices

vispy/visuals/rectangle.py:67–138  ·  view source on GitHub ↗
(center, radius, height, width)

Source from the content-addressed store, hash-verified

65
66 @staticmethod
67 def _generate_vertices(center, radius, height, width):
68 half_height = height / 2.
69 half_width = width / 2.
70 hw = min(half_height, half_width)
71
72 if isinstance(radius, (list, tuple)):
73 if len(radius) != 4:
74 raise ValueError("radius must be float or 4 value tuple/list"
75 " (got %s of length %d)" % (type(radius),
76 len(radius)))
77
78 if (radius > np.ones(4) * hw).all():
79 raise ValueError('Radius of curvature cannot be greater than\
80 half of min(width, height)')
81 radius = np.array(radius, dtype=np.float32)
82
83 else:
84 if radius > hw:
85 raise ValueError('Radius of curvature cannot be greater than\
86 half of min(width, height)')
87 radius = np.ones(4) * radius
88
89 num_segments = (radius / hw * 500.).astype(int)
90
91 bias1 = np.ones(4) * half_width - radius
92 bias2 = np.ones(4) * half_height - radius
93
94 corner1 = np.empty([num_segments[0]+1, 3], dtype=np.float32)
95 corner2 = np.empty([num_segments[1]+1, 3], dtype=np.float32)
96 corner3 = np.empty([num_segments[2]+1, 3], dtype=np.float32)
97 corner4 = np.empty([num_segments[3]+1, 3], dtype=np.float32)
98
99 start_angle = 0.
100 end_angle = np.pi / 2.
101
102 theta = np.linspace(end_angle, start_angle, num_segments[0]+1)
103
104 corner1[:, 0] = center[0] - bias1[0] - radius[0] * np.sin(theta)
105 corner1[:, 1] = center[1] - bias2[0] - radius[0] * np.cos(theta)
106 corner1[:, 2] = 0
107
108 theta = np.linspace(start_angle, end_angle, num_segments[1]+1)
109
110 corner2[:, 0] = center[0] + bias1[1] + radius[1] * np.sin(theta)
111 corner2[:, 1] = center[1] - bias2[1] - radius[1] * np.cos(theta)
112 corner2[:, 2] = 0
113
114 theta = np.linspace(end_angle, start_angle, num_segments[2]+1)
115
116 corner3[:, 0] = center[0] + bias1[2] + radius[2] * np.sin(theta)
117 corner3[:, 1] = center[1] + bias2[2] + radius[2] * np.cos(theta)
118 corner3[:, 2] = 0
119
120 theta = np.linspace(start_angle, end_angle, num_segments[3]+1)
121
122 corner4[:, 0] = center[0] - bias1[3] - radius[3] * np.sin(theta)
123 corner4[:, 1] = center[1] + bias2[3] + radius[3] * np.cos(theta)
124 corner4[:, 2] = 0

Callers 1

_regen_posMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected