@@ -20,8 +20,8 @@ export function buildModel(context) {
2020 return SURFACE_GRID_CACHE . get ( hash )
2121 }
2222 const regionGridContext = buildRegionGridMap ( context )
23- const regionSurfaceMap = buildDirectionTypeMap ( context )
24- const landMaskGrid = buildLandMaskGrid ( { ...context , ...regionGridContext , regionSurfaceMap } )
23+ const directionTypeMap = buildDirectionTypeMap ( context )
24+ const landMaskGrid = buildLandMaskGrid ( { ...context , ...regionGridContext , directionTypeMap } )
2525 const model = { landMaskGrid, ...regionGridContext }
2626 SURFACE_GRID_CACHE . set ( hash , model )
2727 return model
@@ -30,45 +30,57 @@ export function buildModel(context) {
3030
3131function buildDirectionTypeMap ( context ) {
3232 const { world, worldPoint} = context
33+ const surfaceLayer = world . surface
3334 const directionTypeMap = new Map ( )
34- const isWorldPointLand = world . surface . isLand ( worldPoint )
35-
35+ const isWorldPointLand = surfaceLayer . isLand ( worldPoint )
36+ // set center region
37+ directionTypeMap . set ( Direction . CENTER . id , isWorldPointLand )
38+ // set adjacents regions
3639 Point . adjacents ( worldPoint , ( sidePoint , direction ) => {
37- const isSideLand = world . surface . isLand ( sidePoint )
40+ const isSideLand = surfaceLayer . isLand ( sidePoint )
41+ if ( isWorldPointLand == isSideLand ) {
42+ directionTypeMap . set ( direction . id , isSideLand )
43+ }
44+ } )
45+ // set diagonal regions
46+ Point . diagonals ( worldPoint , ( sidePoint , direction ) => {
47+ const ortoDirs = Direction . getComponents ( direction )
48+ const orto1 = Point . atDirection ( worldPoint , ortoDirs [ 0 ] )
49+ const orto2 = Point . atDirection ( worldPoint , ortoDirs [ 1 ] )
3850 if ( isWorldPointLand ) {
39- if ( isSideLand ) {
40- const type = isWaterChannel ( context , direction ) ? REGION_WATER : REGION_LAND
41- directionTypeMap . set ( direction . id , type )
42- }
43- } else if ( ! isSideLand ) {
44- directionTypeMap . set ( direction . id , REGION_WATER )
51+ const sameType = surfaceLayer . isLand ( sidePoint )
52+ const ortoDiff = surfaceLayer . isWater ( orto1 ) && surfaceLayer . isWater ( orto2 )
53+ if ( sameType && ortoDiff )
54+ directionTypeMap . set ( direction . id , REGION_WATER )
55+ } else {
56+ const sameType = surfaceLayer . isWater ( sidePoint )
57+ const ortoDiff = surfaceLayer . isLand ( orto1 ) && surfaceLayer . isLand ( orto2 )
58+ if ( sameType && ortoDiff )
59+ directionTypeMap . set ( direction . id , REGION_WATER )
4560 }
4661 } )
4762 return directionTypeMap
4863}
4964
5065
51- function isWaterChannel ( context , direction ) {
52- const { world, worldPoint} = context
53- const ortoDirs = Direction . getComponents ( direction )
54- if ( ortoDirs . length != 2 ) return false
55- const isWater1 = world . surface . isWater ( Point . atDirection ( worldPoint , ortoDirs [ 0 ] ) )
56- const isWater2 = world . surface . isWater ( Point . atDirection ( worldPoint , ortoDirs [ 1 ] ) )
57- return isWater1 && isWater2
58- }
59-
60-
6166function buildLandMaskGrid ( context ) {
62- /*
63- Generate a boolean grid (land or water)
64- */
65- const { worldPoint, world, rect, zoneRect} = context
67+ // Generate a boolean grid (land or water)
68+ const {
69+ worldPoint, world, rect, zoneRect, regionGrid,
70+ directionTypeMap, regionDirMap
71+ } = context
6672 const relativePoint = Point . multiplyScalar ( worldPoint , zoneRect . width )
6773 const noiseRect = Rect . multiply ( rect , zoneRect . width )
6874 return Grid . fromRect ( zoneRect , zonePoint => {
6975 // if (! world.surface.isBorder(worldPoint)) {
7076 // return world.surface.isLand(worldPoint)
7177 // }
78+ const regionId = regionGrid . get ( zonePoint )
79+ const regionDirId = regionDirMap . get ( regionId )
80+ const regionType = directionTypeMap . get ( regionDirId )
81+ // if (regionType === REGION_LAND || regionType === REGION_WATER) {
82+ // return regionType
83+ // }
7284 const noisePoint = Point . plus ( relativePoint , zonePoint )
7385 const noise = world . noise . get4DZoneOutline ( noiseRect , noisePoint )
7486 return noise > SURFACE_NOISE_RATIO ? REGION_LAND : REGION_WATER
0 commit comments