@@ -57,22 +57,20 @@ const VALID_BOUNDARIES: Boundaries<AbsoluteNumber> = {
5757 yMax : 1.1 as AbsoluteNumber ,
5858}
5959
60- const validatePatternPosition = ( pattern : AbsolutePattern ) : boolean => {
61- return getPatternPoints ( pattern ) . some ( p => pointIsInBoundaries ( p , VALID_BOUNDARIES ) )
62- }
60+ const isValidPattern = ( pattern : AbsolutePattern ) : boolean => {
61+ const { xMin, xMax, yMin, yMax } = getBoundariesFromPattern ( pattern )
6362
64- const validatePatternSize = ( pattern : AbsolutePattern ) : boolean => {
65- const boundaries = getBoundariesFromPattern ( pattern )
6663 return (
67- boundaries . xMax - boundaries . xMin >= MIN_PATTERN_SIZE ||
68- boundaries . yMax - boundaries . yMin >= MIN_PATTERN_SIZE
64+ // Pattern fulfills minimum size.
65+ xMax - xMin >= MIN_PATTERN_SIZE &&
66+ yMax - yMin >= MIN_PATTERN_SIZE &&
67+ // X and Y ranges overlap with the valid boundaries.
68+ // We will only render patterns if at least one corner is inside the valid boundaries.
69+ ( xMin <= VALID_BOUNDARIES . xMax && xMax >= VALID_BOUNDARIES . xMin ) &&
70+ ( yMin <= VALID_BOUNDARIES . yMax && yMax >= VALID_BOUNDARIES . yMin )
6971 )
7072}
7173
72- const isValidPattern = ( pattern : AbsolutePattern ) : boolean => {
73- return validatePatternSize ( pattern ) && validatePatternPosition ( pattern )
74- }
75-
7674const measure = ( f : ( ) => void ) : number => {
7775 const start = performance . now ( )
7876
@@ -85,10 +83,11 @@ const measure = (f: () => void): number => {
8583
8684const drawScreen = (
8785 ctx : CanvasRenderingContext2D ,
86+ screenSize : Size ,
8887 absolutePattern : AbsolutePattern ,
8988 strokeStyle : string
9089) : void => {
91- const viewportPattern = mapPatternToViewportSpace ( absolutePattern , getScreenSize ( ctx ) )
90+ const viewportPattern = mapPatternToViewportSpace ( absolutePattern , screenSize )
9291 const [ p1 , p2 , p3 , p4 ] = getPatternPoints ( viewportPattern )
9392
9493 ctx . lineWidth = 1
@@ -117,6 +116,8 @@ const draw = (
117116 globalMutableState : GlobalMutableState ,
118117 queue : QueueEntry [ ]
119118) : void => {
119+ const screenSize = getScreenSize ( ctx )
120+
120121 while ( queue . length > 0 ) {
121122 globalMutableState . queueIterations += 1
122123 const { currentPattern, depth } = queue . shift ( ) !
@@ -126,7 +127,7 @@ const draw = (
126127 if ( depth > MIN_DEPTH && globalMutableState . drawScreenCalls >= MAX_DRAW_CALLS ) break
127128
128129 globalMutableState . drawScreenCalls += 1
129- drawScreen ( ctx , currentPattern , COLORS [ Math . min ( COLORS . length - 1 , depth ) ] ! )
130+ drawScreen ( ctx , screenSize , currentPattern , COLORS [ Math . min ( COLORS . length - 1 , depth ) ] ! )
130131
131132 for ( const pattern of state . patterns ) {
132133 const virtualScreen = combinePatterns ( currentPattern , pattern )
0 commit comments