-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Physics decomposed to new Interface.
- Loading branch information
Showing
14 changed files
with
72 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { TypesConfig, WorldConfig } from "../types/config"; | ||
import type { AtomInterface } from "../types/atomic"; | ||
import type { PhysicModelInterface } from "../types/interaction"; | ||
|
||
export class PhysicModelV1 implements PhysicModelInterface { | ||
private WORLD_CONFIG: WorldConfig; | ||
private TYPES_CONFIG: TypesConfig; | ||
|
||
constructor(worldConfig: WorldConfig, typesConfig: TypesConfig) { | ||
this.WORLD_CONFIG = worldConfig; | ||
this.TYPES_CONFIG = typesConfig; | ||
} | ||
|
||
getGravityForce(lhs: AtomInterface, rhs: AtomInterface, dist2: number): number { | ||
let multiplier: number; | ||
|
||
if (dist2 < (this.WORLD_CONFIG.ATOM_RADIUS * 2) ** 2) { | ||
multiplier = -this.WORLD_CONFIG.BOUNCE_FORCE_MULTIPLIER; | ||
} else if (!lhs.bonds.has(rhs)) { | ||
multiplier = this.WORLD_CONFIG.GRAVITY_FORCE_MULTIPLIER * this.TYPES_CONFIG.GRAVITY[lhs.type][rhs.type]; | ||
} else { | ||
multiplier = this.WORLD_CONFIG.GRAVITY_FORCE_MULTIPLIER * this.TYPES_CONFIG.LINK_GRAVITY[lhs.type][rhs.type]; | ||
} | ||
|
||
const result = multiplier * this.WORLD_CONFIG.SPEED / dist2; | ||
|
||
if (Math.abs(result) > this.WORLD_CONFIG.MAX_FORCE) { | ||
return Math.sign(result) * this.WORLD_CONFIG.MAX_FORCE; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
getLinkForce(): number { | ||
const result = Math.min(this.WORLD_CONFIG.LINK_FORCE_MULTIPLIER * this.WORLD_CONFIG.SPEED); | ||
|
||
if (Math.abs(result) > this.WORLD_CONFIG.MAX_FORCE) { | ||
return Math.sign(result) * this.WORLD_CONFIG.MAX_FORCE; | ||
} | ||
|
||
return result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters