[Feature Request] Create generator for matrix values.
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 74/100
Research direction
Start by reading MatrixInterface and the Matrix implementation, then check how getBlockCount() and getBlockValue() are used and tested. Add a generator that yields row and column indexes for blocks whose value is 1; done means callers can iterate with foreach as shown in the issue and the behavior is covered by a test.
Written by the indexing model from the issue text.
Description
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]) {
// ...
}
- Dominant language
- PHP
- Stars
- 4.8k
- Forks
- 766
- Avg merge
- 10h 51m
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from endroid/qr-code
-
Difficulty 2/5 1-3 hours Newbie friendliness 45/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 38/100
-
[Feature Request] Implement logoPunchoutBackground in SVG writerMay be free again @endroid claimed this 735 days ago, and no pull request is open. Openenhancement
-
[Feature Request] Arabic RTL LabelsMay be free again @endroid claimed this 1000 days ago, and no pull request is open. Openenhancement
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
mailcow/mailcow-dockerized#7677 · 1 comment ·
Maintainers usually reply within 1 day
-
a11y
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
-
wpvc
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
10up/ElasticPressLabs#254 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
🧑💻 tech-debt
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
guibranco/gstraccini-bot-service#1206 ·
Maintainers usually reply within 1 day