我正在编写一个游戏,我想用透明边框(精灵)对着圆圈碰撞图像.
通过检查与不透明的像素的碰撞,很容易知道圆是否与图像重叠.
我遇到的问题是要知道正常角度才能反弹.
我需要一个库(Java)或算法给出一个图像,它会返回一个数组,其像素位于图像的边界,这样我就可以找到表面两点之间的斜率.
我可以从中学习任何库/算法/代码片段吗?
我有以下 Django 视图:
@login_required
def view(request: HttpRequest) -> HttpResponse:
if not request.user.some_attribute:
return redirect("somewhere")
return render(request, "template_name")
Run Code Online (Sandbox Code Playgroud)
以及一个User具有属性 的自定义模型some_attribute。
我用mypy这个来强制类型检查mypy.ini:
[mypy]
ignore_missing_imports = True
plugins = mypy_django_plugin.main
[mypy.plugins.django-stubs]
django_settings_module = [PROJECT NAME].settings
Run Code Online (Sandbox Code Playgroud)
但是,mypy出现以下错误:
Item "AnonymousUser" of "Union[User, AnonymousUser]" has no attribute "some_attribute"
Run Code Online (Sandbox Code Playgroud)
这是有道理的,因为匿名用户不会有该属性,但我有一个login_required装饰器,使得AnonymousUsers 不可能(它将是 a User)。
我如何告诉mypy忽略这一点,而不使用# type: ignore?
由于多种原因,我需要使用C ++列表(而不是向量),但需要对元素进行基于索引的访问。
我想到了这样的东西:
point* point1i = std::next(listPoints.begin(), i);
point* point2i = std::next(listPoints.begin(), i + 1);
Run Code Online (Sandbox Code Playgroud)
其中在point其他地方声明的类i是整数。
但是当我编译的时候我得到这个错误:
error: cannot convert ‘std::_List_iterator<point*>’ to ‘point*’ in initialization
Run Code Online (Sandbox Code Playgroud)
我在这里做错了什么?
谢谢!