11import type { AtomInterface } from './types/atomic' ;
22import type { NumericVector } from '../math/types' ;
3- import type { ClusterInterface , ClusterManagerInterface , ClusterMapInterface } from './types/cluster ' ;
3+ import type { SectorInterface , SectorManagerInterface , SectorMapInterface } from './types/sector ' ;
44
55function incPoint ( aPoint : NumericVector , aCenterPoint : NumericVector , aDim : number ) : boolean {
66 aPoint [ aDim ] ++ ;
@@ -26,7 +26,7 @@ function getNeighboursCoords(coords: NumericVector): Iterable<NumericVector> {
2626 return result ;
2727}
2828
29- class Cluster implements ClusterInterface {
29+ class Sector implements SectorInterface {
3030 atoms : Set < AtomInterface > = new Set < AtomInterface > ( ) ;
3131 coords : NumericVector ;
3232
@@ -55,8 +55,8 @@ class Cluster implements ClusterInterface {
5555 }
5656}
5757
58- class ClusterMap implements ClusterMapInterface {
59- map : Map < number , Cluster > = new Map ( ) ;
58+ class SectorMap implements SectorMapInterface {
59+ map : Map < number , Sector > = new Map ( ) ;
6060 quantum : number ;
6161 phase : number ;
6262
@@ -65,20 +65,20 @@ class ClusterMap implements ClusterMapInterface {
6565 this . phase = phase ;
6666 }
6767
68- getNeighbourhood ( atom : AtomInterface ) : ClusterInterface [ ] {
68+ getNeighbourhood ( atom : AtomInterface ) : SectorInterface [ ] {
6969 const result = [ ] ;
70- const currentCluster = this . handleAtom ( atom ) ;
71- for ( const coords of getNeighboursCoords ( currentCluster . coords ) ) {
72- const cluster = this . getCluster ( coords ) ;
73- result . push ( cluster ) ;
70+ const currentSector = this . handleAtom ( atom ) ;
71+ for ( const coords of getNeighboursCoords ( currentSector . coords ) ) {
72+ const sector = this . getSector ( coords ) ;
73+ result . push ( sector ) ;
7474 }
7575 return result ;
7676 }
7777
7878 countAtoms ( ) : number {
7979 let result = 0 ;
80- for ( const [ , cluster ] of this . map ) {
81- result += cluster . length ;
80+ for ( const [ , sector ] of this . map ) {
81+ result += sector . length ;
8282 }
8383 return result ;
8484 }
@@ -87,37 +87,37 @@ class ClusterMap implements ClusterMapInterface {
8787 this . map . clear ( ) ;
8888 }
8989
90- public handleAtom ( atom : AtomInterface ) : ClusterInterface {
91- const actualCluster = this . getClusterByAtom ( atom ) ;
92- const currentCluster = atom . cluster ;
90+ public handleAtom ( atom : AtomInterface ) : SectorInterface {
91+ const actualSector = this . getSectorByAtom ( atom ) ;
92+ const currentSector = atom . sector ;
9393
94- if ( actualCluster !== currentCluster ) {
95- if ( currentCluster !== undefined ) {
96- currentCluster . remove ( atom ) ;
94+ if ( actualSector !== currentSector ) {
95+ if ( currentSector !== undefined ) {
96+ currentSector . remove ( atom ) ;
9797 }
98- actualCluster . add ( atom ) ;
99- atom . cluster = actualCluster ;
98+ actualSector . add ( atom ) ;
99+ atom . sector = actualSector ;
100100 }
101101
102- return actualCluster ;
102+ return actualSector ;
103103 }
104104
105- public getCluster ( clusterCoords : NumericVector ) : ClusterInterface {
106- const key = clusterCoords . length === 3
107- ? clusterCoords [ 0 ] * 10000 + clusterCoords [ 1 ] * 100000000 + clusterCoords [ 2 ]
108- : clusterCoords [ 0 ] * 10000 + clusterCoords [ 1 ] ;
105+ public getSector ( sectorCoords : NumericVector ) : SectorInterface {
106+ const key = sectorCoords . length === 3
107+ ? sectorCoords [ 0 ] * 10000 + sectorCoords [ 1 ] * 100000000 + sectorCoords [ 2 ]
108+ : sectorCoords [ 0 ] * 10000 + sectorCoords [ 1 ] ;
109109
110110 if ( ! this . map . has ( key ) ) {
111- this . map . set ( key , new Cluster ( [ ...clusterCoords ] ) ) ;
111+ this . map . set ( key , new Sector ( [ ...sectorCoords ] ) ) ;
112112 }
113113
114- return this . map . get ( key ) as Cluster ;
114+ return this . map . get ( key ) as Sector ;
115115 }
116116
117117 public findAtomByCoords ( coords : NumericVector , radiusMap : number [ ] , radiusMultiplier : number ) : AtomInterface | undefined {
118- const clusterCoords = this . getClusterCoords ( coords ) ;
119- const cluster = this . getCluster ( clusterCoords ) ;
120- for ( const atom of cluster ) {
118+ const sectorCoords = this . getSectorCoords ( coords ) ;
119+ const sector = this . getSector ( sectorCoords ) ;
120+ for ( const atom of sector ) {
121121 const dist = atom . position . clone ( ) . sub ( coords ) . abs ;
122122 if ( dist <= radiusMap [ atom . type ] * radiusMultiplier ) {
123123 return atom ;
@@ -126,12 +126,12 @@ class ClusterMap implements ClusterMapInterface {
126126 return undefined ;
127127 }
128128
129- private getClusterByAtom ( atom : AtomInterface ) : ClusterInterface {
130- const clusterCoords = this . getClusterCoords ( atom . position ) ;
131- return this . getCluster ( clusterCoords ) ;
129+ private getSectorByAtom ( atom : AtomInterface ) : SectorInterface {
130+ const sectorCoords = this . getSectorCoords ( atom . position ) ;
131+ return this . getSector ( sectorCoords ) ;
132132 }
133133
134- private getClusterCoords ( coords : NumericVector ) : NumericVector {
134+ private getSectorCoords ( coords : NumericVector ) : NumericVector {
135135 const result : NumericVector = new Array < number > ( coords . length ) ;
136136 for ( let i = 0 ; i < coords . length ; ++ i ) {
137137 result [ i ] = Math . round ( coords [ i ] / this . quantum ) + this . phase ;
@@ -140,11 +140,11 @@ class ClusterMap implements ClusterMapInterface {
140140 }
141141}
142142
143- export class ClusterManager implements ClusterManagerInterface {
144- private readonly map : ClusterMap ;
143+ export class SectorManager implements SectorManagerInterface {
144+ private readonly map : SectorMap ;
145145
146146 constructor ( quantum : number ) {
147- this . map = new ClusterMap ( quantum , 0 ) ;
147+ this . map = new SectorMap ( quantum , 0 ) ;
148148 }
149149
150150 countAtoms ( ) : number {
@@ -161,8 +161,8 @@ export class ClusterManager implements ClusterManagerInterface {
161161 for ( let i = cc . coords [ 0 ] - 1 ; i <= cc . coords [ 0 ] + 1 ; ++ i ) {
162162 for ( let j = cc . coords [ 1 ] - 1 ; j <= cc . coords [ 1 ] + 1 ; ++ j ) {
163163 for ( let k = cc . coords [ 2 ] - 1 ; k <= cc . coords [ 2 ] + 1 ; ++ k ) {
164- const cluster = this . map . getCluster ( [ i , j , k ] ) ;
165- for ( const neighbour of cluster . atoms ) {
164+ const sector = this . map . getSector ( [ i , j , k ] ) ;
165+ for ( const neighbour of sector . atoms ) {
166166 callback ( atom , neighbour ) ;
167167 }
168168 }
@@ -172,17 +172,17 @@ export class ClusterManager implements ClusterManagerInterface {
172172 const cc = this . map . handleAtom ( atom ) ;
173173 for ( let i = cc . coords [ 0 ] - 1 ; i <= cc . coords [ 0 ] + 1 ; ++ i ) {
174174 for ( let j = cc . coords [ 1 ] - 1 ; j <= cc . coords [ 1 ] + 1 ; ++ j ) {
175- const cluster = this . map . getCluster ( [ i , j ] ) ;
176- for ( const neighbour of cluster . atoms ) {
175+ const sector = this . map . getSector ( [ i , j ] ) ;
176+ for ( const neighbour of sector . atoms ) {
177177 callback ( atom , neighbour ) ;
178178 }
179179 }
180180 }
181181 } else {
182182 const neighborhood = this . map . getNeighbourhood ( atom ) ;
183183 for ( let i = 0 ; i < neighborhood . length ; ++ i ) {
184- const cluster = neighborhood [ i ] ;
185- for ( const neighbour of cluster . atoms ) {
184+ const sector = neighborhood [ i ] ;
185+ for ( const neighbour of sector . atoms ) {
186186 callback ( atom , neighbour ) ;
187187 }
188188 }
0 commit comments