pyfoil2d 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,29 @@
1
+ [package]
2
+ name = "foil"
3
+ version = "0.1.0"
4
+ edition = "2021"
5
+ license = "MIT"
6
+ readme = "README.md"
7
+ repository = "https://gitee.com/longyateng/dargon"
8
+ description = "2D grid collision: 32px cells, two chains, box and circle."
9
+ exclude = ["python/", "examples/", "pyproject.toml"]
10
+
11
+ [lib]
12
+ name = "Foil"
13
+
14
+ [features]
15
+ default = ["gpu"]
16
+ gpu = ["dep:wgpu", "dep:bytemuck", "dep:pollster"]
17
+
18
+ [package.metadata.docs.rs]
19
+ features = ["gpu"]
20
+
21
+ [dependencies]
22
+ rayon = "1.10"
23
+ bytemuck = { version = "1", features = ["derive"], optional = true }
24
+ wgpu = { version = "22", optional = true }
25
+ pollster = { version = "0.3", optional = true }
26
+
27
+ [dev-dependencies]
28
+ pollster = "0.3"
29
+ minifb = "0.27"
pyfoil2d-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Foil contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: pyfoil2d
3
+ Version: 0.1.0
4
+ License-File: LICENSE
5
+ Summary: 2D grid collision: 32px cells, two chains, box and circle.
6
+ Requires-Python: >=3.13
@@ -0,0 +1,12 @@
1
+ # Foil
2
+
3
+ Foil 是一个轻量级 2D 游戏物理引擎,以速度、轻量、可玩性为目标,不追求复杂的物理系统,主要面向大多数 2D 游戏场景。
4
+
5
+ 目前完成了轴对齐矩形和圆的重叠检测、传感器、分组和掩码。编号由调用方指定。调用方用 `set_pose` 摆位置,用 `overlaps` 或 `query` 取重叠结果。精度可选 `f32`,或仅在 CPU 上使用的 `f64`。批量查询可以限制线程数。
6
+
7
+ 接口说明见 [docs/groups.html](https://gitee.com/longyateng/dargon/blob/foil/foil/docs/groups.html)。
8
+
9
+ 注
10
+
11
+ 1. 项目正处在开发阶段,如遇到 Bug,欢迎提交反馈 / Issue。
12
+ 2. GPU 加速正属于实验性功能,传输开销远大于带来的性能提升,暂时不推荐使用。
@@ -0,0 +1,388 @@
1
+ <!DOCTYPE html>
2
+ <html lang="zh" data-api="rs">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Foil — 接口</title>
7
+ <link rel="preconnect" href="https://fonts.googleapis.com">
8
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
9
+ <link href="https://fonts.googleapis.com/css2?family=Familjen+Grotesk:wght@500;600&family=Petrona:ital,wght@0,400;0,560;1,400&display=swap" rel="stylesheet">
10
+ <style>
11
+ :root {
12
+ --paper: #e6eee9;
13
+ --ink: #17211e;
14
+ --muted: #4d5e57;
15
+ --line: #c3d2cb;
16
+ --solid: #1d4a42;
17
+ --sensor: #b85c38;
18
+ --chip: #f7faf8;
19
+ }
20
+ * { box-sizing: border-box; }
21
+ html { background: var(--paper); color: var(--ink); }
22
+ body {
23
+ margin: 0;
24
+ font-family: Petrona, "Songti SC", "Noto Serif SC", serif;
25
+ font-size: 1.125rem;
26
+ line-height: 1.6;
27
+ background-image:
28
+ linear-gradient(to right, rgba(29, 74, 66, 0.05) 1px, transparent 1px),
29
+ linear-gradient(to bottom, rgba(29, 74, 66, 0.05) 1px, transparent 1px);
30
+ background-size: 32px 32px;
31
+ }
32
+ .wrap { width: min(920px, calc(100% - 2rem)); margin: 0 auto; padding: 1.5rem 0 4.5rem; }
33
+ header { display: flex; justify-content: space-between; align-items: baseline; gap: 1rem; margin-bottom: 1.5rem; }
34
+ .mark { font-family: "Familjen Grotesk", "Microsoft YaHei", sans-serif; font-weight: 600; letter-spacing: -0.03em; }
35
+ .switches { display: flex; gap: 0.45rem; }
36
+ .pill {
37
+ font-family: "Familjen Grotesk", "Microsoft YaHei", sans-serif;
38
+ background: transparent; color: var(--ink); border: 1px solid var(--ink);
39
+ border-radius: 999px; padding: 0.28rem 0.8rem; cursor: pointer;
40
+ }
41
+ .pill:focus-visible, a:focus-visible { outline: 2px solid var(--sensor); outline-offset: 3px; }
42
+ h1 {
43
+ font-family: "Familjen Grotesk", "Microsoft YaHei", sans-serif;
44
+ font-weight: 600; letter-spacing: -0.04em; line-height: 1.08;
45
+ font-size: clamp(2rem, 4vw, 2.8rem); margin: 0 0 0.6rem; max-width: 16ch;
46
+ }
47
+ h2 {
48
+ font-family: "Familjen Grotesk", "Microsoft YaHei", sans-serif;
49
+ font-weight: 600; font-size: 1.45rem; letter-spacing: -0.03em;
50
+ margin: 2.4rem 0 0.7rem; padding-top: 0.2rem;
51
+ }
52
+ h3 {
53
+ font-family: "Familjen Grotesk", "Microsoft YaHei", sans-serif;
54
+ font-weight: 600; font-size: 1.15rem; margin: 1.5rem 0 0.25rem;
55
+ }
56
+ p, li { max-width: 42rem; }
57
+ ul { padding-left: 1.2rem; margin: 0.3rem 0 0.8rem; }
58
+ li { margin: 0.2rem 0; }
59
+ a { color: var(--solid); }
60
+ code, pre { font-family: "Familjen Grotesk", ui-monospace, monospace; }
61
+ code { font-size: 0.92em; }
62
+ pre {
63
+ max-width: 100%; background: var(--chip); border-left: 3px solid var(--solid);
64
+ padding: 0.75rem 1rem; overflow-x: auto; font-size: 0.88rem; line-height: 1.45;
65
+ margin: 0.35rem 0 0.2rem;
66
+ }
67
+ nav.toc { margin: 1rem 0 0.4rem; }
68
+ nav.toc ul { columns: 2; padding-left: 1.15rem; margin: 0.35rem 0 0; }
69
+ html[lang="zh"] .en { display: none; }
70
+ html[lang="en"] .zh { display: none; }
71
+ html[data-api="rs"] .py { display: none; }
72
+ html[data-api="py"] .rs { display: none; }
73
+ @media (max-width: 640px) { nav.toc ul { columns: 1; } }
74
+ @media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
75
+ </style>
76
+ </head>
77
+ <body>
78
+ <div class="wrap">
79
+ <header>
80
+ <div class="mark">foil</div>
81
+ <div class="switches">
82
+ <button class="pill" id="lang" type="button">English</button>
83
+ <button class="pill" id="api" type="button">Python</button>
84
+ </div>
85
+ </header>
86
+
87
+ <h1 class="zh">接口</h1>
88
+ <h1 class="en">API</h1>
89
+ <p class="zh">坐标是像素,Y 向下。库不推动物体。边贴着不算重叠。矩形不旋转。编号要能放进 32 位,<code>4294967295</code> 可以用。</p>
90
+ <p class="en">Coordinates are pixels, Y down. The library does not move bodies. Touching edges is not an overlap. Rectangles do not rotate. An id has to fit in 32 bits; <code>4294967295</code> is allowed.</p>
91
+
92
+ <nav class="toc" aria-label="contents">
93
+ <ul>
94
+ <li><a href="#new">new</a></li>
95
+ <li><a href="#open">open</a></li>
96
+ <li><a href="#open_with">open_with</a></li>
97
+ <li><a href="#backend">backend</a></li>
98
+ <li><a href="#real">real</a></li>
99
+ <li><a href="#threads">threads</a></li>
100
+ <li><a href="#set_threads">set_threads</a></li>
101
+ <li><a href="#add">add</a></li>
102
+ <li><a href="#remove">remove</a></li>
103
+ <li><a href="#clear">clear</a></li>
104
+ <li><a href="#set_pose">set_pose</a></li>
105
+ <li><a href="#pose">pose</a></li>
106
+ <li><a href="#set_size">set_size</a></li>
107
+ <li><a href="#size">size</a></li>
108
+ <li><a href="#shape">shape</a></li>
109
+ <li><a href="#set_offset">set_offset</a></li>
110
+ <li><a href="#set_group">set_group</a></li>
111
+ <li><a href="#group">group</a></li>
112
+ <li><a href="#set_mask">set_mask</a></li>
113
+ <li><a href="#mask">mask</a></li>
114
+ <li><a href="#set_sensor">set_sensor</a></li>
115
+ <li><a href="#is_sensor">is_sensor</a></li>
116
+ <li><a href="#overlaps">overlaps</a></li>
117
+ <li><a href="#overlaps_at">overlaps_at</a></li>
118
+ <li><a href="#query">query</a></li>
119
+ <li><a href="#query_many">query_many</a></li>
120
+ <li><a href="#hit">hit</a></li>
121
+ <li><a href="#len">len</a></li>
122
+ <li><a href="#count">count</a></li>
123
+ <li><a href="#contains">contains</a></li>
124
+ <li><a href="#each">each</a></li>
125
+ <li><a href="#set_timing">set_timing</a></li>
126
+ <li><a href="#detect_ns">detect_ns</a></li>
127
+ <li><a href="#has_device">has_device</a></li>
128
+ <li><a href="#bind_device">bind_device</a></li>
129
+ </ul>
130
+ </nav>
131
+
132
+ <h2><span class="zh">创建</span><span class="en">Create</span></h2>
133
+
134
+ <h3 id="new"><code>new</code></h3>
135
+ <p class="zh">CPU,精度 <code>f32</code>,查询线程上限 16。</p>
136
+ <p class="en">CPU, <code>f32</code>, query thread cap 16.</p>
137
+ <pre class="rs">let world = Foil::new();</pre>
138
+ <pre class="py">world = Foil.Foil()
139
+ world = Foil.Foil(backend="cpu", real="f32", threads=16)</pre>
140
+
141
+ <h3 id="open"><code>open</code></h3>
142
+ <p class="zh">按后端创建,精度是 <code>f32</code>。名字可以是 <code>cpu</code>、<code>dx12</code>(也认 <code>d3d12</code>、<code>directx12</code>)、<code>vulkan</code>、<code>metal</code>、<code>gl</code>(也认 <code>opengl</code>、<code>gles</code>、<code>angle</code>),以及 <code>wgpu</code>、<code>webgpu</code>、<code>gpu</code>。显卡查询是实验功能,传输开销目前大于收益。</p>
143
+ <p class="en">Create with a backend, in <code>f32</code>. Names: <code>cpu</code>, <code>dx12</code> (also <code>d3d12</code>, <code>directx12</code>), <code>vulkan</code>, <code>metal</code>, <code>gl</code> (also <code>opengl</code>, <code>gles</code>, <code>angle</code>), and <code>wgpu</code>, <code>webgpu</code>, <code>gpu</code>. GPU query is experimental; transfer cost currently outweighs the gain.</p>
144
+ <pre class="rs">let world = Foil::open("dx12")?;</pre>
145
+ <pre class="py">world = Foil.Foil("dx12")</pre>
146
+
147
+ <h3 id="open_with"><code>open_with</code></h3>
148
+ <p class="zh"><code>real</code> 写 <code>f32</code> 或 <code>f64</code>。<code>f64</code> 只能配 <code>cpu</code>,否则返回错误。Python 用构造参数,没有单独的这个函数。</p>
149
+ <p class="en"><code>real</code> is <code>f32</code> or <code>f64</code>. <code>f64</code> only pairs with <code>cpu</code>; anything else returns an error. Python passes this to the constructor and has no separate function.</p>
150
+ <pre class="rs">let world = Foil::open_with("cpu", "f64")?;</pre>
151
+ <pre class="py">world = Foil.Foil(backend="cpu", real="f64")</pre>
152
+
153
+ <h3 id="backend"><code>backend</code></h3>
154
+ <p class="zh">创建时选定的后端名字。一次查询改走 CPU 时,这个字符串不变。</p>
155
+ <p class="en">The backend name chosen at creation. It stays put when one query falls back to the CPU.</p>
156
+ <pre class="rs">world.backend()</pre>
157
+ <pre class="py">world.backend()</pre>
158
+
159
+ <h3 id="real"><code>real</code></h3>
160
+ <p class="zh">返回 <code>"f32"</code> 或 <code>"f64"</code>。</p>
161
+ <p class="en">Returns <code>"f32"</code> or <code>"f64"</code>.</p>
162
+ <pre class="rs">world.real()</pre>
163
+ <pre class="py">world.real()</pre>
164
+
165
+ <h3 id="threads"><code>threads</code></h3>
166
+ <p class="zh">当前上限。写多少就用多少。<code>0</code> 表示用进程里现成的线程池,按那台机器的逻辑处理器数拆开。被查物体少于 192 个时始终单线程。</p>
167
+ <p class="en">The current cap. The number you set is the number used. <code>0</code> uses the process thread pool and splits by the machine’s logical processors. Fewer than 192 queried bodies always run on one thread.</p>
168
+ <pre class="rs">world.threads()</pre>
169
+ <pre class="py">world.threads()</pre>
170
+
171
+ <h3 id="set_threads"><code>set_threads</code></h3>
172
+ <p class="zh">改上限。<code>1</code> 始终单线程。下次批量查询才按新的数量建池。</p>
173
+ <p class="en">Change the cap. <code>1</code> stays single-threaded. The next batch query builds the pool at the new size.</p>
174
+ <pre class="rs">world.set_threads(0);</pre>
175
+ <pre class="py">world.set_threads(0)</pre>
176
+
177
+ <h2><span class="zh">物体</span><span class="en">Bodies</span></h2>
178
+
179
+ <h3 id="add"><code>add</code></h3>
180
+ <p class="zh">放进一个物体。<code>x</code> <code>y</code> 是中心,<code>w</code> <code>h</code> 是宽高。圆的半径是宽高里较大的一半。<code>shape</code> 只接受 <code>rect</code> 和 <code>circle</code>。形状写错,或编号放不进 32 位,返回错误,物体不会放进去。<code>sensor</code> 为真时只参与检测。<code>mask == 0</code> 碰上所有人,对方 <code>group == 0</code> 也碰上。0 不是「谁都不碰」。</p>
181
+ <p class="en">Insert a body. <code>x</code> <code>y</code> is the center, <code>w</code> <code>h</code> the full size. A circle’s radius is half the larger side. <code>shape</code> accepts only <code>rect</code> and <code>circle</code>. A bad shape, or an id that does not fit in 32 bits, returns an error and inserts nothing. <code>sensor</code> true means detection only. <code>mask == 0</code> meets everyone, and so does the other body’s <code>group == 0</code>. 0 does not mean “meet nobody.”</p>
182
+ <pre class="rs">world.add(id, x, y, w, h, "rect", false, group, mask)?;</pre>
183
+ <pre class="py">world.add(idx, x, y, w, h, shape="rect", sensor=False, group=0, mask=0)</pre>
184
+
185
+ <h3 id="remove"><code>remove</code></h3>
186
+ <p class="zh">按编号删掉。编号不在世界里时什么也不做。</p>
187
+ <p class="en">Remove by id. A missing id does nothing.</p>
188
+ <pre class="rs">world.remove(id);</pre>
189
+ <pre class="py">world.remove(idx)</pre>
190
+
191
+ <h3 id="clear"><code>clear</code></h3>
192
+ <p class="zh">清空全部物体和格子。</p>
193
+ <p class="en">Remove every body and the grid.</p>
194
+ <pre class="rs">world.clear();</pre>
195
+ <pre class="py">world.clear()</pre>
196
+
197
+ <h3 id="set_pose"><code>set_pose</code></h3>
198
+ <p class="zh">改中心。不存在的编号会被忽略。</p>
199
+ <p class="en">Move the center. A missing id is ignored.</p>
200
+ <pre class="rs">world.set_pose(id, x, y);</pre>
201
+ <pre class="py">world.set_pose(idx, x, y)</pre>
202
+
203
+ <h3 id="pose"><code>pose</code></h3>
204
+ <p class="zh">读中心。编号不存在时返回 <code>None</code>。</p>
205
+ <p class="en">Read the center. Returns <code>None</code> when the id is missing.</p>
206
+ <pre class="rs">let (x, y) = world.pose(id)?;</pre>
207
+ <pre class="py">xy = world.pose(idx)</pre>
208
+
209
+ <h3 id="set_size"><code>set_size</code></h3>
210
+ <p class="zh">改宽高。Rust 的形状参数在尺寸前面,空字符串表示沿用现在的形状。Python 的形状在最后,默认也是空字符串。形状名写错才返回错误。</p>
211
+ <p class="en">Change width and height. In Rust the shape argument comes before the size; an empty string keeps the current shape. In Python the shape is last and defaults to an empty string. Only an unknown shape name returns an error.</p>
212
+ <pre class="rs">world.set_size(id, "circle", w, h)?;</pre>
213
+ <pre class="py">world.set_size(idx, w, h, shape="")</pre>
214
+
215
+ <h3 id="size"><code>size</code></h3>
216
+ <p class="zh">读宽高。编号不存在时没有结果。</p>
217
+ <p class="en">Read width and height. No result when the id is missing.</p>
218
+ <pre class="rs">let (w, h) = world.size(id)?;</pre>
219
+ <pre class="py">w, h = world.size(idx)</pre>
220
+
221
+ <h3 id="shape"><code>shape</code></h3>
222
+ <p class="zh">返回 <code>"rect"</code> 或 <code>"circle"</code>。</p>
223
+ <p class="en">Returns <code>"rect"</code> or <code>"circle"</code>.</p>
224
+ <pre class="rs">world.shape(id)</pre>
225
+ <pre class="py">world.shape(idx)</pre>
226
+
227
+ <h3 id="set_offset"><code>set_offset</code></h3>
228
+ <p class="zh">形状中心相对 <code>set_pose</code> 的偏移。</p>
229
+ <p class="en">Offset of the shape center from <code>set_pose</code>.</p>
230
+ <pre class="rs">world.set_offset(id, ox, oy);</pre>
231
+ <pre class="py">world.set_offset(idx, ox, oy)</pre>
232
+
233
+ <h3 id="set_group"><code>set_group</code></h3>
234
+ <p class="zh">改自己的分组位。</p>
235
+ <p class="en">Set this body’s group bits.</p>
236
+ <pre class="rs">world.set_group(id, group);</pre>
237
+ <pre class="py">world.set_group(idx, group)</pre>
238
+
239
+ <h3 id="group"><code>group</code></h3>
240
+ <p class="zh">读分组位。</p>
241
+ <p class="en">Read the group bits.</p>
242
+ <pre class="rs">world.group(id)</pre>
243
+ <pre class="py">world.group(idx)</pre>
244
+
245
+ <h3 id="set_mask"><code>set_mask</code></h3>
246
+ <p class="zh">改掩码。0 表示碰上所有人。</p>
247
+ <p class="en">Set the mask. 0 meets everyone.</p>
248
+ <pre class="rs">world.set_mask(id, mask);</pre>
249
+ <pre class="py">world.set_mask(idx, mask)</pre>
250
+
251
+ <h3 id="mask"><code>mask</code></h3>
252
+ <p class="zh">读掩码。</p>
253
+ <p class="en">Read the mask.</p>
254
+ <pre class="rs">world.mask(id)</pre>
255
+ <pre class="py">world.mask(idx)</pre>
256
+
257
+ <h3 id="set_sensor"><code>set_sensor</code></h3>
258
+ <p class="zh">改成传感器或实体。传感器互相看不见,实体仍能看见传感器。</p>
259
+ <p class="en">Turn the body into a sensor or a solid. Sensors do not see each other. A solid still sees sensors.</p>
260
+ <pre class="rs">world.set_sensor(id, true);</pre>
261
+ <pre class="py">world.set_sensor(idx, True)</pre>
262
+
263
+ <h3 id="is_sensor"><code>is_sensor</code></h3>
264
+ <p class="zh">编号不存在时返回假。</p>
265
+ <p class="en">Returns false when the id is missing.</p>
266
+ <pre class="rs">world.is_sensor(id)</pre>
267
+ <pre class="py">world.is_sensor(idx)</pre>
268
+
269
+ <h2><span class="zh">查询</span><span class="en">Queries</span></h2>
270
+
271
+ <h3 id="overlaps"><code>overlaps</code></h3>
272
+ <p class="zh">用它存着的位置,返回重叠到的编号。边贴着不算。传感器不会列出别的传感器。</p>
273
+ <p class="en">Using its stored position, return the overlapping ids. Touching edges do not count. A sensor does not list other sensors.</p>
274
+ <pre class="rs">let hits = world.overlaps(id);</pre>
275
+ <pre class="py">hits = world.overlaps(idx)</pre>
276
+
277
+ <h3 id="overlaps_at"><code>overlaps_at</code></h3>
278
+ <p class="zh">临时放到 <code>(x, y)</code> 再查,不改存着的坐标。</p>
279
+ <p class="en">Query as if it were at <code>(x, y)</code>, without storing that position.</p>
280
+ <pre class="rs">let hits = world.overlaps_at(id, x, y);</pre>
281
+ <p class="zh py">Python 没有这个方法。</p>
282
+ <p class="en py">Not wrapped in Python.</p>
283
+
284
+ <h3 id="query"><code>query</code></h3>
285
+ <p class="zh">一次查很多个编号。结果是 <code>(被查询的编号, 对方)</code>。两边都在名单里时,两个方向都留。选了显卡且精度是 <code>f32</code> 时先走显卡,查不了再整次改走 CPU。显卡路径是实验功能。</p>
286
+ <p class="en">Query many ids at once. Each result is <code>(queried id, other id)</code>. When both ids are in the list, both directions are kept. With a GPU backend and <code>f32</code>, the GPU runs first; if it cannot, the whole query uses the CPU. The GPU path is experimental.</p>
287
+ <pre class="rs">let pairs = world.query(&amp;ids);</pre>
288
+ <pre class="py">pairs = world.query(ids)</pre>
289
+
290
+ <h3 id="query_many"><code>query_many</code></h3>
291
+ <p class="zh">和 <code>query</code> 同一套 CPU 检测,把结果追加进你给的 <code>Vec</code>。不走显卡。</p>
292
+ <p class="en">The same CPU detection as <code>query</code>, appending into a <code>Vec</code> you pass. It does not use the GPU.</p>
293
+ <pre class="rs">world.query_many(&amp;ids, &amp;mut pairs);</pre>
294
+ <p class="zh py">Python 没有这个方法。用 query。</p>
295
+ <p class="en py">Not wrapped in Python. Use query.</p>
296
+
297
+ <h3 id="hit"><code>hit</code></h3>
298
+ <p class="zh">问这两个编号在给定中心上是否重叠。分组和形状都算,位置由参数给出。</p>
299
+ <p class="en">Whether these two ids overlap at the given centers. Groups and shapes count. The positions come from the arguments.</p>
300
+ <pre class="rs">world.hit(a, ax, ay, b, bx, by)</pre>
301
+ <p class="zh py">Python 没有这个方法。</p>
302
+ <p class="en py">Not wrapped in Python.</p>
303
+
304
+ <h2><span class="zh">数量</span><span class="en">Counts</span></h2>
305
+
306
+ <h3 id="len"><code>len</code></h3>
307
+ <p class="zh">实体个数。传感器不算。</p>
308
+ <p class="en">Solid count. Sensors are left out.</p>
309
+ <pre class="rs">world.len()</pre>
310
+ <pre class="py">world.len()</pre>
311
+
312
+ <h3 id="count"><code>count</code></h3>
313
+ <p class="zh">还在世界里的物体,含传感器。</p>
314
+ <p class="en">Bodies still in the world, sensors included.</p>
315
+ <pre class="rs">world.count()</pre>
316
+ <pre class="py">world.count()</pre>
317
+
318
+ <h3 id="contains"><code>contains</code></h3>
319
+ <p class="zh">这个编号是否还在。</p>
320
+ <p class="en">Whether this id is still present.</p>
321
+ <pre class="rs">world.contains(id)</pre>
322
+ <p class="zh py">Python 没有这个方法。</p>
323
+ <p class="en py">Not wrapped in Python.</p>
324
+
325
+ <h3 id="each"><code>each</code></h3>
326
+ <p class="zh">逐个交给回调。<code>BodyView</code> 有 <code>id</code>、<code>x</code>、<code>y</code>、<code>is_sensor</code>。</p>
327
+ <p class="en">Hand each live body to a callback. <code>BodyView</code> has <code>id</code>, <code>x</code>, <code>y</code>, and <code>is_sensor</code>.</p>
328
+ <pre class="rs">world.each(|body| { let _ = body.id; });</pre>
329
+ <p class="zh py">Python 没有这个方法。</p>
330
+ <p class="en py">Not wrapped in Python.</p>
331
+
332
+ <h2><span class="zh">显卡</span><span class="en">GPU</span></h2>
333
+
334
+ <h3 id="set_timing"><code>set_timing</code></h3>
335
+ <p class="zh">打开之后,<code>query</code> 才读显卡上的检测耗时。CPU 后端没有这个数。</p>
336
+ <p class="en">After this is on, <code>query</code> reads GPU detection time. A CPU backend has no such number.</p>
337
+ <pre class="rs">world.set_timing(true);</pre>
338
+ <pre class="py">world.set_timing(True)</pre>
339
+
340
+ <h3 id="detect_ns"><code>detect_ns</code></h3>
341
+ <p class="zh">历次显卡检测耗时合计,单位纳秒。</p>
342
+ <p class="en">Total GPU detection time across queries, in nanoseconds.</p>
343
+ <pre class="rs">world.detect_ns()</pre>
344
+ <pre class="py">world.detect_ns()</pre>
345
+
346
+ <h3 id="has_device"><code>has_device</code></h3>
347
+ <p class="zh">创建时选了显卡,或接上过一块设备。</p>
348
+ <p class="en">A GPU backend was selected, or a device was attached.</p>
349
+ <pre class="rs">world.has_device()</pre>
350
+ <p class="zh py">Python 没有这个方法。</p>
351
+ <p class="en py">Not wrapped in Python.</p>
352
+
353
+ <h3 id="bind_device"><code>bind_device</code></h3>
354
+ <p class="zh">接上程序里已有的 <code>wgpu</code> 设备和队列。之后 <code>query</code> 走这块设备。<code>f64</code> 会返回错误。</p>
355
+ <p class="en">Attach an existing <code>wgpu</code> device and queue. Later <code>query</code> calls use that device. <code>f64</code> returns an error.</p>
356
+ <pre class="rs">world.bind_device(device, queue)?;</pre>
357
+ <p class="zh py">Python 没有这个方法。</p>
358
+ <p class="en py">Not wrapped in Python.</p>
359
+ </div>
360
+ <script>
361
+ function setLang(lang) {
362
+ document.documentElement.lang = lang;
363
+ document.title = lang === "en" ? "Foil — API" : "Foil — 接口";
364
+ document.getElementById("lang").textContent = lang === "en" ? "中文" : "English";
365
+ try { localStorage.setItem("foil-doc-lang", lang); } catch (e) {}
366
+ }
367
+ function setApi(api) {
368
+ document.documentElement.dataset.api = api;
369
+ document.getElementById("api").textContent = api === "py" ? "Rust" : "Python";
370
+ try { localStorage.setItem("foil-doc-api", api); } catch (e) {}
371
+ }
372
+ document.getElementById("lang").addEventListener("click", () => {
373
+ setLang(document.documentElement.lang === "en" ? "zh" : "en");
374
+ });
375
+ document.getElementById("api").addEventListener("click", () => {
376
+ setApi(document.documentElement.dataset.api === "py" ? "rs" : "py");
377
+ });
378
+ let lang = "zh";
379
+ let api = "rs";
380
+ try {
381
+ lang = localStorage.getItem("foil-doc-lang") || "zh";
382
+ api = localStorage.getItem("foil-doc-api") || "rs";
383
+ } catch (e) {}
384
+ setLang(lang === "en" ? "en" : "zh");
385
+ setApi(api === "py" ? "py" : "rs");
386
+ </script>
387
+ </body>
388
+ </html>
@@ -0,0 +1,15 @@
1
+ [build-system]
2
+ requires = ["maturin>=1.5,<2"]
3
+ build-backend = "maturin"
4
+
5
+ [project]
6
+ name = "pyfoil2d"
7
+ version = "0.1.0"
8
+ description = "2D grid collision: 32px cells, two chains, box and circle."
9
+ requires-python = ">=3.13"
10
+ license = { file = "LICENSE" }
11
+
12
+ [tool.maturin]
13
+ manifest-path = "python/Cargo.toml"
14
+ bindings = "pyo3"
15
+ module-name = "Foil"