Project the rect onto the specified axis. .. tip:: This function is extremely fast for vertical or horizontal axises. :param rect: the rect to project :type rect: :class:`pygorithm.geometry.rect2.Rect2` :par
(rect, axis)
| 145 | |
| 146 | @staticmethod |
| 147 | def project_onto_axis(rect, axis): |
| 148 | """ |
| 149 | Project the rect onto the specified axis. |
| 150 | |
| 151 | .. tip:: |
| 152 | |
| 153 | This function is extremely fast for vertical or |
| 154 | horizontal axises. |
| 155 | |
| 156 | :param rect: the rect to project |
| 157 | :type rect: :class:`pygorithm.geometry.rect2.Rect2` |
| 158 | :param axis: the axis to project onto (normalized) |
| 159 | :type axis: :class:`pygorithm.geometry.vector2.Vector2` |
| 160 | :returns: the projection of the rect along axis |
| 161 | :rtype: :class:`pygorithm.geometry.axisall.AxisAlignedLine` |
| 162 | """ |
| 163 | |
| 164 | if axis.x == 0: |
| 165 | return axisall.AxisAlignedLine(axis, rect.mincorner.y * axis.y, (rect.mincorner.y + rect.height) * axis.y) |
| 166 | elif axis.y == 0: |
| 167 | return axisall.AxisAlignedLine(axis, rect.mincorner.x * axis.x, (rect.mincorner.x + rect.width) * axis.x) |
| 168 | |
| 169 | p1 = rect.mincorner.dot(axis) |
| 170 | p2 = vector2.Vector2(rect.mincorner.x + rect.width, rect.mincorner.y).dot(axis) |
| 171 | p3 = vector2.Vector2(rect.mincorner.x + rect.width, rect.mincorner.y + rect.height).dot(axis) |
| 172 | p4 = vector2.Vector2(rect.mincorner.x, rect.mincorner.y + rect.height).dot(axis) |
| 173 | |
| 174 | _min = min(p1, p2, p3, p4) |
| 175 | _max = max(p1, p2, p3, p4) |
| 176 | return axisall.AxisAlignedLine(axis, _min, _max) |
| 177 | |
| 178 | @staticmethod |
| 179 | def contains_point(rect, point): |