1- import { combinePatterns , mapPatternToViewportSpace , mutateBoundariesFromPattern } from '../functions'
1+ import {
2+ applyMatrixAndOffsetToRectangle ,
3+ combineTransformations ,
4+ getMatrixAndOffsetFromRectangle ,
5+ mapPatternToViewportSpace ,
6+ mutateBoundariesFromPattern ,
7+ } from '../functions'
28import { Queue } from '../queue'
3- import { Boundaries , Size , State , ViewportNumber , ViewportPattern } from '../types'
9+ import {
10+ AbsolutePoint ,
11+ Boundaries ,
12+ Size ,
13+ State ,
14+ Transformation ,
15+ ViewportNumber ,
16+ ViewportPattern ,
17+ } from '../types'
418import { MAX_DEPTH , MAX_QUEUE_SIZE , MIN_PATTERN_SIZE_PX } from './constants'
519
620// We'll ignore everything that's a bit outside the viewport.
@@ -16,7 +30,12 @@ function getViewportBoundaries(screenSize: Size): Boundaries<ViewportNumber> {
1630}
1731
1832type QueueEntry = {
19- currentPattern : ViewportPattern
33+ currentTransformation : Transformation
34+ depth : number
35+ }
36+
37+ type DrawablePattern = {
38+ pattern : ViewportPattern
2039 depth : number
2140}
2241
@@ -65,7 +84,7 @@ export function* streamDrawablePatterns({
6584} : {
6685 state : State
6786 screenSize : Size
68- } ) : Generator < QueueEntry , void , void > {
87+ } ) : Generator < DrawablePattern , void , void > {
6988 console . log (
7089 `generateDrawQueue start. Initial screens: ${ state . screens . length } , Patterns: ${ state . patterns . length } `
7190 )
@@ -76,9 +95,14 @@ export function* streamDrawablePatterns({
7695
7796 for ( const screen of state . screens ) {
7897 patternQueue . push ( {
79- currentPattern : mapPatternToViewportSpace ( screen , screenSize ) ,
98+ currentTransformation : getMatrixAndOffsetFromRectangle ( screen ) ,
8099 depth : 0 ,
81100 } )
101+
102+ yield {
103+ pattern : mapPatternToViewportSpace ( screen , screenSize ) ,
104+ depth : 0 ,
105+ }
82106 }
83107
84108 let iterations = 0
@@ -87,8 +111,6 @@ export function* streamDrawablePatterns({
87111
88112 const entry = patternQueue . shift ( )
89113
90- yield entry
91-
92114 // Don't add patterns that are too deep.
93115 if ( entry . depth >= MAX_DEPTH ) {
94116 console . log (
@@ -97,13 +119,34 @@ export function* streamDrawablePatterns({
97119 break
98120 }
99121
100- for ( const { pattern } of state . patterns ) {
122+ for ( const { matrix , offset } of state . patterns ) {
101123 // Get new pattern
102- const newViewportPattern = combinePatterns ( entry . currentPattern , pattern )
124+ const newTransformation = combineTransformations (
125+ entry . currentTransformation . matrix ,
126+ entry . currentTransformation . offset ,
127+ matrix ,
128+ offset
129+ )
130+
131+ const transformedUnit = applyMatrixAndOffsetToRectangle (
132+ newTransformation . matrix ,
133+ newTransformation . offset ,
134+ {
135+ anchor : [ 0 , 0 ] as AbsolutePoint ,
136+ target : [ 1 , 1 ] as AbsolutePoint ,
137+ }
138+ )
139+
140+ const newScreen = mapPatternToViewportSpace ( transformedUnit , screenSize )
141+
142+ if ( isValidPattern ( newScreen , viewportBoundaries ) ) {
143+ yield {
144+ pattern : newScreen ,
145+ depth : entry . depth + 1 ,
146+ }
103147
104- if ( isValidPattern ( newViewportPattern , viewportBoundaries ) ) {
105148 patternQueue . push ( {
106- currentPattern : newViewportPattern ,
149+ currentTransformation : newTransformation ,
107150 depth : entry . depth + 1 ,
108151 } )
109152
0 commit comments