Skip to content

Commit

Permalink
feat: update section indexing (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsgalarraga authored Mar 5, 2024
1 parent 0dd3900 commit 490c16d
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions packages/board_generator/lib/create_sections.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,15 @@ void main(List<String> args) async {
final sections = <BoardSection>[];
const sectionSize = 300;

var sectionX = minX;
while (sectionX < maxX) {
var sectionY = minY;
while (sectionY < maxY) {
final minSectionX = (minX / sectionSize).floor();
final maxSectionX = (maxX / sectionSize).ceil();
final minSectionY = (minY / sectionSize).floor();
final maxSectionY = (maxY / sectionSize).ceil();

for (var i = minSectionX; i < maxSectionX; i++) {
for (var j = minSectionY; j < maxSectionY; j++) {
final sectionX = i * sectionSize;
final sectionY = j * sectionSize;
final sectionWords = words.where((word) {
return word.isStartInSection(sectionX, sectionY, sectionSize);
}).toList();
Expand All @@ -79,16 +84,13 @@ void main(List<String> args) async {

final section = BoardSection(
id: '',
position: Point(sectionX, sectionY),
position: Point(i, j),
size: sectionSize,
words: sectionWords,
borderWords: borderWords,
);
sections.add(section);

sectionY += sectionSize;
}
sectionX += sectionSize;
}

await crosswordRepository.addSections(sections);
Expand Down

0 comments on commit 490c16d

Please sign in to comment.