[Feature Request] Create generator for matrix values.
还没有人认领这个 Issue。
评估
调研方向
先阅读 MatrixInterface 和 Matrix 的实现,然后检查 getBlockCount() 和 getBlockValue() 的使用方式及测试情况。添加一个生成器,用于产出值为 1 的块的行索引和列索引;完成标准是调用方可以像 issue 中所示那样使用 foreach 迭代,并且该行为有测试覆盖。
由索引模型根据 Issue 内容生成。
描述
When using MatrixInterface, you often write code like this:
$matrix = ...
$blockCount = $matrix->getBlockCount();
for ($rowIndex = 0; $rowIndex < $blockCount; ++$rowIndex) {
for ($columnIndex = 0; $columnIndex < $blockCount; ++$columnIndex) {
if (1 === $matrix->getBlockValue($rowIndex, $columnIndex)) {
// ...
}
}
}
It would be nice to create a new function (a generator) that returns the row and column indices only for valid values:
interface MatrixInterface {
/**
* @return \Generator<array{0: int, 1: int}>
*/
public function getIndexes(): \Generator;
}
And the implementation:
final readonly class Matrix implements MatrixInterface {
#[\Override]
public function getIndexes(): \Generator {
$blockCount = $this->getBlockCount();
for ($rowIndex = 0; $rowIndex < $blockCount; ++$rowIndex) {
for ($columnIndex = 0; $columnIndex < $blockCount; ++$columnIndex) {
if (1 === $this->getBlockValue($rowIndex, $columnIndex)) {
yield [$rowIndex, $columnIndex];
}
}
}
}
}
Then use as follow:
$matrix = ...
foreach ($matrix->getIndexes() as [$rowIndex, $columnIndex]) {
// ...
}
- 主要语言
- PHP
- 星标
- 4.8k
- 派生
- 766
- 平均合并
- 10 小时 51 分钟
- 30 天内合并 PR
- 1
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
endroid/qr-code 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 45/100
-
难度 2/5 1-3 小时 新手友好度 38/100
-
[Feature Request] Implement logoPunchoutBackground in SVG writer可能重新可做 @endroid 于 735 天前认领,目前没有进行中的 PR。 未关闭enhancement
-
[Feature Request] Arabic RTL Labels可能重新可做 @endroid 于 1000 天前认领,目前没有进行中的 PR。 未关闭enhancement
-
难度 4/5 3-5 天 新手友好度 38/100
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 68/100
mailcow/mailcow-dockerized#7677 · 1 条评论 ·
维护者通常 1 天内回复
-
a11y
难度 2/5 1-3 小时 新手友好度 67/100
-
wpvc
难度 2/5 1-3 小时 新手友好度 75/100
10up/ElasticPressLabs#254 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
🧑💻 tech-debt
难度 2/5 1-3 小时 新手友好度 70/100
guibranco/gstraccini-bot-service#1206 ·
维护者通常 1 天内回复