├── bigbang ├── rustfmt.toml ├── 3d_example.gif ├── generate_header.sh ├── src │ ├── simulation_result.rs │ ├── dimension.rs │ ├── lib.rs │ ├── responsive.rs │ ├── as_entity.rs │ ├── collisions.rs │ ├── utilities.rs │ ├── grav_tree.rs │ ├── entity.rs │ └── node.rs ├── Makefile ├── grav_tree.h ├── Cargo.toml ├── bigbang.h ├── cbindgen.toml ├── tests │ ├── test.rs │ └── correctness.rs ├── README.md ├── benches │ └── theta.rs ├── test_files │ └── test_output.txt └── LICENSE.md ├── .gitignore ├── Cargo.toml ├── examples ├── src │ ├── websocket_3d │ │ ├── frontend │ │ │ ├── disc.png │ │ │ ├── index.css │ │ │ ├── index.html │ │ │ └── index.js │ │ └── server.rs │ ├── 2d_js │ │ ├── README.md │ │ ├── visualize.html │ │ └── main.rs │ ├── README.md │ └── basic_simulation │ │ └── main.rs ├── README.md └── Cargo.toml ├── bigbang_derive ├── README.md ├── Cargo.toml └── src │ └── lib.rs ├── .travis.yml ├── .github └── FUNDING.yml └── README.md /bigbang/rustfmt.toml: -------------------------------------------------------------------------------- 1 | edition = "2018" 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target 2 | test_files/test_output.txt 3 | .idea 4 | -------------------------------------------------------------------------------- /bigbang/3d_example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sezna/bigbang/HEAD/bigbang/3d_example.gif -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = [ 3 | "bigbang", 4 | "bigbang_derive", 5 | "examples" 6 | ] -------------------------------------------------------------------------------- /bigbang/generate_header.sh: -------------------------------------------------------------------------------- 1 | cbindgen --config cbindgen.toml --crate bigbang --output bigbang.h 2 | -------------------------------------------------------------------------------- /examples/src/websocket_3d/frontend/disc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sezna/bigbang/HEAD/examples/src/websocket_3d/frontend/disc.png -------------------------------------------------------------------------------- /bigbang_derive/README.md: -------------------------------------------------------------------------------- 1 | # Bigbang Derive 2 | 3 | This crate houses the bigbang derive proc macro which implements `AsEntity` for a struct which contains the fields -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: rust 2 | rust: 3 | - nightly 4 | script: 5 | - (cd examples && cargo build --bin 2d_js) 6 | - (cd examples && cargo build --bin basic_simulation) 7 | - (cd examples && cargo build --bin websocket_3d_server) 8 | - cargo test 9 | - cargo bench -------------------------------------------------------------------------------- /bigbang/src/simulation_result.rs: -------------------------------------------------------------------------------- 1 | pub struct SimulationResult<'a, T> { 2 | /// The result of the simulation's collision check 3 | /// just a vector of references to potential collisions 4 | pub collisions: Vec<&'a T>, 5 | pub gravitational_acceleration: (f64, f64, f64), 6 | } 7 | -------------------------------------------------------------------------------- /examples/src/2d_js/README.md: -------------------------------------------------------------------------------- 1 | # 2d_js 2 | This example runs a 2d simulation in your browser using charts.js. It is pretty glitchy due to using charts.js, which is entirely suboptimal and should just be a canvas or something. 3 | 4 | Run this example with `cargo run --bin 2d_js`, and then browse to `localhost:4001`. -------------------------------------------------------------------------------- /examples/src/websocket_3d/frontend/index.css: -------------------------------------------------------------------------------- 1 | html, 2 | body { 3 | padding: 0; 4 | margin: 0; 5 | overflow: hidden; 6 | } 7 | 8 | body { 9 | background-color: #111; 10 | } 11 | 12 | #viz-controls { 13 | margin-right: 11px; 14 | display: inline-block; 15 | z-index: 30; 16 | position: absolute; 17 | top: 0; 18 | right: 0; 19 | } 20 | -------------------------------------------------------------------------------- /examples/README.md: -------------------------------------------------------------------------------- 1 | # Bigbang Examples 2 | 3 | A set of examples and simulations that can serve as starting points or references. 4 | S 5 | ## How to Run an Example 6 | Some examples may have specific instructions on how to run them. In this case, refer to that folder's individual `README.md`. In general, an example can be run with: 7 | ``` 8 | cargo run --bin 9 | ``` -------------------------------------------------------------------------------- /bigbang_derive/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bigbang_derive" 3 | version = "0.1.0" 4 | authors = ["Alex Hansen "] 5 | edition = "2018" 6 | description = "Convenience macro for crates.io/crates/bigbang" 7 | license = "MIT" 8 | 9 | [dependencies] 10 | quote = "1.0.2" 11 | syn = { version = "1.0", features = ["derive"] } 12 | proc-macro2 = "1.0" 13 | 14 | [lib] 15 | proc-macro = true 16 | -------------------------------------------------------------------------------- /bigbang/Makefile: -------------------------------------------------------------------------------- 1 | # This Makefile is based off of one I found here: 2 | # https://www.greyblake.com/blog/2017-08-10-exposing-rust-library-to-c/ 3 | GCC_BIN ?= $(shell which gcc) 4 | CARGO_BIN ?= $(shell which cargo) 5 | 6 | run: clean build 7 | ./examples/c_example 8 | clean: 9 | $(CARGO_BIN) clean 10 | rm -f ./examples/c_example 11 | build: 12 | $(CARGO_BIN) build --release 13 | $(GCC_BIN) -std=c99 -o ./examples/c_example ./examples/c_example.c -Isrc -L./target/release/ -lbigbang 14 | -------------------------------------------------------------------------------- /examples/src/README.md: -------------------------------------------------------------------------------- 1 | # Websocket Bigbang Example 2 | This example will run a 3d simulation in your browser using three.js. There are two components that must be run: the server and the client. The server can be run with `cargo run --bin websocket_3d_server`. The frontend in this folder must be served manually, either by something like `miniserve .` or `python -m SimpleHTTPServer `. Then, browse to where you are hosting the frontend and view the simulation. 3 | 4 | A PR to make the server also host the frontend like the `2d_js` example would be welcome. :) -------------------------------------------------------------------------------- /bigbang/src/dimension.rs: -------------------------------------------------------------------------------- 1 | use serde::{Deserialize, Serialize}; 2 | #[derive(Clone, PartialEq, Serialize, Deserialize)] 3 | /// Used to represent which dimension the GravTree node has split on. 4 | pub enum Dimension { 5 | X, 6 | Y, 7 | Z, 8 | } 9 | 10 | /// Convenience function that returns the Dimension as a &str. 11 | impl Dimension { 12 | pub fn as_string(&self) -> &str { 13 | match *self { 14 | Dimension::X => "X", 15 | Dimension::Y => "Y", 16 | Dimension::Z => "Z", 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /bigbang/src/lib.rs: -------------------------------------------------------------------------------- 1 | //! For more details on usage, see [the README](https://github.com/sezna/blob/master/README.md). 2 | extern crate either; 3 | extern crate rayon; 4 | mod as_entity; 5 | mod dimension; 6 | mod entity; 7 | mod grav_tree; 8 | mod node; 9 | mod responsive; 10 | mod simulation_result; 11 | mod utilities; 12 | 13 | use dimension::Dimension; 14 | use node::Node; 15 | /* public-facing entry points */ 16 | pub use as_entity::AsEntity; 17 | pub use bigbang_derive::AsEntity; 18 | pub use entity::{CalculateCollisions, Entity}; 19 | pub use grav_tree::GravTree; 20 | pub use responsive::Responsive; 21 | pub use simulation_result::SimulationResult; 22 | pub mod collisions; 23 | -------------------------------------------------------------------------------- /bigbang/src/responsive.rs: -------------------------------------------------------------------------------- 1 | use crate::SimulationResult; 2 | 3 | /// Define how to respond to the results of the simulation at every time step. 4 | pub trait Responsive { 5 | /// Respond to the forces that bigbang has calculated are acting upon the entity. 6 | /// It is recommended to at least set the position to where the simulation says 7 | /// it should be and add the velocity to the position. See the examples directory for examples. 8 | /// Basic collision functions are available in [collisions](crate::collisions]. 9 | fn respond(&self, simulation_result: SimulationResult, time_step: f64) -> Self 10 | where 11 | Self: std::marker::Sized; 12 | } 13 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [sezna] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /bigbang/grav_tree.h: -------------------------------------------------------------------------------- 1 | #include "stdint.h" 2 | 3 | /** 4 | * An Entity is an object (generalized to be spherical, having only a radius dimension) which has 5 | * velocity, position, radius, and mass. This gravitational tree contains many entities and it moves 6 | * them around according to the gravity they exert on each other. 7 | */ 8 | typedef struct Entity { 9 | float vx; 10 | float vy; 11 | float vz; 12 | float x; 13 | float y; 14 | float z; 15 | float radius; 16 | float mass; 17 | } Entity; 18 | 19 | void *from_data_file(const char *file_path_buff); 20 | 21 | void *new(const Entity *array, int length); 22 | 23 | void *time_step(void *gravtree_buf); 24 | 25 | void write_data_file(const char *file_path_buff, unsigned char *gravtree_buf); 26 | -------------------------------------------------------------------------------- /bigbang/src/as_entity.rs: -------------------------------------------------------------------------------- 1 | use crate::entity::Entity; 2 | 3 | /// [[GravTree]] works with any type which implements [[AsEntity]] and [[Responsive]]. In order to implement [[AsEntity]], 4 | /// a type must be able to represent itself as a gravitational spatial entity. This, simply, entails 5 | /// constructing an [[Entity]] from the type, and defining how to add acceleration to the velocity of your type. 6 | /// 7 | /// More generally, this entails that a type must contain, or be able to derive, its velocity, position, 8 | /// radius and mass, and it must be able to respond to acceleration impulses in the form of triples of `f64`s. 9 | pub trait AsEntity { 10 | /// Return an [[Entity]] representation of your struct. 11 | fn as_entity(&self) -> Entity; 12 | } 13 | -------------------------------------------------------------------------------- /bigbang/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | edition = "2018" 3 | name = "bigbang" 4 | version = "0.0.11" 5 | authors = ["Alex "] 6 | license-file = "LICENSE.md" 7 | description = "An optimized framework for n-(hard)-body gravitational simulation" 8 | repository = "https://github.com/sezna/bigbang" 9 | keywords = ["nbody", "gravity", "simulation"] 10 | categories = ["simulation"] 11 | exclude = ["test_files/*"] 12 | readme = "README.md" 13 | documentation = "https://docs.rs/bigbang" 14 | 15 | [dependencies] 16 | either = "1.5" 17 | rayon = "1.3" 18 | serde = { version = "1.0", features = ["derive"] } 19 | bigbang_derive = { path = "../bigbang_derive", version = "0.1.0" } 20 | 21 | [dev-dependencies] 22 | criterion = "0.3" 23 | rand = "0.7.0" 24 | 25 | [lib] 26 | crate-type = ["cdylib", "lib", "staticlib"] 27 | 28 | [[bench]] 29 | name = "theta" 30 | harness = false 31 | -------------------------------------------------------------------------------- /examples/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "bigbang_examples" 3 | version = "0.1.0" 4 | authors = ["Alex Hansen "] 5 | edition = "2018" 6 | 7 | [[bin]] 8 | name = "websocket_3d_server" 9 | path = "src/websocket_3d/server.rs" 10 | 11 | [[bin]] 12 | name = "2d_js" 13 | path = "src/2d_js/main.rs" 14 | 15 | [[bin]] 16 | name = "basic_simulation" 17 | path = "src/basic_simulation/main.rs" 18 | 19 | 20 | [dependencies] 21 | bigbang = { path = "../bigbang" } 22 | iron = "0.6" 23 | router = "0.6" 24 | staticfile = "0.5.0" 25 | serde_derive = "1.0.100" 26 | serde = "1.0.100" 27 | mount = "0.4.0" 28 | serde_json = "1.0.40" 29 | lazy_static = "1.4.0" 30 | iron-cors = "0.8.0" 31 | websocket = "0.23.0" 32 | multiqueue = "0.3.2" 33 | tokio = "0.1.22" 34 | tokio-reactor = "0.1.9" 35 | futures-preview = { version = "=0.3.0-alpha.18", features = ["compat"] } 36 | futures-util = "0.2.1" 37 | log = "0.4.8" 38 | chrono = "0.4.9" 39 | rand = "0.7.0" 40 | -------------------------------------------------------------------------------- /bigbang/bigbang.h: -------------------------------------------------------------------------------- 1 | #include "stdint.h" 2 | 3 | /** 4 | * An Entity is an object (generalized to be spherical, having only a radius dimension) which has 5 | * velocity, position, radius, and mass. This gravitational tree contains many entities and it moves 6 | * them around according to the gravity they exert on each other. 7 | */ 8 | typedef struct Entity { 9 | double vx; 10 | double vy; 11 | double vz; 12 | double x; 13 | double y; 14 | double z; 15 | double radius; 16 | double mass; 17 | } Entity; 18 | 19 | /** 20 | * The exported FFI version of [[GravTree]]'s `new()` method. Returns a void pointer to the location 21 | * in memory where the [[GravTree]] is located. Use this void pointer to tell Rust where to look for 22 | * the tree in the other FFI functions. 23 | */ 24 | void *new(const Entity *array, int length, double time_step, int max_entities, double theta); 25 | 26 | /** 27 | * The exported FFI version of [[GravTree]]'s `time_step()` method. Instead of being a method, it is a 28 | * function which takes in a [[GravTree]] (rather, a void pointer to the space where the [[GravTree]] is). 29 | */ 30 | void *time_step(void *grav_tree_buf); 31 | -------------------------------------------------------------------------------- /bigbang_derive/src/lib.rs: -------------------------------------------------------------------------------- 1 | extern crate proc_macro; 2 | #[macro_use] 3 | extern crate quote; 4 | #[macro_use] 5 | extern crate syn; 6 | 7 | use crate::proc_macro::TokenStream; 8 | use syn::DeriveInput; 9 | 10 | #[proc_macro_derive(AsEntity)] 11 | pub fn derive_as_entity(input: TokenStream) -> TokenStream { 12 | let input = parse_macro_input!(input as DeriveInput); 13 | 14 | // type name 15 | let name = &input.ident; 16 | 17 | // generics 18 | let generics = input.generics; 19 | let (impl_generics, ty_generics, where_clause) = generics.split_for_impl(); 20 | 21 | let expanded = quote! { 22 | impl #impl_generics AsEntity for #name #ty_generics #where_clause { 23 | fn as_entity(&self) -> bigbang::Entity { 24 | bigbang::Entity { 25 | vx: self.vx, 26 | vy: self.vy, 27 | vz: self.vz, 28 | x: self.x, 29 | y: self.y, 30 | z: self.z, 31 | radius: self.radius, 32 | mass: self.mass 33 | } 34 | } 35 | } 36 | }; 37 | 38 | TokenStream::from(expanded) 39 | } 40 | -------------------------------------------------------------------------------- /examples/src/websocket_3d/frontend/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | BigBang Client 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 27 | 28 | 38 | 39 | 40 |
41 | 42 | 43 | -------------------------------------------------------------------------------- /bigbang/src/collisions.rs: -------------------------------------------------------------------------------- 1 | //! This module contains functions to be used for collision calculations. 2 | //! You do not need to use these, they are provided merely for convenience. 3 | //! All of the functions follow the format of: 4 | //! > Given two `T: AsEntity` `p1` and `p2` and some parameters, return the acceleration vector being 5 | //! > exerted from the collision 6 | 7 | use crate::as_entity::AsEntity; 8 | 9 | /// Uses [Hooke's law](https://en.wikipedia.org/wiki/Hooke%27s_law) exerting an outwards force 10 | /// proportional to the amount of overlap when two entities are overlapping. 11 | /// The argument `stiffness` refers to the stiffness coefficient applied to the overlapping value. 12 | pub fn soft_body(p1: &T, p2: &T, stiffness: f64) -> (f64, f64, f64) 13 | where 14 | T: AsEntity, 15 | { 16 | let p1 = p1.as_entity(); 17 | let p2 = p2.as_entity(); 18 | // calculate the overlap of the two particles 19 | let distance = p1.distance(&p2); 20 | let radii_sum = p1.radius + p2.radius; 21 | // if the distance is greater than the radii combined, then there actually was no collision and 22 | // we can return early. 23 | if distance >= radii_sum { 24 | return (p1.vx, p1.vy, p1.vz); 25 | } 26 | let overlap = radii_sum - distance; 27 | let force = stiffness * overlap; 28 | let acceleration_scalar = force / p1.mass; 29 | let (unit_x, unit_y, unit_z) = unit_vector(&p2.distance_vector(&p1)); 30 | ( 31 | unit_x * acceleration_scalar, 32 | unit_y * acceleration_scalar, 33 | unit_z * acceleration_scalar, 34 | ) 35 | } 36 | 37 | /// Utility function to turn a vector into a unit vector. 38 | fn unit_vector(vec: &(f64, f64, f64)) -> (f64, f64, f64) { 39 | let (x, y, z) = vec; 40 | let length = f64::sqrt((x * x) + (y * y) + (z * z)); 41 | (x / length, y / length, z / length) 42 | } 43 | -------------------------------------------------------------------------------- /examples/src/2d_js/visualize.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 3D Scatter Plot 7 | 8 | 9 | 10 | 11 | 73 | 80 | 81 | 82 | -------------------------------------------------------------------------------- /bigbang/cbindgen.toml: -------------------------------------------------------------------------------- 1 | 2 | 3 | language = "C" 4 | 5 | 6 | 7 | ############## Options for Wrapping the Contents of the Header ################# 8 | 9 | # header = "/* Text to put at the beginning of the generated file. Probably a license. */" 10 | # trailer = "/* Text to put at the end of the generated file */" 11 | # include_guard = "my_bindings_h" 12 | # autogen_warning = "/* Warning, this file is autogenerated by cbindgen. Don't modify this manually. */" 13 | include_version = false 14 | # namespace = "my_namespace" 15 | namespaces = [] 16 | sys_includes = [] 17 | includes = ["stdint.h"] 18 | no_includes = true 19 | 20 | 21 | 22 | 23 | ############################ Code Style Options ################################ 24 | 25 | braces = "SameLine" 26 | line_length = 100 27 | tab_width = 2 28 | documentation_style = "auto" 29 | 30 | 31 | 32 | 33 | 34 | ############################# Codegen Options ################################## 35 | 36 | style = "both" 37 | 38 | 39 | 40 | [defines] 41 | # "target_os = freebsd" = "DEFINE_FREEBSD" 42 | # "feature = serde" = "DEFINE_SERDE" 43 | 44 | 45 | 46 | [export] 47 | include = [] 48 | exclude = [] 49 | # prefix = "CAPI_" 50 | item_types = [] 51 | renaming_overrides_prefixing = false 52 | 53 | 54 | 55 | [export.rename] 56 | 57 | 58 | 59 | [export.body] 60 | 61 | 62 | 63 | 64 | [fn] 65 | rename_args = "None" 66 | # must_use = "MUST_USE_FUNC" 67 | # prefix = "START_FUNC" 68 | # postfix = "END_FUNC" 69 | args = "auto" 70 | 71 | 72 | 73 | 74 | [struct] 75 | rename_fields = "None" 76 | # must_use = "MUST_USE_STRUCT" 77 | derive_constructor = false 78 | derive_eq = false 79 | derive_neq = false 80 | derive_lt = false 81 | derive_lte = false 82 | derive_gt = false 83 | derive_gte = false 84 | 85 | 86 | 87 | 88 | [enum] 89 | rename_variants = "None" 90 | # must_use = "MUST_USE_ENUM" 91 | add_sentinel = false 92 | prefix_with_name = false 93 | derive_helper_methods = false 94 | derive_const_casts = false 95 | derive_mut_casts = false 96 | # cast_assert_name = "ASSERT" 97 | derive_tagged_enum_destructor = false 98 | derive_tagged_enum_copy_constructor = false 99 | private_default_tagged_enum_constructor = false 100 | 101 | 102 | 103 | 104 | [const] 105 | allow_static_const = true 106 | 107 | 108 | 109 | 110 | [macro_expansion] 111 | bitflags = false 112 | 113 | 114 | 115 | 116 | 117 | 118 | ############## Options for How Your Rust library Should Be Parsed ############## 119 | 120 | [parse] 121 | parse_deps = false 122 | # include = [] 123 | exclude = [] 124 | clean = false 125 | extra_bindings = [] 126 | 127 | 128 | 129 | [parse.expand] 130 | crates = [] 131 | all_features = false 132 | default_features = true 133 | features = [] 134 | -------------------------------------------------------------------------------- /examples/src/basic_simulation/main.rs: -------------------------------------------------------------------------------- 1 | extern crate bigbang; 2 | use bigbang::{AsEntity, GravTree, Responsive, SimulationResult}; 3 | 4 | #[derive(Clone, PartialEq)] 5 | struct Entity { 6 | x: f64, 7 | y: f64, 8 | z: f64, 9 | vx: f64, 10 | vy: f64, 11 | vz: f64, 12 | radius: f64, 13 | mass: f64, 14 | } 15 | 16 | impl AsEntity for Entity { 17 | fn as_entity(&self) -> bigbang::Entity { 18 | bigbang::Entity { 19 | x: self.x, 20 | y: self.y, 21 | z: self.z, 22 | vx: self.vx, 23 | vy: self.vy, 24 | vz: self.vz, 25 | radius: self.radius, 26 | mass: self.mass, 27 | } 28 | } 29 | } 30 | 31 | impl Responsive for Entity { 32 | fn respond(&self, simulation_result: SimulationResult, time_step: f64) -> Self { 33 | let (ax, ay, _az) = simulation_result.gravitational_acceleration; 34 | let (x, y, z) = (self.x, self.y, self.z); 35 | let (mut vx, mut vy, mut vz) = (self.vx, self.vy, self.vz); 36 | let self_mass = if self.radius < 1. { 0.5 } else { 105. }; 37 | // calculate the collisions 38 | for other in simulation_result.collisions.clone() { 39 | let other_mass = if other.radius < 1. { 0.5 } else { 105. }; 40 | let mass_coefficient_v1 = (self_mass - other_mass) / (self_mass + other_mass); 41 | let mass_coefficient_v2 = (2f64 * other_mass) / (self_mass + other_mass); 42 | vx = (mass_coefficient_v1 * vx) + (mass_coefficient_v2 * other.vx); 43 | vy = (mass_coefficient_v1 * vy) + (mass_coefficient_v2 * other.vy); 44 | vz = (mass_coefficient_v1 * vz) + (mass_coefficient_v2 * other.vz); 45 | } 46 | vx += ax * time_step; 47 | vy += ay * time_step; 48 | Entity { 49 | vx, 50 | vy, 51 | vz, 52 | x: x + (vx * time_step), 53 | y: y + (vy * time_step), 54 | z: z + (vz * time_step), 55 | radius: self.radius, 56 | mass: self.mass, 57 | } 58 | } 59 | } 60 | 61 | fn main() { 62 | let mut vec_that_wants_to_be_a_kdtree: Vec = Vec::new(); 63 | for i in 0..10_000 { 64 | vec_that_wants_to_be_a_kdtree.push(Entity { 65 | x: i as f64, 66 | y: i as f64, 67 | z: i as f64, 68 | vx: i as f64, 69 | vy: i as f64, 70 | vz: i as f64, 71 | mass: 5., 72 | radius: 5., 73 | }); 74 | } 75 | 76 | let mut test_tree = GravTree::new( 77 | &mut vec_that_wants_to_be_a_kdtree, 78 | 0.2, 79 | 3, 80 | 0.2, 81 | bigbang::CalculateCollisions::Yes, 82 | ); 83 | 84 | for i in 0..20 { 85 | println!("time step: {}", i); 86 | test_tree = test_tree.time_step(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /bigbang/src/utilities.rs: -------------------------------------------------------------------------------- 1 | use super::Dimension; 2 | #[allow(unused_imports)] 3 | use crate::entity::Entity; 4 | use std::cmp::Ordering; 5 | /// Returns the absolute distance in every dimension (the range in every dimension) 6 | /// of an array slice of entities. 7 | pub(crate) fn xyz_distances(entities: &[Entity]) -> (f64, f64, f64) { 8 | let (x_max, x_min, y_max, y_min, z_max, z_min) = max_min_xyz(entities); 9 | let x_distance = x_max - x_min; 10 | let y_distance = y_max - y_min; 11 | let z_distance = z_max - z_min; 12 | (x_distance.abs(), y_distance.abs(), z_distance.abs()) 13 | } 14 | 15 | /// Given an array slice of entities, returns the maximum and minimum x, y, and z values as 16 | /// a septuple. 17 | pub(crate) fn max_min_xyz(entities: &[Entity]) -> (&f64, &f64, &f64, &f64, &f64, &f64) { 18 | let (x_max, x_min) = max_min(Dimension::X, entities); 19 | let (y_max, y_min) = max_min(Dimension::Y, entities); 20 | let (z_max, z_min) = max_min(Dimension::Z, entities); 21 | (x_max, x_min, y_max, y_min, z_max, z_min) 22 | } 23 | 24 | /// Returns the maximum and minimum values in a slice of entities, given a dimension. 25 | pub(crate) fn max_min(dim: Dimension, entities: &[Entity]) -> (&f64, &f64) { 26 | ( 27 | entities 28 | .iter() 29 | .max_by(|a, b| { 30 | a.get_dim(&dim) 31 | .partial_cmp(b.get_dim(&dim)) 32 | .unwrap_or(Ordering::Equal) 33 | }) 34 | .unwrap_or_else(|| panic!("no max {} found", dim.as_string())) 35 | .get_dim(&dim), 36 | entities 37 | .iter() 38 | .min_by(|a, b| { 39 | a.get_dim(&dim) 40 | .partial_cmp(b.get_dim(&dim)) 41 | .unwrap_or(Ordering::Equal) 42 | }) 43 | .unwrap_or_else(|| panic!("no min {} found", dim.as_string())) 44 | .get_dim(&dim), 45 | ) 46 | } 47 | 48 | /// Finds the median value for a given dimension in a slice of entities. 49 | /// Making one that clones/uses immutability could be an interesting performance benchmark. 50 | pub(crate) fn find_median(dim: Dimension, pts: &mut [Entity]) -> (&f64, usize) { 51 | find_median_helper(dim, pts, 0, pts.len(), pts.len() / 2usize) 52 | } 53 | 54 | fn find_median_helper( 55 | dim: Dimension, 56 | pts: &mut [Entity], 57 | start: usize, 58 | end: usize, 59 | mid: usize, 60 | ) -> (&f64, usize) { 61 | let mut low = (start + 1); 62 | let mut high = (end - 1); //exclusive end 63 | while low <= high { 64 | if pts[low].get_dim(&dim) < pts[start].get_dim(&dim) { 65 | low += 1; 66 | } else { 67 | pts.swap(low, high); 68 | high -= 1; 69 | } 70 | } 71 | pts.swap(start, high); 72 | if start == mid { 73 | (pts[start].get_dim(&dim), start) 74 | } else if high < mid { 75 | find_median_helper(dim, pts, high + 1, end, mid) 76 | } else { 77 | find_median_helper(dim, pts, start, high, mid) 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /bigbang/tests/test.rs: -------------------------------------------------------------------------------- 1 | extern crate bigbang; 2 | use bigbang::{AsEntity, Entity, GravTree, Responsive, SimulationResult}; 3 | 4 | #[derive(Clone, PartialEq)] 5 | struct MyEntity { 6 | x: f64, 7 | y: f64, 8 | z: f64, 9 | vx: f64, 10 | vy: f64, 11 | vz: f64, 12 | radius: f64, 13 | } 14 | 15 | impl AsEntity for MyEntity { 16 | fn as_entity(&self) -> Entity { 17 | return Entity { 18 | x: self.x, 19 | y: self.y, 20 | z: self.z, 21 | vx: self.vx, 22 | vy: self.vy, 23 | vz: self.vz, 24 | radius: self.radius, 25 | mass: if self.radius < 1. { 0.5 } else { 105. }, 26 | }; 27 | } 28 | } 29 | 30 | impl Responsive for MyEntity { 31 | fn respond(&self, simulation_result: SimulationResult, time_step: f64) -> Self { 32 | let (ax, ay, _az) = simulation_result.gravitational_acceleration; 33 | let (x, y, z) = (self.x, self.y, self.z); 34 | let (mut vx, mut vy, mut vz) = (self.vx, self.vy, self.vz); 35 | let self_mass = if self.radius < 1. { 0.5 } else { 105. }; 36 | // calculate the collisions 37 | for other in simulation_result.collisions.clone() { 38 | let other_mass = if other.radius < 1. { 0.5 } else { 105. }; 39 | let mass_coefficient_v1 = (self_mass - other_mass) / (self_mass + other_mass); 40 | let mass_coefficient_v2 = (2f64 * other_mass) / (self_mass + other_mass); 41 | vx = (mass_coefficient_v1 * vx) + (mass_coefficient_v2 * other.vx); 42 | vy = (mass_coefficient_v1 * vy) + (mass_coefficient_v2 * other.vy); 43 | vz = (mass_coefficient_v1 * vz) + (mass_coefficient_v2 * other.vz); 44 | } 45 | vx += ax * time_step; 46 | vy += ay * time_step; 47 | MyEntity { 48 | vx, 49 | vy, 50 | vz, 51 | x: x + (vx * time_step), 52 | y: y + (vy * time_step), 53 | z: z + (vz * time_step), 54 | radius: self.radius, 55 | } 56 | } 57 | } 58 | 59 | impl MyEntity { 60 | pub fn random_entity() -> MyEntity { 61 | MyEntity { 62 | vx: 0f64, 63 | vy: 0f64, 64 | vz: 0f64, 65 | x: rand::random::() * 50f64, 66 | y: rand::random::() * 50f64, 67 | z: rand::random::() * 50f64, 68 | radius: rand::random::() / 10f64, 69 | } 70 | } 71 | } 72 | 73 | #[test] 74 | fn test_traversal() { 75 | let mut vec: Vec = Vec::new(); 76 | for _ in 0..100 { 77 | let entity = MyEntity::random_entity(); 78 | vec.push(entity); 79 | } 80 | let vec_clone = vec.clone(); 81 | let tree = GravTree::new(&vec, 0.2, 3, 0.2); 82 | let traversed_vec = tree.as_vec(); 83 | let mut all_found = true; 84 | for i in vec_clone { 85 | if !traversed_vec.contains(&i) { 86 | all_found = false; 87 | } 88 | } 89 | 90 | assert!(all_found); 91 | } 92 | 93 | #[test] 94 | fn test_time_step() { 95 | let mut vec_that_wants_to_be_a_kdtree: Vec = Vec::new(); 96 | for _ in 0..1000 { 97 | let entity = MyEntity::random_entity(); 98 | vec_that_wants_to_be_a_kdtree.push(entity); 99 | } 100 | 101 | let test_tree = GravTree::new(&vec_that_wants_to_be_a_kdtree, 0.2, 3, 0.2); 102 | let after_time_step = test_tree.time_step(); 103 | assert_eq!(after_time_step.as_vec().len(), 1000); 104 | } 105 | -------------------------------------------------------------------------------- /bigbang/README.md: -------------------------------------------------------------------------------- 1 | ![docs.rs](https://docs.rs/bigbang/badge.svg) 2 | ![crates.io](https://img.shields.io/crates/v/bigbang.svg) 3 | [![Build Status](https://travis-ci.org/sezna/bigbang.svg?branch=master)](https://travis-ci.org/sezna/bigbang) 4 | _Have you used this project in your work? I'd love to hear about it and work with you. Email me at [alex@alex-hansen.com](mailto:alex@alex-hansen.com)._ 5 | 6 | # About the project 7 | This is a project in re-implementing a C++ particle simulation in Rust for speed comparison purposes. I originally created this tree at Trinity University with Dr. Mark Lewis around 2015. Rust changed a lot in the following years, and so I re-wrote it in 2019. 8 | 9 | 10 | ![example in 3d](./3d_example.gif) 11 | _3d websocket-based simulation is available in the examples directory and was provided by [Casey Primozic](https://cprimozic.net/)._ 12 | 13 | # What exactly does it do? 14 | It constructs a spatial k-dimensional tree (3 dimensions) and optimally calculates gravitational acceleration forces and collisions. 15 | 16 | # Getting started with bigbang 17 | ## Implementing the `AsEntity` and `Responsive` traits 18 | In order to use your arbitrary type inside this tree, your struct must be `AsEntity + Responsive + Clone + Send + Sync`. I'd like to eventually get rid of the `Clone` requirement, but currently the tree works in an immutable way where each time step an entirely new tree is constructed with the gravitational acceleration applied to it. This makes parallelism easier to reason about and safer, and requires `Clone`. `Send` and `Sync` are required for the parallelism. 19 | 20 | `AsEntity` requires that you represent your struct as a gravitational entity, which entails providing velocity and position vectors, as well as a radius and a mass (all bodies are spheres in this simulation). 21 | 22 | The real meat and potatoes you must implement is the trait `Responsive`. This trait defines how your struct responds to the simulation's results at every time step. 23 | 24 | ```rust 25 | impl bigbang::AsEntity for MyStruct { 26 | fn as_entity(&self) -> bigbang::Entity; 27 | } 28 | 29 | impl bigbang::Responsive for MyStruct { 30 | fn respond(&self, simulation_result: bigbang::SimulationResult, time_step: f64) -> Self; 31 | } 32 | ``` 33 | 34 | `as_entity` must take your struct and return it as a gravitational entity consisting of a velocity vector, a position vector, a radius, and a mass: 35 | ```rust 36 | struct MyEntity { 37 | pub vx: f64, 38 | pub vy: f64, 39 | pub vz: f64, 40 | pub x: f64, 41 | pub y: f64, 42 | pub z: f64, 43 | pub radius: f64, 44 | pub mass: f64, 45 | } 46 | ``` 47 | 48 | If your struct has these fields and they are named this way already, you can derive the `AsEntity` trait. 49 | 50 | ```rust 51 | use bigbang::AsEntity; 52 | #[derive(AsEntity)] 53 | struct MyEntity { 54 | pub vx: f64, // because these fields are named 55 | pub vy: f64, // the standard way, the same as in 56 | pub vz: f64, // the `AsEntity` trait, we can use 57 | pub x: f64, // the automatic derive. 58 | pub y: f64, 59 | pub z: f64, 60 | pub radius: f64, 61 | pub mass: f64, 62 | } 63 | ``` 64 | 65 | `respond(&self, simulation_result: SimulationResult, time_step: f64) -> Self` allows the user to decide how to respond to the simulation results. There are examples of this throughout the `examples` directory, as well as some helper collision calculation functions in the `collisions` module. 66 | 67 | ## Starting the Simulation 68 | Now that you have a compliant type with sufficient trait implementations, you may construct a vector with the starting positions for all of these entities. Pass a mutable reference to that vector and a _time\_step_ coefficent into `GravTree::new()` and you'll be off to the races: 69 | ```rust 70 | use bigbang::{ GravTree, AsEntity }; 71 | 72 | struct MyEntity { ... } 73 | 74 | impl AsEntity for MyEntity { ... } 75 | 76 | impl Responsive for MyEntity { ... } 77 | 78 | let mut my_vec:Vec = vec![entity1, entity2, entity3]; 79 | let grav_tree = GravTree::new(&my_vec, 0.2); 80 | 81 | ``` 82 | 83 | The _time\_step_ coefficient is later passed into `respond()`. It can be used to effectively control the granularity of the simulation, i.e. how much each simulation frame actually impacts the movement of the entities. A smaller _time\_step_ will result in a more granular, more precise simulation. You'll probably have to play around with the constants a little bit to find something ideal for your use case. In order to advance the simulation, call `grav_tree.time_step()`. 84 | 85 | See the examples directory for a minimalist working example. 86 | 87 | # C/C++ Interface 88 | There used to be a robust C/C++ interface for this library, but it was difficult to maintain with rapid API changes during development. If you were using this FFI, and would like for it to be re-introduced, please [contact me](mailto:alex@alex-hansen.com) and I will help you set it up. Otherwise, FFI is on hold until this crate stabilizes. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![docs.rs](https://docs.rs/bigbang/badge.svg) 2 | ![crates.io](https://img.shields.io/crates/v/bigbang.svg) 3 | [![Build Status](https://travis-ci.org/sezna/bigbang.svg?branch=master)](https://travis-ci.org/sezna/bigbang) 4 | _Have you used this project in your work? I'd love to hear about it and work with you. Email me at [alex@alex-hansen.com](mailto:alex@alex-hansen.com)._ 5 | 6 | # About the project 7 | This is a project in re-implementing a C++ particle simulation in Rust for speed comparison purposes. I originally created this tree at Trinity University with Dr. Mark Lewis around 2015. Rust changed a lot in the following years, and so I re-wrote it in 2019. 8 | 9 | 10 | ![example in 3d](./bigbang/3d_example.gif) 11 | _3d websocket-based simulation is available in the examples directory and was provided by [Casey Primozic](https://cprimozic.net/)._ 12 | 13 | # What exactly does it do? 14 | It constructs a spatial k-dimensional tree (3 dimensions) and optimally calculates gravitational acceleration forces and collisions. 15 | 16 | # Getting started with bigbang 17 | ## Implementing the `AsEntity` and `Responsive` traits 18 | In order to use your arbitrary type inside this tree, your struct must be `AsEntity + Responsive + Clone + Send + Sync`. I'd like to eventually get rid of the `Clone` requirement, but currently the tree works in an immutable way where each time step an entirely new tree is constructed with the gravitational acceleration applied to it. This makes parallelism easier to reason about and safer, and requires `Clone`. `Send` and `Sync` are required for the parallelism. 19 | 20 | `AsEntity` requires that you represent your struct as a gravitational entity, which entails providing velocity and position vectors, as well as a radius and a mass (all bodies are spheres in this simulation). 21 | 22 | The real meat and potatoes you must implement is the trait `Responsive`. This trait defines how your struct responds to the simulation's results at every time step. 23 | 24 | ```rust 25 | impl bigbang::AsEntity for MyStruct { 26 | fn as_entity(&self) -> bigbang::Entity; 27 | } 28 | 29 | impl bigbang::Responsive for MyStruct { 30 | fn respond(&self, simulation_result: bigbang::SimulationResult, time_step: f64) -> Self; 31 | } 32 | ``` 33 | 34 | `as_entity` must take your struct and return it as a gravitational entity consisting of a velocity vector, a position vector, a radius, and a mass: 35 | ```rust 36 | struct MyEntity { 37 | pub vx: f64, 38 | pub vy: f64, 39 | pub vz: f64, 40 | pub x: f64, 41 | pub y: f64, 42 | pub z: f64, 43 | pub radius: f64, 44 | pub mass: f64, 45 | } 46 | ``` 47 | 48 | If your struct has these fields and they are named this way already, you can derive the `AsEntity` trait. 49 | 50 | ```rust 51 | use bigbang::AsEntity; 52 | #[derive(AsEntity)] 53 | struct MyEntity { 54 | pub vx: f64, // because these fields are named 55 | pub vy: f64, // the standard way, the same as in 56 | pub vz: f64, // the `AsEntity` trait, we can use 57 | pub x: f64, // the automatic derive. 58 | pub y: f64, 59 | pub z: f64, 60 | pub radius: f64, 61 | pub mass: f64, 62 | } 63 | ``` 64 | 65 | `respond(&self, simulation_result: SimulationResult, time_step: f64) -> Self` allows the user to decide how to respond to the simulation results. There are examples of this throughout the `examples` directory, as well as some helper collision calculation functions in the `collisions` module. 66 | 67 | ## Starting the Simulation 68 | Now that you have a compliant type with sufficient trait implementations, you may construct a vector with the starting positions for all of these entities. Pass a mutable reference to that vector and a _time\_step_ coefficent into `GravTree::new()` and you'll be off to the races: 69 | ```rust 70 | use bigbang::{ GravTree, AsEntity }; 71 | 72 | struct MyEntity { ... } 73 | 74 | impl AsEntity for MyEntity { ... } 75 | 76 | impl Responsive for MyEntity { ... } 77 | 78 | let mut my_vec:Vec = vec![entity1, entity2, entity3]; 79 | let grav_tree = GravTree::new(&my_vec, 0.2); 80 | 81 | ``` 82 | 83 | The _time\_step_ coefficient is later passed into `respond()`. It can be used to effectively control the granularity of the simulation, i.e. how much each simulation frame actually impacts the movement of the entities. A smaller _time\_step_ will result in a more granular, more precise simulation. You'll probably have to play around with the constants a little bit to find something ideal for your use case. In order to advance the simulation, call `grav_tree.time_step()`. 84 | 85 | See the examples directory for a minimalist working example. 86 | 87 | # C/C++ Interface 88 | There used to be a robust C/C++ interface for this library, but it was difficult to maintain with rapid API changes during development. If you were using this FFI, and would like for it to be re-introduced, please [contact me](mailto:alex@alex-hansen.com) and I will help you set it up. Otherwise, FFI is on hold until this crate stabilizes. 89 | -------------------------------------------------------------------------------- /examples/src/websocket_3d/frontend/index.js: -------------------------------------------------------------------------------- 1 | const PARTICLE_SIZE = 20; 2 | // How much to scale the particle size by when zooming. 3 | const ZOOM_TO_SIZE_SCALE = 2; 4 | // How many coordinates are moved when moving camera in response to user input 5 | const TRANSLATION_STEP_SIZE = 80; 6 | 7 | var iters = 0; 8 | var isInitialized = false; 9 | 10 | var renderer, scene, camera; 11 | var particles; 12 | 13 | var zoomFactor = 0.2; 14 | var rotationX = 0; 15 | var rotationY = 0; 16 | var rotationZ = 0; 17 | 18 | var particlesOffsets = { x: 0, y: 0, z: 0 }; 19 | 20 | const initControlPanel = () => { 21 | const inputs = [ 22 | { type: 'range', label: 'zoom', min: 0.01, max: 5, step: 0.001, initial: zoomFactor }, 23 | { type: 'range', label: 'rotation_x', min: 0, max: Math.PI * 2, step: 0.1, initial: 0 }, 24 | { type: 'range', label: 'rotation_y', min: 0, max: Math.PI * 2, step: 0.1, initial: 0 }, 25 | { type: 'range', label: 'rotation_z', min: 0, max: Math.PI * 2, step: 0.1, initial: 0 }, 26 | ]; 27 | 28 | var panelNode = document.body.appendChild(document.createElement('div')); 29 | panelNode.setAttribute('id', 'viz-controls'); 30 | const panel = control(inputs, { 31 | theme: 'dark', 32 | title: 'visualization controls', 33 | root: panelNode, 34 | }); 35 | 36 | panel.on('input', ({ zoom, rotation_x, rotation_y, rotation_z }) => { 37 | zoomFactor = zoom; 38 | rotationX = rotation_x; 39 | rotationY = rotation_y; 40 | rotationZ = rotation_z; 41 | }); 42 | }; 43 | 44 | function buildGeometry(bigbangPositions) { 45 | var positions = new Float32Array((bigbangPositions.length / 4) * 3); 46 | var colors = new Float32Array((bigbangPositions.length / 4) * 3); 47 | var sizes = new Float32Array(bigbangPositions.length / 4); 48 | 49 | var color = new THREE.Color(); 50 | for (let i = 0, l = bigbangPositions.length / 4; i < l; i += 4) { 51 | positions[i * 3 + 0] = bigbangPositions[i * 4 + 0]; 52 | positions[i * 3 + 1] = bigbangPositions[i * 4 + 1]; 53 | positions[i * 3 + 2] = bigbangPositions[i * 4 + 2]; 54 | 55 | color.setHSL(0.01 + 0.1 * (i / l), 1.0, 0.5); 56 | color.toArray(colors, i * 3); 57 | sizes[i] = bigbangPositions[i * 4 + 3] * PARTICLE_SIZE * (zoomFactor * ZOOM_TO_SIZE_SCALE); 58 | } 59 | 60 | var geometry = new THREE.BufferGeometry(); 61 | geometry.addAttribute('position', new THREE.BufferAttribute(positions, 3)); 62 | geometry.addAttribute('customColor', new THREE.BufferAttribute(colors, 3)); 63 | geometry.addAttribute('size', new THREE.BufferAttribute(sizes, 1)); 64 | 65 | return geometry; 66 | } 67 | 68 | function init(bigbangPositions) { 69 | var container = document.getElementById('container'); 70 | scene = new THREE.Scene(); 71 | camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 1, 10000); 72 | camera.position.x = 0; 73 | camera.position.y = 0; 74 | camera.position.z = -1000; 75 | camera.lookAt(new THREE.Vector3(0, 0, 0)); 76 | 77 | const geometry = buildGeometry(bigbangPositions); 78 | console.log(geometry); 79 | 80 | var material = new THREE.ShaderMaterial({ 81 | uniforms: { 82 | color: { value: new THREE.Color(0xffffff) }, 83 | pointTexture: { value: new THREE.TextureLoader().load('./disc.png') }, 84 | }, 85 | vertexShader: document.getElementById('vertexshader').textContent, 86 | fragmentShader: document.getElementById('fragmentshader').textContent, 87 | alphaTest: 0.9, 88 | }); 89 | 90 | particles = new THREE.Points(geometry, material); 91 | scene.add(particles); 92 | console.log(particles); 93 | 94 | renderer = new THREE.WebGLRenderer(); 95 | renderer.setPixelRatio(window.devicePixelRatio); 96 | renderer.setSize(window.innerWidth, window.innerHeight); 97 | container.appendChild(renderer.domElement); 98 | 99 | raycaster = new THREE.Raycaster(); 100 | 101 | window.addEventListener('resize', onWindowResize, false); 102 | 103 | initControlPanel(); 104 | 105 | document.addEventListener('keypress', evt => { 106 | switch (evt.key) { 107 | case 'd': 108 | case 'ArrowRight': 109 | particlesOffsets.x += TRANSLATION_STEP_SIZE; 110 | break; 111 | case 'a': 112 | case 'ArrowLeft': 113 | particlesOffsets.x -= TRANSLATION_STEP_SIZE; 114 | break; 115 | case 'w': 116 | case 'ArrowUp': 117 | particlesOffsets.y += TRANSLATION_STEP_SIZE; 118 | break; 119 | case 's': 120 | case 'ArrowDown': 121 | particlesOffsets.y -= TRANSLATION_STEP_SIZE; 122 | break; 123 | case '=': 124 | particlesOffsets.z -= TRANSLATION_STEP_SIZE; 125 | break; 126 | case '-': 127 | particlesOffsets.z += TRANSLATION_STEP_SIZE; 128 | break; 129 | 130 | default: 131 | } 132 | console.log(particlesOffsets, evt.key); 133 | }); 134 | } 135 | 136 | function onWindowResize() { 137 | camera.aspect = window.innerWidth / window.innerHeight; 138 | console.log(camera); 139 | camera.updateProjectionMatrix(); 140 | renderer.setSize(window.innerWidth, window.innerHeight); 141 | } 142 | 143 | function render(bigbangPositions) { 144 | camera.rotation.x = rotationX; 145 | camera.rotation.y = rotationY; 146 | camera.rotation.z = rotationZ; 147 | camera.position.x = particlesOffsets.x; 148 | camera.position.y = particlesOffsets.y; 149 | camera.position.z = particlesOffsets.z; 150 | camera.zoom = zoomFactor; 151 | camera.updateProjectionMatrix(); 152 | 153 | var geometry = particles.geometry; 154 | var attributes = geometry.attributes; 155 | 156 | const newGeometry = buildGeometry(bigbangPositions); 157 | attributes.position.array = newGeometry.attributes.position.array; 158 | attributes.position.needsUpdate = true; 159 | attributes.size.array = newGeometry.attributes.size.array; 160 | attributes.size.needsUpdate = true; 161 | 162 | renderer.render(scene, camera); 163 | } 164 | 165 | const handleMessage = async msg => { 166 | if (iters === 0) { 167 | iters += 1; 168 | // ignore welcome message 169 | console.log(msg.data); 170 | return; 171 | } 172 | 173 | const data = new Float64Array(await msg.data.arrayBuffer()); 174 | 175 | iters += 1; 176 | 177 | if (!isInitialized) { 178 | isInitialized = true; 179 | init(data); 180 | } else { 181 | render(data); 182 | } 183 | }; 184 | 185 | window.onload = () => { 186 | const container = document.getElementById('container'); 187 | if (!container) { 188 | throw new Error('Failed to find #container element'); 189 | } 190 | 191 | const ws = new WebSocket('ws://localhost:3355', ['rust-websocket']); 192 | 193 | ws.onmessage = handleMessage; 194 | }; 195 | -------------------------------------------------------------------------------- /bigbang/src/grav_tree.rs: -------------------------------------------------------------------------------- 1 | use crate::responsive::Responsive; 2 | use crate::Node; 3 | use crate::{as_entity::AsEntity, entity::CalculateCollisions}; 4 | use rayon::prelude::*; 5 | use serde::{Deserialize, Serialize}; 6 | 7 | /// The main struct you will interact with. This is a k-d tree containing all of your gravitational 8 | /// entities. 9 | #[derive(Serialize, Deserialize)] 10 | pub struct GravTree { 11 | /// A GravTree consists of a root [[Node]]. A [[Node]] is a recursive binary tree data structure. 12 | /// Tragically must be public for now for testing reasons. Perhaps could be replaced by various 13 | /// getter methods later. 14 | pub(crate) root: Node, 15 | /// This is just the number of entities in the tree. This is used in testing to verify that no 16 | /// entities are being dropped. 17 | number_of_entities: usize, 18 | /// This coefficient determines the granularity of the simulation, i.e. how much each frame of 19 | /// the simulation actually moves the individual entities. 20 | time_step: f64, // the time coefficient; how large each simulation frame is time-wise. 21 | /// The maximum number of entities to be contained within any leaf node. Defaults to 3 but is 22 | /// configurable. This is _not_ the maximum number of entities in the simulation. A higher 23 | /// number here will result in lower simulation granularity. 24 | max_entities: i32, 25 | /// `theta` is how far away a node has to be before the simulation starts approximating its 26 | /// contained entities by treating them as one large node instead of individually addressing 27 | /// them. 28 | /// More specifically, this is the tolerance for the distance from an entity to the center of mass of an entity 29 | /// If the distance is beyond this threshold, we treat the entire node as one giant 30 | /// entity instead of recursing into it. 31 | theta: f64, 32 | /// Whether or not to calculate collisions when time stepping 33 | calculate_collisions: CalculateCollisions, 34 | } 35 | 36 | impl GravTree { 37 | pub fn new( 38 | pts: &[T], 39 | time_step: f64, 40 | max_entities: i32, 41 | theta: f64, 42 | calculate_collisions: CalculateCollisions, 43 | ) -> GravTree 44 | where 45 | T: AsEntity, 46 | { 47 | let size_of_vec = pts.len(); 48 | // Handle the case where a grav tree is initialized without any points... 49 | if size_of_vec == 0 { 50 | return GravTree { 51 | root: Node::new(), 52 | number_of_entities: size_of_vec, 53 | time_step, 54 | max_entities, 55 | theta, 56 | calculate_collisions, 57 | }; 58 | } 59 | 60 | // Because of the tree's recursive gravity calculation, there needs to be a parent node 61 | // that "contains" the _real_ root node. This "phantom_parent" serves no purpose other than 62 | // to hold a pointer to the real root node. Perhaps not the most ideal situation for now, 63 | // and can be made more elegant in the future, if need be. 64 | // The real root of the tree is therefore tree.root.left 65 | let mut phantom_parent = Node::new(); 66 | phantom_parent.left = Some(Box::new(Node::::new_root_node(pts, max_entities))); 67 | phantom_parent.points = Some(Vec::new()); 68 | 69 | GravTree { 70 | root: phantom_parent, 71 | number_of_entities: size_of_vec, 72 | time_step, 73 | max_entities, 74 | theta, 75 | calculate_collisions, 76 | } 77 | } 78 | /// Sets the `theta` value of the simulation. 79 | pub fn set_theta(&mut self, theta: f64) { 80 | self.theta = theta; 81 | } 82 | 83 | /// Traverses the tree and returns a vector of all entities in the tree. 84 | pub fn as_vec(&self) -> Vec { 85 | let node = self.root.clone(); 86 | let mut to_return: Vec = Vec::new(); 87 | if let Some(node) = &node.left { 88 | to_return.append(&mut node.traverse_tree_helper()); 89 | } 90 | if let Some(node) = &node.right { 91 | to_return.append(&mut node.traverse_tree_helper()); 92 | } else { 93 | to_return.append( 94 | &mut (node 95 | .points 96 | .as_ref() 97 | .expect("unexpected null node #9") 98 | .clone()), 99 | ); 100 | } 101 | to_return 102 | } 103 | /// Gets the total number of entities contained by this tree. 104 | pub fn get_number_of_entities(&self) -> usize { 105 | self.number_of_entities 106 | } 107 | 108 | /// This function creates a vector of all entities from the tree and applies gravity to them. 109 | /// Returns a new GravTree. 110 | // of note: The c++ implementation of this just stores a vector of 111 | // accelerations and matches up the 112 | // indexes with the indexes of the entities, and then applies them. That way 113 | // some memory is saved. 114 | // I am not sure if this will be necessary or very practical in the rust 115 | // implementation (I would have to implement indexing in my GravTree struct). 116 | pub fn time_step(&self) -> GravTree { 117 | // TODO currently there is a time when the entities are stored twice. 118 | // Store only accelerations perhaps? 119 | // First, we extract the entities out into a vector 120 | let post_gravity_entity_vec: Vec = self.root.traverse_tree_helper(); 121 | // Then, we construct a new grav tree after the gravitational acceleration for each 122 | // entity has been calculated. 123 | GravTree::::new( 124 | &post_gravity_entity_vec 125 | .par_iter() 126 | .map(|x| { 127 | let x_entity = x.as_entity(); 128 | let accel = match self.calculate_collisions { 129 | CalculateCollisions::Yes => { 130 | x_entity.get_acceleration_and_collisions(&self.root, self.theta) 131 | } 132 | CalculateCollisions::No => { 133 | x_entity.get_acceleration_without_collisions(&self.root, self.theta) 134 | } 135 | }; 136 | x.respond(accel, self.time_step) 137 | }) 138 | .collect::>(), 139 | self.time_step, 140 | self.max_entities, 141 | self.theta, 142 | self.calculate_collisions, 143 | ) 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /bigbang/benches/theta.rs: -------------------------------------------------------------------------------- 1 | use bigbang::{collisions::soft_body, AsEntity, Entity, GravTree, Responsive, SimulationResult}; 2 | use criterion::{criterion_group, criterion_main, BatchSize, Criterion}; 3 | use std::time; 4 | #[derive(Clone)] 5 | struct MyEntity { 6 | x: f64, 7 | y: f64, 8 | z: f64, 9 | vx: f64, 10 | vy: f64, 11 | vz: f64, 12 | radius: f64, 13 | } 14 | impl AsEntity for MyEntity { 15 | fn as_entity(&self) -> Entity { 16 | return Entity { 17 | x: self.x, 18 | y: self.y, 19 | z: self.z, 20 | vx: self.vx, 21 | vy: self.vy, 22 | vz: self.vz, 23 | radius: self.radius, 24 | mass: if self.radius < 1. { 0.5 } else { 105. }, 25 | }; 26 | } 27 | } 28 | 29 | impl Responsive for MyEntity { 30 | fn respond(&self, simulation_result: SimulationResult, time_step: f64) -> Self { 31 | let (mut ax, mut ay, mut az) = simulation_result.gravitational_acceleration; 32 | let (x, y, z) = (self.x, self.y, self.z); 33 | let (mut vx, mut vy, mut vz) = (self.vx, self.vy, self.vz); 34 | // calculate the collisions 35 | for other in &simulation_result.collisions { 36 | let (collision_ax, collision_ay, collision_az) = soft_body(self, other, 20f64); 37 | ax += collision_ax; 38 | ay += collision_ay; 39 | az += collision_az; 40 | } 41 | vx += ax * time_step; 42 | vy += ay * time_step; 43 | vz += az * time_step; 44 | MyEntity { 45 | vx, 46 | vy, 47 | vz, 48 | x: x + vx, 49 | y: y + vy, 50 | z: z + vz, 51 | radius: self.radius, 52 | } 53 | } 54 | } 55 | 56 | impl MyEntity { 57 | pub fn new_entity(x: f64, y: f64, z: f64, radius: f64) -> MyEntity { 58 | MyEntity { 59 | vx: 0f64, 60 | vy: 0f64, 61 | vz: 0f64, 62 | x, 63 | y, 64 | z, 65 | radius, 66 | } 67 | } 68 | } 69 | 70 | fn initialize_data(number_of_particles: usize) -> Vec { 71 | let mut vec: Vec = Vec::new(); 72 | for x in 0..number_of_particles { 73 | let entity = MyEntity::new_entity(x as f64, x as f64, x as f64, 10.); 74 | vec.push(entity); 75 | } 76 | vec 77 | } 78 | 79 | fn initialize_tree(number_of_particles: usize, theta: f64) -> GravTree { 80 | let max_entities = 3; 81 | let time_step = 0.2; 82 | let mut data = initialize_data(number_of_particles); 83 | GravTree::new(&mut data, time_step, max_entities, theta) 84 | } 85 | 86 | // Theta isn't used in tree construction so it isn't varied in the benches 87 | fn tree_construction(c: &mut Criterion) { 88 | let mut group = c.benchmark_group("tree construction"); 89 | group.bench_function("n=125", |b| { 90 | b.iter_batched( 91 | || initialize_data(125), 92 | |mut data| GravTree::new(&mut data, 0.2, 3, 0.2), 93 | BatchSize::SmallInput, 94 | ) 95 | }); 96 | group.bench_function("n=2000", |b| { 97 | b.iter_batched( 98 | || initialize_data(2000), 99 | |mut data| GravTree::new(&mut data, 0.2, 3, 0.2), 100 | BatchSize::SmallInput, 101 | ) 102 | }); 103 | group.measurement_time(time::Duration::new(217, 0)); 104 | group.bench_function("n=20_000", |b| { 105 | b.iter_batched( 106 | || initialize_data(20_000), 107 | |mut data| GravTree::new(&mut data, 0.2, 3, 0.2), 108 | BatchSize::SmallInput, 109 | ) 110 | }); 111 | } 112 | 113 | // Benching time stepping with a low number of entities - 125 114 | 115 | fn time_step_0125(c: &mut Criterion) { 116 | let mut group = c.benchmark_group("time step: n=125"); 117 | group.bench_function("theta=0.2", |b| { 118 | b.iter_batched( 119 | || initialize_tree(125, 0.2), 120 | |data| data.time_step(), 121 | BatchSize::SmallInput, 122 | ) 123 | }); 124 | group.bench_function("theta=0.3", |b| { 125 | b.iter_batched( 126 | || initialize_tree(125, 0.3), 127 | |data| data.time_step(), 128 | BatchSize::SmallInput, 129 | ) 130 | }); 131 | group.bench_function("theta=0.4", |b| { 132 | b.iter_batched( 133 | || initialize_tree(125, 0.4), 134 | |data| data.time_step(), 135 | BatchSize::SmallInput, 136 | ) 137 | }); 138 | group.bench_function("theta=0.5", |b| { 139 | b.iter_batched( 140 | || initialize_tree(125, 0.5), 141 | |data| data.time_step(), 142 | BatchSize::SmallInput, 143 | ) 144 | }); 145 | } 146 | 147 | // Benching time stepping with a medium number of entities - 2000 148 | 149 | fn time_step_2000(c: &mut Criterion) { 150 | let mut group = c.benchmark_group("time step: n=2000"); 151 | group.measurement_time(time::Duration::new(35, 0)); 152 | group.bench_function("theta=0.2", |b| { 153 | b.iter_batched( 154 | || initialize_tree(2000, 0.2), 155 | |data| data.time_step(), 156 | BatchSize::SmallInput, 157 | ) 158 | }); 159 | group.bench_function("theta=0.3", |b| { 160 | b.iter_batched( 161 | || initialize_tree(2000, 0.3), 162 | |data| data.time_step(), 163 | BatchSize::SmallInput, 164 | ) 165 | }); 166 | group.bench_function("theta=0.4", |b| { 167 | b.iter_batched( 168 | || initialize_tree(2000, 0.4), 169 | |data| data.time_step(), 170 | BatchSize::SmallInput, 171 | ) 172 | }); 173 | group.bench_function("theta=0.5", |b| { 174 | b.iter_batched( 175 | || initialize_tree(2000, 0.5), 176 | |data| data.time_step(), 177 | BatchSize::SmallInput, 178 | ) 179 | }); 180 | } 181 | 182 | // Benching time stepping with a medium high number of entities - 20_000 183 | fn time_step_20000(c: &mut Criterion) { 184 | let mut group = c.benchmark_group("time step: n=20_000"); 185 | group.measurement_time(time::Duration::new(35, 0)); 186 | group.sample_size(20); 187 | group.bench_function("theta=0.2", |b| { 188 | b.iter_batched( 189 | || initialize_tree(20_000, 0.2), 190 | |data| data.time_step(), 191 | BatchSize::SmallInput, 192 | ) 193 | }); 194 | group.bench_function("theta=0.3", |b| { 195 | b.iter_batched( 196 | || initialize_tree(20_000, 0.3), 197 | |data| data.time_step(), 198 | BatchSize::SmallInput, 199 | ) 200 | }); 201 | group.bench_function("theta=0.4", |b| { 202 | b.iter_batched( 203 | || initialize_tree(20_000, 0.4), 204 | |data| data.time_step(), 205 | BatchSize::SmallInput, 206 | ) 207 | }); 208 | group.bench_function("theta=0.5", |b| { 209 | b.iter_batched( 210 | || initialize_tree(20_000, 0.5), 211 | |data| data.time_step(), 212 | BatchSize::SmallInput, 213 | ) 214 | }); 215 | } 216 | 217 | criterion_group!( 218 | benches, 219 | tree_construction, 220 | time_step_0125, 221 | time_step_2000, 222 | time_step_20000, 223 | ); 224 | criterion_main!(benches); 225 | -------------------------------------------------------------------------------- /bigbang/tests/correctness.rs: -------------------------------------------------------------------------------- 1 | // the situation seems to be as such: 2 | // the simulation is totally broken on 2 entities 3 | // collisions are not detected accurately -- perhaps having something to do with the tree 4 | // structure? 5 | // acceleration is zeroed out 6 | // The issue probably arises when the total number of entities is less than max_pts? 7 | 8 | extern crate bigbang; 9 | use bigbang::{collisions::soft_body, AsEntity, Entity, GravTree, Responsive, SimulationResult}; 10 | 11 | #[derive(Clone, PartialEq, AsEntity)] 12 | struct MyEntity { 13 | x: f64, 14 | y: f64, 15 | z: f64, 16 | vx: f64, 17 | vy: f64, 18 | vz: f64, 19 | radius: f64, 20 | mass: f64, 21 | collided_with: Vec, 22 | } 23 | 24 | impl MyEntity { 25 | fn new(x: f64, y: f64, z: f64, radius: f64, mass: f64) -> MyEntity { 26 | MyEntity { 27 | x, 28 | y, 29 | z, 30 | vx: 0., 31 | vy: 0., 32 | vz: 0., 33 | radius, 34 | mass, 35 | collided_with: Vec::new(), 36 | } 37 | } 38 | } 39 | 40 | impl Responsive for MyEntity { 41 | fn respond(&self, simulation_result: SimulationResult, time_step: f64) -> Self { 42 | let mut vx = self.vx; 43 | let mut vy = self.vy; 44 | let mut vz = self.vz; 45 | let mut collided_with = Vec::new(); 46 | let (mut ax, mut ay, mut az) = simulation_result.gravitational_acceleration; 47 | for other in simulation_result.collisions { 48 | collided_with.push(other.clone()); 49 | let (collision_ax, collision_ay, collision_az) = soft_body(self, other, 50f64); 50 | ax += collision_ax; 51 | ay += collision_ay; 52 | az += collision_az; 53 | } 54 | vx += ax * time_step; 55 | vy += ay * time_step; 56 | vz += az * time_step; 57 | 58 | MyEntity { 59 | vx, 60 | vy, 61 | vz, 62 | x: self.x + (vx * time_step), 63 | y: self.y + (vy * time_step), 64 | z: self.z + (vz * time_step), 65 | radius: self.radius, 66 | mass: self.mass, 67 | collided_with, 68 | } 69 | } 70 | } 71 | 72 | /// Test that, given two entities that are overlapping, the tree detects their collision. 73 | #[test] 74 | fn two_entities_collision() { 75 | let vec_that_wants_to_be_a_kdtree: Vec = vec![ 76 | MyEntity::new(0., 0., 0., 10., 5.), 77 | MyEntity::new(0., 0., 1., 10., 5.), 78 | ]; 79 | 80 | let test_tree = GravTree::new(&vec_that_wants_to_be_a_kdtree, 0.2, 3, 0.2); 81 | let after_time_step = test_tree.time_step().as_vec(); 82 | 83 | // Each entity should have collided with exactly one other entity 84 | assert_eq!(after_time_step[0].collided_with.len(), 1); 85 | assert_eq!(after_time_step[1].collided_with.len(), 1); 86 | } 87 | 88 | /// Test that, given two entities that are not overlapping, the tree correctly does not report their collision. 89 | #[test] 90 | fn two_entities_no_collision() { 91 | let vec_that_wants_to_be_a_kdtree: Vec = vec![ 92 | MyEntity::new(0., 1000., 0., 10., 5.), 93 | MyEntity::new(0., 0., 1., 10., 5.), 94 | ]; 95 | 96 | let test_tree = GravTree::new(&vec_that_wants_to_be_a_kdtree, 0.2, 3, 0.2); 97 | let after_time_step = test_tree.time_step().as_vec(); 98 | 99 | assert_eq!(after_time_step[0].collided_with.len(), 0); 100 | assert_eq!(after_time_step[1].collided_with.len(), 0); 101 | } 102 | 103 | /// Test that the gravitational acceleration of two distant particles is calculated correctly 104 | #[test] 105 | fn two_entities_accel() { 106 | let vec_that_wants_to_be_a_kdtree: Vec = vec![ 107 | MyEntity::new(0., 100., 0., 10., 50.), 108 | MyEntity::new(50., 0., 1., 10., 500.), 109 | ]; 110 | 111 | let test_tree = GravTree::new(&vec_that_wants_to_be_a_kdtree, 0.3, 3, 0.2); 112 | let _after_time_step = test_tree.time_step().time_step().as_vec(); 113 | 114 | // 1.0 isn't right but it should at least not be 0, what the current test is suggesting 115 | // Uncomment the following line when you're ready to fix this 116 | // assert_eq!(after_time_step[0].vx, 1.); 117 | } 118 | 119 | /// Test that, given entities that are at the _exact same position_, the tree detects their collision. 120 | /// * NOTE: 121 | /// This is how things _should_ be, but isn't working quite yet. This is related to the fundamental 122 | /// structure of the tree and how it compares every particle to itself as part of the iteration. 123 | /// This is not ideal. 124 | /* 125 | #[test] 126 | fn exact_overlap_collision() { 127 | let vec_that_wants_to_be_a_kdtree: Vec = vec![ 128 | MyEntity::new(0., 0., 0., 10., 5.), 129 | MyEntity::new(0., 0., 1., 10., 5.), 130 | MyEntity::new(0., 0., 1., 10., 5.), 131 | MyEntity::new(0., 0., 1., 10., 5.), 132 | MyEntity::new(0., 0., 1., 10., 5.), 133 | ]; 134 | 135 | let test_tree = GravTree::new(&vec_that_wants_to_be_a_kdtree, 0.2); 136 | let after_time_step = test_tree.time_step().as_vec(); 137 | 138 | // Each entity should have collided with exactly all four other entities 139 | assert_eq!(after_time_step[0].collided_with.len(), 4); 140 | assert_eq!(after_time_step[1].collided_with.len(), 4); 141 | assert_eq!(after_time_step[2].collided_with.len(), 4); 142 | assert_eq!(after_time_step[3].collided_with.len(), 4); 143 | assert_eq!(after_time_step[4].collided_with.len(), 4); 144 | } 145 | */ 146 | 147 | /// Test that, given five entities that are overlapping, the tree detects their collision. 148 | #[test] 149 | fn five_entities_collision() { 150 | let vec_that_wants_to_be_a_kdtree: Vec = vec![ 151 | MyEntity::new(0., 0., 0., 10., 5.), 152 | MyEntity::new(0., 1., 0., 10., 5.), 153 | MyEntity::new(1., 0., 0., 10., 5.), 154 | MyEntity::new(1., 1., 1., 10., 5.), 155 | MyEntity::new(0., 1., 1., 10., 5.), 156 | ]; 157 | 158 | let test_tree = GravTree::new(&vec_that_wants_to_be_a_kdtree, 0.2, 3, 0.2); 159 | let after_time_step = test_tree.time_step().as_vec(); 160 | 161 | // Each entity should have collided with exactly all four other entities 162 | assert_eq!(after_time_step[0].collided_with.len(), 4); 163 | assert_eq!(after_time_step[1].collided_with.len(), 4); 164 | assert_eq!(after_time_step[2].collided_with.len(), 4); 165 | assert_eq!(after_time_step[3].collided_with.len(), 4); 166 | assert_eq!(after_time_step[4].collided_with.len(), 4); 167 | } 168 | /// Test that the gravitational acceleration of five particles is calculated correctly 169 | /// by verifying their velocity afterwards 170 | #[test] 171 | fn five_entities_accel() { 172 | let vec_that_wants_to_be_a_kdtree: Vec = vec![ 173 | MyEntity::new(0., 100., 0., 10., 50.), 174 | MyEntity::new(50., 0., 1., 10., 500.), 175 | MyEntity::new(50., 20., 1., 10., 500.), 176 | MyEntity::new(10., 20., 1., 10., 500.), 177 | MyEntity::new(50., 100., 1., 10., 500.), 178 | ]; 179 | 180 | let test_tree = GravTree::new(&vec_that_wants_to_be_a_kdtree, 0.3, 3, 0.2); 181 | let after_time_step = test_tree.time_step().time_step().as_vec(); 182 | 183 | assert_eq!(after_time_step[0].vx, 234.62426718543517); 184 | assert_eq!(after_time_step[0].vy, -308.1666357163429); 185 | assert_eq!(after_time_step[0].vz, 6.374453794316003); 186 | 187 | assert_eq!(after_time_step[1].vx, -728.0140671441542); 188 | assert_eq!(after_time_step[1].vy, 961.0687440357227); 189 | assert_eq!(after_time_step[1].vz, -22.318277419464977); 190 | 191 | assert_eq!(after_time_step[2].vx, 68.99261434517841); 192 | assert_eq!(after_time_step[2].vy, 202.1872542350379); 193 | assert_eq!(after_time_step[2].vz, 0.28488247914098197); 194 | 195 | assert_eq!(after_time_step[3].vx, -232.853993009126); 196 | assert_eq!(after_time_step[3].vy, 189.20383841899522); 197 | assert_eq!(after_time_step[3].vz, -2.014092604958015); 198 | } 199 | -------------------------------------------------------------------------------- /examples/src/2d_js/main.rs: -------------------------------------------------------------------------------- 1 | /// To get some things out of the way, I know this is not ideal rust. This is under-baked, 2 | /// and an improvisational sketch to demonstrate bigbang's core gravitational tree. 3 | /// I had three goals: 4 | /// * the simulation doesn't progress when there are no visitors (wasted effort) 5 | /// * the simulation, when it is progressing, progresses at a constant rate 6 | /// * some basic caching 7 | /// 8 | /// A global lazy static which contains a tuple of when the last simulation ran and 9 | /// what I returned when that ran achieves caching and the auto-shutdown ability. 10 | /// When a new request comes in, if the current time is less than x seconds 11 | /// from when I last advanced the simulation, just return what I did last time. 12 | /// Otherwise, progress the simulation. 13 | /// 14 | /// An additional lazy static contains the contents of the entire simulation as global 15 | /// mutable state. Sigh. To be fair, this was written in about 30 minutes. 16 | extern crate chrono; 17 | extern crate iron; 18 | extern crate mount; 19 | extern crate rand; 20 | extern crate router; 21 | extern crate serde; 22 | #[macro_use] 23 | extern crate serde_derive; 24 | #[macro_use] 25 | extern crate lazy_static; 26 | extern crate bigbang; 27 | extern crate iron_cors; 28 | extern crate serde_json; 29 | extern crate staticfile; 30 | 31 | use bigbang::{ 32 | collisions::soft_body, AsEntity, CalculateCollisions, Entity, GravTree, Responsive, 33 | SimulationResult, 34 | }; 35 | use iron::prelude::*; 36 | use iron_cors::CorsMiddleware; 37 | use router::Router; 38 | use staticfile::Static; 39 | 40 | use chrono::{DateTime, Utc}; 41 | 42 | use iron::typemap::Key; 43 | use iron::{status, Request, Response}; 44 | use mount::Mount; 45 | use std::sync::RwLock; 46 | 47 | const TIME_STEP: f64 = 0.0000002; 48 | const THETA: f64 = 0.2; 49 | const MAX_ENTITIES: i32 = 3; 50 | 51 | struct State { 52 | state: SimulationState, 53 | } 54 | 55 | struct SimulationState { 56 | grav_tree: GravTree, 57 | last_time_ran: DateTime, 58 | last_response: String, 59 | } 60 | 61 | lazy_static! { 62 | static ref STATE: RwLock = RwLock::new(State { 63 | state: SimulationState { 64 | grav_tree: GravTree::new( 65 | &Vec::new(), 66 | TIME_STEP, 67 | MAX_ENTITIES, 68 | THETA, 69 | CalculateCollisions::Yes 70 | ), 71 | last_time_ran: Utc::now(), 72 | last_response: String::new(), 73 | } 74 | }); 75 | } 76 | 77 | #[derive(Clone, Serialize, Deserialize)] 78 | struct MyEntity { 79 | x: f64, 80 | y: f64, 81 | vx: f64, 82 | vy: f64, 83 | radius: f64, 84 | color: String, 85 | } 86 | impl AsEntity for MyEntity { 87 | fn as_entity(&self) -> Entity { 88 | Entity { 89 | x: self.x, 90 | y: self.y, 91 | z: 0., 92 | vx: self.vx, 93 | vy: self.vy, 94 | vz: 0., 95 | radius: self.radius, 96 | mass: self.radius, 97 | } 98 | } 99 | } 100 | 101 | impl Responsive for MyEntity { 102 | fn respond(&self, simulation_result: SimulationResult, time_step: f64) -> Self { 103 | let (ax, ay) = if !simulation_result.collisions.is_empty() { 104 | // If there were some collisions, perform collision calculations instead of gravitational onees. 105 | let mut ax = 0.; 106 | let mut ay = 0.; 107 | for other in &simulation_result.collisions { 108 | let (collision_ax, collision_ay, _az) = soft_body(self, other, 200000f64); 109 | ax += collision_ax; 110 | ay += collision_ay; 111 | } 112 | (ax, ay) 113 | } else { 114 | // Otherwise, use gravtiational acceleration. 115 | let (ax, ay, _) = simulation_result.gravitational_acceleration; 116 | (ax, ay) 117 | }; 118 | 119 | let (mut vx, mut vy) = (self.vx, self.vy); 120 | 121 | // Add the acceleration to the velocity, scaled to the time step 122 | vx += ax * time_step; 123 | vy += ay * time_step; 124 | let (mut x, mut y) = (self.x, self.y); 125 | 126 | // Perform bounds checking on the borders 127 | if x - self.radius <= 0.1f64 { 128 | vx *= -0.3; 129 | x = 0.1f64 + self.radius; 130 | } else if x + self.radius >= 19.9f64 { 131 | vx *= -0.3; 132 | x = 19.9f64 - self.radius; 133 | } 134 | if y - self.radius < 0.01f64 { 135 | vy *= -0.3; 136 | y = 0.01f64 + self.radius; 137 | } else if y + self.radius > 19.9f64 { 138 | vy *= -0.3; 139 | y = 19.9f64 - self.radius; 140 | } 141 | 142 | MyEntity { 143 | vx, 144 | vy, 145 | x: x + vx, 146 | y: y + vy, 147 | radius: self.radius, 148 | color: if !simulation_result.collisions.is_empty() { 149 | "red" 150 | } else { 151 | "blue" 152 | } 153 | .to_string(), 154 | } 155 | } 156 | } 157 | 158 | impl Key for MyEntity { 159 | type Value = MyEntity; 160 | } 161 | 162 | impl MyEntity { 163 | pub fn random_entity() -> MyEntity { 164 | MyEntity { 165 | vx: 0f64, 166 | vy: 0f64, 167 | x: rand::random::() * 20f64, 168 | y: rand::random::() * 20f64, 169 | radius: rand::random::() / 10f64, 170 | color: String::from("blue"), 171 | } 172 | } 173 | } 174 | 175 | fn main() { 176 | let mut starter_entities: Vec = (0..20).map(|_| MyEntity::random_entity()).collect(); 177 | let mut big_boi = MyEntity::random_entity(); 178 | big_boi.x = 10f64; 179 | big_boi.y = 10f64; 180 | big_boi.radius = 1f64; 181 | starter_entities.push(big_boi); 182 | let mut big_boi_2 = MyEntity::random_entity(); 183 | big_boi_2.x = 7f64; 184 | big_boi_2.y = 7f64; 185 | big_boi_2.radius = 1f64; 186 | big_boi_2.color = "green".to_string(); 187 | starter_entities.push(big_boi_2); 188 | let grav_tree = bigbang::GravTree::new( 189 | &mut starter_entities, 190 | TIME_STEP, 191 | MAX_ENTITIES, 192 | THETA, 193 | CalculateCollisions::No, 194 | ); 195 | 196 | println!("initializing simulation..."); 197 | { 198 | STATE.write().unwrap().state = SimulationState { 199 | grav_tree, 200 | last_time_ran: Utc::now(), 201 | last_response: String::new(), 202 | }; 203 | } 204 | let mut router = Router::new(); 205 | router.get("/", move |_r: &mut Request| simulation(), "home"); 206 | 207 | let mut chain = Chain::new(router); 208 | let cors_middleware = CorsMiddleware::with_allow_any(); 209 | chain.link_around(cors_middleware); 210 | 211 | // Find the path of the JS visualization file to serve. 212 | let project_directory = env!("CARGO_MANIFEST_DIR"); 213 | println!("project dir is {}", project_directory); 214 | let files_path = format!("{}{}", project_directory, "/src/2d_js/visualize.html"); 215 | println!("Serving {}", files_path); 216 | let mut mount = Mount::new(); 217 | mount 218 | .mount("/api", chain) 219 | .mount("/", Static::new(files_path)); 220 | 221 | println!("Browse to http://localhost:4001 to heat up your computer."); 222 | Iron::new(mount) 223 | .http("localhost:4001") 224 | .expect("unable to mount server"); 225 | } 226 | 227 | fn simulation() -> IronResult { 228 | { 229 | if Utc::now() 230 | .signed_duration_since(STATE.read().unwrap().state.last_time_ran) 231 | .num_milliseconds() 232 | < 30 233 | { 234 | return Ok(Response::with(( 235 | status::Ok, 236 | STATE.read().unwrap().state.last_response.clone(), 237 | ))); 238 | } 239 | } 240 | let grav_tree = STATE.read().unwrap().state.grav_tree.time_step(); 241 | 242 | let resp_data = serde_json::to_string(&grav_tree.as_vec()).unwrap(); 243 | 244 | STATE.write().unwrap().state = SimulationState { 245 | grav_tree, 246 | last_time_ran: Utc::now(), 247 | last_response: resp_data.clone(), 248 | }; 249 | Ok(Response::with((status::Ok, resp_data))) 250 | } 251 | -------------------------------------------------------------------------------- /examples/src/websocket_3d/server.rs: -------------------------------------------------------------------------------- 1 | //! Implements a WebSocket server that provides updates of the current state of the simulation 2 | //! to all connected clients. 3 | 4 | extern crate bigbang; 5 | extern crate rand; 6 | use bigbang::{collisions::soft_body, AsEntity, GravTree, Responsive, SimulationResult}; 7 | #[macro_use] 8 | extern crate log; 9 | 10 | use std::error::Error; 11 | use std::net::SocketAddr; 12 | use std::sync::{Arc, RwLock}; 13 | use std::thread; 14 | 15 | use futures::{ 16 | compat::{Compat, Compat01As03, Compat01As03Sink, Future01CompatExt, Stream01CompatExt}, 17 | future::FutureExt, 18 | prelude::*, 19 | }; 20 | 21 | use rand::prelude::*; 22 | use tokio::runtime::TaskExecutor; 23 | use websocket::message::OwnedMessage; 24 | use websocket::r#async::{Server, TcpStream}; 25 | use websocket::server::{r#async::Incoming, upgrade::r#async::Upgrade}; 26 | const ENTITY_COUNT: usize = 200; 27 | const MAX_ENTITIES: i32 = 3; 28 | const THETA: f64 = 0.2; 29 | const TIME_STEP: f64 = 0.00001; 30 | 31 | fn spawn_future(f: F, executor: &TaskExecutor) 32 | where 33 | F: FutureExt + 'static + Send + Unpin, 34 | { 35 | executor.spawn(Compat::new(f.unit_error().map(move |_| Ok(())))); 36 | } 37 | 38 | #[derive(Clone, PartialEq, AsEntity)] 39 | struct Entity { 40 | x: f64, 41 | y: f64, 42 | z: f64, 43 | vx: f64, 44 | vy: f64, 45 | vz: f64, 46 | radius: f64, 47 | mass: f64, 48 | } 49 | 50 | impl Responsive for Entity { 51 | fn respond(&self, simulation_result: SimulationResult, time_step: f64) -> Self { 52 | let (ax, ay, az) = if !simulation_result.collisions.is_empty() { 53 | // If there were some collisions, perform collision calculations instead of gravitational onees. 54 | let mut ax = 0.; 55 | let mut ay = 0.; 56 | let mut az = 0.; 57 | for other in &simulation_result.collisions { 58 | let (collision_ax, collision_ay, collision_az) = soft_body(self, other, 200000f64); 59 | ax += collision_ax; 60 | ay += collision_ay; 61 | az += collision_az 62 | } 63 | (ax, ay, az) 64 | } else { 65 | // Otherwise, use gravtiational acceleration. 66 | let (ax, ay, az) = simulation_result.gravitational_acceleration; 67 | (ax, ay, az) 68 | }; 69 | 70 | let (mut vx, mut vy, mut vz) = (self.vx, self.vy, self.vz); 71 | 72 | // Add the acceleration to the velocity, scaled to the time step 73 | vx += ax * time_step; 74 | vy += ay * time_step; 75 | vz += az * time_step; 76 | 77 | Entity { 78 | vx, 79 | vy, 80 | vz, 81 | x: self.x + vx, 82 | y: self.y + vy, 83 | z: self.z + vz, 84 | radius: self.radius, 85 | mass: self.mass, 86 | } 87 | } 88 | } 89 | 90 | async fn handle_connection( 91 | executor: TaskExecutor, 92 | upgrade: Upgrade, 93 | socket_addr: SocketAddr, 94 | state: Arc>>, 95 | rx: multiqueue::BroadcastFutReceiver<()>, 96 | ) { 97 | debug!("Handling WS connection..."); 98 | if !upgrade.protocols().iter().any(|s| s == "rust-websocket") { 99 | warn!( 100 | "Invalid protocol received from WS client; doesn't include \"rust-websocket\": {:?}", 101 | upgrade.protocols() 102 | ); 103 | spawn_future(upgrade.reject().compat(), &executor); 104 | return; 105 | } 106 | 107 | let client: websocket::client::r#async::Client = match upgrade 108 | .use_protocol("rust-websocket") 109 | .accept() 110 | .compat() 111 | .await 112 | { 113 | Ok((client, _headers)) => client, 114 | Err(err) => { 115 | error!("Error accepting client connection: {:?}", err); 116 | return; 117 | } 118 | }; 119 | 120 | info!("New client connected; sending welcome message..."); 121 | 122 | let mut compat_client = Compat01As03Sink::new(client); 123 | match compat_client 124 | .send(websocket::message::Message::text("Connected").into()) 125 | .await 126 | { 127 | Ok(()) => (), 128 | Err(err) => { 129 | error!("Error sending welcome message to client: {:?}", err); 130 | return; 131 | } 132 | }; 133 | 134 | let (mut sink, _stream) = compat_client.split(); 135 | 136 | // Listen for notification events and trigger each client to send the current simulation state 137 | let mut rx = rx.compat(); 138 | while (rx.next().await).is_some() { 139 | debug!( 140 | "New server tick! Sending update to connected client on address {}...", 141 | socket_addr 142 | ); 143 | 144 | trace!("Reading state buffer..."); 145 | let msg = { 146 | let state_inner = &*state.read().unwrap(); 147 | let mut state_clone: Vec = unsafe { std::mem::transmute(state_inner.clone()) }; 148 | unsafe { state_clone.set_len(state_inner.len() * std::mem::size_of::()) }; 149 | 150 | OwnedMessage::Binary(state_clone) 151 | }; 152 | trace!("Releasing read lock on state buffer."); 153 | trace!("Sending update message to client {}", socket_addr); 154 | 155 | match sink.send(msg).await { 156 | Ok(_) => debug!("Successfully sent server update to client {}", socket_addr), 157 | Err(err) => error!("Error sending server update to client: {:?}", err), 158 | }; 159 | } 160 | } 161 | 162 | async fn server_logic( 163 | executor: TaskExecutor, 164 | incoming: Incoming, 165 | state: Arc>>, 166 | rx: multiqueue::BroadcastFutReceiver<()>, 167 | ) -> Result<(), ()> { 168 | let mut incoming = incoming.compat(); 169 | while let Some(res) = incoming.next().await { 170 | match res { 171 | Ok((upgrade, socket_addr)) => { 172 | info!("Got a new WS connection from {}", socket_addr); 173 | 174 | executor.spawn( 175 | handle_connection( 176 | executor.clone(), 177 | upgrade, 178 | socket_addr, 179 | Arc::clone(&state), 180 | rx.add_stream(), 181 | ) 182 | .unit_error() 183 | .boxed() 184 | .compat(), 185 | ); 186 | } 187 | Err(err) => { 188 | error!("Error in WS server: {:?}", err); 189 | } 190 | } 191 | } 192 | 193 | Ok(()) 194 | } 195 | 196 | /// Starts the WebSocket server and returns a handle that can be used to communicate with it in 197 | /// order to indicate that there is a new update to send to clients. 198 | fn start_ws_server( 199 | executor: TaskExecutor, 200 | ) -> Result<(Arc>>, multiqueue::BroadcastFutSender<()>), Box> { 201 | //INIT.call_once(|| init_logging().expect("Failed to initialize logger")); 202 | 203 | let (tx, rx) = multiqueue::broadcast_fut_queue(1); 204 | 205 | let state = Arc::new(RwLock::new(Vec::new())); 206 | let state_clone = Arc::clone(&state); 207 | 208 | thread::spawn(move || { 209 | let ws_server = Server::bind("0.0.0.0:3355", &tokio::reactor::Handle::default()) 210 | .expect("Failed to initialize WS server"); 211 | 212 | // Initialize the loop that handles incoming client connections, sends them welcome 213 | // messages, and stores them in the set of active connections. 214 | let server_loop_v03_future = 215 | server_logic(executor.clone(), ws_server.incoming(), state, rx.clone()); 216 | 217 | spawn_future(server_loop_v03_future.boxed(), &executor); 218 | 219 | info!("Initializing main sink..."); 220 | let sink_fut = Compat01As03::new(rx).fold((), |_acc, _| future::ready(())); 221 | spawn_future(sink_fut.boxed(), &executor); 222 | }); 223 | 224 | Ok((state_clone, tx)) 225 | } 226 | 227 | #[allow(unreachable_code)] 228 | async fn run(executor: TaskExecutor) { 229 | let (state, tx) = match start_ws_server(executor) { 230 | Ok((state, tx)) => (state, tx), 231 | Err(err) => panic!("Failed to initialize WebSocket server: {:?}", err), 232 | }; 233 | let mut tx = Compat01As03Sink::new(tx); 234 | 235 | let mut vec_that_wants_to_be_a_kdtree: Vec = Vec::new(); 236 | for _ in 0..ENTITY_COUNT { 237 | let mass = rand::thread_rng().gen_range(0.1, 2.5); 238 | let entity = Entity { 239 | vx: 0.0, //rand::thread_rng().gen_range(-190., 90.), 240 | vy: 0.0, //rand::thread_rng().gen_range(-190., 90.), 241 | vz: 0.0, //rand::thread_rng().gen_range(-190., 90.), 242 | x: rand::thread_rng().gen_range(-190., 90.), 243 | y: rand::thread_rng().gen_range(-190., 90.), 244 | z: rand::thread_rng().gen_range(-190., 90.), 245 | radius: mass, 246 | mass, 247 | }; 248 | vec_that_wants_to_be_a_kdtree.push(entity); 249 | } 250 | 251 | // create one large entity in the middle 252 | vec_that_wants_to_be_a_kdtree.push(Entity { 253 | vx: 0., 254 | vy: 0., 255 | vz: 0., 256 | x: rand::thread_rng().gen_range(-190., 90.), 257 | y: rand::thread_rng().gen_range(-190., 90.), 258 | z: rand::thread_rng().gen_range(-190., 90.), 259 | radius: 25., 260 | mass: 250., 261 | }); 262 | 263 | let mut test_tree = GravTree::new( 264 | &mut vec_that_wants_to_be_a_kdtree, 265 | TIME_STEP, 266 | MAX_ENTITIES, 267 | THETA, 268 | bigbang::CalculateCollisions::Yes, 269 | ); 270 | 271 | loop { 272 | test_tree = test_tree.time_step(); 273 | let mut entities = test_tree.as_vec(); 274 | // Update the state with data about all of the entities 275 | { 276 | let mut state_inner = state.write().unwrap(); 277 | state_inner.clear(); 278 | // TODO this needs to be made into a proper iter later, instead of a vec and reconstruction 279 | for e in entities.iter_mut() { 280 | state_inner.push(e.x); 281 | state_inner.push(e.y); 282 | state_inner.push(e.z); 283 | state_inner.push(e.radius); 284 | } 285 | } 286 | trace!("Buffer state updated"); 287 | 288 | // Notify all connected WS clients that a new update is available 289 | trace!("before broadcast send"); 290 | // Send a message for all connected clients + one for the main sink 291 | 292 | match tx.send(()).await { 293 | Ok(_) => { 294 | debug!("Successfully sent tick notification message to all connected clients",) 295 | } 296 | Err(err) => error!("Error sending notification message to clients: {:?}", err), 297 | } 298 | 299 | // Delay::new(Duration::from_millis(30)).await.unwrap(); 300 | } 301 | } 302 | 303 | pub fn main() { 304 | let mut runtime = tokio::runtime::Builder::new().build().unwrap(); 305 | let executor = runtime.executor(); 306 | let main_future = run(executor); 307 | 308 | runtime 309 | .block_on( 310 | main_future 311 | .map(|_| -> Result<(), ()> { Ok(()) }) 312 | .boxed() 313 | .compat(), 314 | ) 315 | .expect("Server loop exited"); 316 | } 317 | -------------------------------------------------------------------------------- /bigbang/src/entity.rs: -------------------------------------------------------------------------------- 1 | use either::{Either, Left, Right}; 2 | 3 | use super::Dimension; 4 | use crate::as_entity::AsEntity; 5 | use crate::simulation_result::SimulationResult; 6 | use crate::Node; 7 | use serde::{Deserialize, Serialize}; 8 | 9 | #[derive(Clone, Copy, Serialize, Deserialize)] 10 | pub enum CalculateCollisions { 11 | Yes, 12 | No, 13 | } 14 | 15 | /// An Entity is an object (generalized to be spherical, having only a radius dimension) which has 16 | /// velocity, position, radius, and mass. This gravitational tree contains many entities and it moves 17 | /// them around according to the gravity they exert on each other. 18 | #[derive(Clone, Default)] 19 | #[repr(C)] 20 | pub struct Entity { 21 | pub vx: f64, 22 | pub vy: f64, 23 | pub vz: f64, 24 | pub x: f64, 25 | pub y: f64, 26 | pub z: f64, 27 | pub radius: f64, 28 | pub mass: f64, 29 | } 30 | 31 | impl AsEntity for Entity { 32 | fn as_entity(&self) -> Entity { 33 | self.clone() 34 | } 35 | } 36 | 37 | impl PartialEq for Entity { 38 | /// This is a workaround to prevent every particle from reporting that it is colliding with 39 | /// itself. If two particles truly become identical, they won't be reported as colliding. This 40 | /// is a spot for future improvement. The cost of adding some sort of unique ID is too much for 41 | /// the time being. 42 | fn eq(&self, other: &Self) -> bool { 43 | self.x == other.x 44 | && self.y == other.y 45 | && self.z == other.z 46 | && self.radius == other.radius 47 | && self.mass == other.mass 48 | } 49 | } 50 | 51 | impl Entity { 52 | /// Needs to be reworked to use min/max position values, but it naively checks 53 | /// if two things collide right now. 54 | fn did_collide_into(&self, other: &Entity) -> bool { 55 | self != other && self.distance(other) <= (self.radius + other.radius) 56 | } 57 | 58 | /// Returns the entity as a string with space separated values. 59 | pub fn as_string(&self) -> String { 60 | format!( 61 | "{} {} {} {} {} {} {} {}", 62 | self.x, self.y, self.z, self.vx, self.vy, self.vz, self.mass, self.radius 63 | ) 64 | } 65 | 66 | /// The returns the distance squared between two particles. 67 | /// Take the sqrt of this to get the distance. 68 | fn distance_squared(&self, other: &Entity) -> f64 { 69 | // (x2 - x1) + (y2 - y1) + (z2 - z1) 70 | // all dist variables are squared 71 | // This is being called from somewhere where `other` has NaN values 72 | let (x_dist, y_dist, z_dist) = self.distance_vector(other); 73 | x_dist * x_dist + y_dist * y_dist + z_dist * z_dist 74 | } 75 | 76 | /// Returns the distance between the two entities 77 | pub(crate) fn distance(&self, other: &Entity) -> f64 { 78 | // sqrt((x2 - x1) + (y2 - y1) + (z2 - z1)) 79 | f64::sqrt(self.distance_squared(other)) 80 | } 81 | 82 | /// Returns the distance between two entities as an (x:f64,y:f64,z:f64) tuple. 83 | pub(crate) fn distance_vector(&self, other: &Entity) -> (f64, f64, f64) { 84 | let x_dist = other.x - self.x; 85 | let y_dist = other.y - self.y; 86 | let z_dist = other.z - self.z; 87 | (x_dist, y_dist, z_dist) 88 | } 89 | 90 | pub(crate) fn get_dim(&self, dim: &Dimension) -> &f64 { 91 | match *dim { 92 | Dimension::X => &self.x, 93 | Dimension::Y => &self.y, 94 | Dimension::Z => &self.z, 95 | } 96 | } 97 | 98 | /// Returns a boolean representing whether or node the node is within the theta range 99 | /// of the entity. 100 | fn theta_exceeded(&self, node: &Node, theta: f64) -> bool { 101 | // 1) distance from entity to COM of that node 102 | // 2) if 1) * theta > size (max diff) then 103 | // This frequently makes a node with NaN positions 104 | let node_as_entity = node.as_entity(); 105 | let dist = self.distance_squared(&node_as_entity); 106 | let max_dist = node.max_distance(); 107 | (dist) * (theta * theta) > (max_dist * max_dist) 108 | } 109 | 110 | /// Given two entities, self and other, returns the acceleration that other is exerting on 111 | /// self. Other can be either an entity or a node. 112 | fn get_gravitational_acceleration( 113 | &self, 114 | oth: Either<&Entity, &Node>, 115 | ) -> (f64, f64, f64) { 116 | // TODO get rid of this clone 117 | let other = match oth { 118 | Left(entity) => entity.clone(), 119 | Right(node) => node.as_entity(), 120 | }; 121 | let d_magnitude = self.distance(&other); 122 | if d_magnitude == 0. { 123 | // sort of other use of THETA here 124 | return (0., 0., 0.); 125 | } 126 | let d_vector = self.distance_vector(&other); 127 | let d_mag_cubed = d_magnitude * d_magnitude; // TODO cube this 128 | let d_over_d_cubed = ( 129 | d_vector.0 / d_mag_cubed, 130 | d_vector.1 / d_mag_cubed, 131 | d_vector.2 / d_mag_cubed, 132 | ); 133 | ( 134 | d_over_d_cubed.0 * other.mass, 135 | d_over_d_cubed.1 * other.mass, 136 | d_over_d_cubed.2 * other.mass, 137 | ) 138 | } 139 | 140 | /// Returns the acceleration of an entity after it has had gravity from the specified node applied to it. 141 | /// In this function, we approximate some entities if they exceed a certain critera specified in 142 | /// "exceeds_theta()". If we reach a node and it is a leaf, then we automatically get the 143 | /// acceleration from every entity in that node, but if we reach a node that is not a leaf and 144 | /// exceeds_theta() is true, then we treat the node as one giant entity and get the 145 | /// acceleration from it. 146 | pub(crate) fn get_acceleration_and_collisions<'a, T: AsEntity + Clone>( 147 | &'a self, 148 | node: &'a Node, 149 | theta: f64, 150 | ) -> SimulationResult { 151 | let mut collisions = Vec::new(); 152 | let mut acceleration = (0., 0., 0.); 153 | if let Some(node) = &node.left { 154 | if node.points.is_some() { 155 | // if this node has some points, calculate their gravitational acceleration 156 | for i in node.points.as_ref().expect("unexpected null node 2") { 157 | if self.did_collide_into(&i.as_entity()) { 158 | collisions.push(i); 159 | } 160 | let tmp_accel = 161 | self.get_gravitational_acceleration::(Left(&(i.as_entity()))); 162 | acceleration.0 += tmp_accel.0; 163 | acceleration.1 += tmp_accel.1; 164 | acceleration.2 += tmp_accel.2; 165 | } 166 | } else if self.theta_exceeded(node, theta) { 167 | // otherwise, if theta is exceeded, calculate the entire node as a big boi particle 168 | let tmp_accel = self.get_gravitational_acceleration(Right(node)); 169 | acceleration.0 += tmp_accel.0; 170 | acceleration.1 += tmp_accel.1; 171 | acceleration.2 += tmp_accel.2; 172 | } else { 173 | // otherwise, theta has not been exceeded and this is not a leaf. recurse 174 | let mut res = self.get_acceleration_and_collisions(node, theta); 175 | let tmp_accel = res.gravitational_acceleration; 176 | collisions.append(&mut res.collisions); 177 | acceleration.0 += tmp_accel.0; 178 | acceleration.1 += tmp_accel.1; 179 | acceleration.2 += tmp_accel.2; 180 | } 181 | }; 182 | if let Some(node) = &node.right { 183 | if node.points.is_some() { 184 | // same logic as above 185 | for i in node.points.as_ref().expect("unexpected null node 2") { 186 | if self.did_collide_into(&i.as_entity()) { 187 | collisions.push(i); 188 | } 189 | let tmp_accel = 190 | self.get_gravitational_acceleration::(Left(&(i.as_entity()))); 191 | acceleration.0 += tmp_accel.0; 192 | acceleration.1 += tmp_accel.1; 193 | acceleration.2 += tmp_accel.2; 194 | } 195 | } else if self.theta_exceeded(node, theta) { 196 | // otherwise, if theta is exceeded, calculate the entire node as a big boi particle 197 | let tmp_accel = self.get_gravitational_acceleration(Right(node)); 198 | acceleration.0 += tmp_accel.0; 199 | acceleration.1 += tmp_accel.1; 200 | acceleration.2 += tmp_accel.2; 201 | } else { 202 | // otherwise, theta has not been exceeded and this is not a leaf. recurse 203 | let mut res = self.get_acceleration_and_collisions(node, theta); 204 | let tmp_accel = res.gravitational_acceleration; 205 | collisions.append(&mut res.collisions); 206 | acceleration.0 += tmp_accel.0; 207 | acceleration.1 += tmp_accel.1; 208 | acceleration.2 += tmp_accel.2; 209 | } 210 | }; 211 | SimulationResult { 212 | collisions, 213 | gravitational_acceleration: ( 214 | acceleration.0 + acceleration.0, 215 | acceleration.1 + acceleration.1, 216 | acceleration.2 + acceleration.2, 217 | ), 218 | } 219 | } 220 | pub(crate) fn get_acceleration_without_collisions<'a, T: AsEntity + Clone>( 221 | &'a self, 222 | node: &'a Node, 223 | theta: f64, 224 | ) -> SimulationResult { 225 | let mut acceleration = (0., 0., 0.); 226 | if let Some(node) = &node.left { 227 | if node.points.is_some() { 228 | // if this node has some points, calculate their gravitational acceleration 229 | for i in node.points.as_ref().expect("unexpected null node 2") { 230 | let tmp_accel = 231 | self.get_gravitational_acceleration::(Left(&(i.as_entity()))); 232 | acceleration.0 += tmp_accel.0; 233 | acceleration.1 += tmp_accel.1; 234 | acceleration.2 += tmp_accel.2; 235 | } 236 | } else if self.theta_exceeded(node, theta) { 237 | // otherwise, if theta is exceeded, calculate the entire node as a big boi particle 238 | let tmp_accel = self.get_gravitational_acceleration(Right(node)); 239 | acceleration.0 += tmp_accel.0; 240 | acceleration.1 += tmp_accel.1; 241 | acceleration.2 += tmp_accel.2; 242 | } else { 243 | // otherwise, theta has not been exceeded and this is not a leaf. recurse 244 | let res = self.get_acceleration_without_collisions(node, theta); 245 | let tmp_accel = res.gravitational_acceleration; 246 | acceleration.0 += tmp_accel.0; 247 | acceleration.1 += tmp_accel.1; 248 | acceleration.2 += tmp_accel.2; 249 | } 250 | }; 251 | if let Some(node) = &node.right { 252 | if node.points.is_some() { 253 | // same logic as above 254 | for i in node.points.as_ref().expect("unexpected null node 2") { 255 | let tmp_accel = 256 | self.get_gravitational_acceleration::(Left(&(i.as_entity()))); 257 | acceleration.0 += tmp_accel.0; 258 | acceleration.1 += tmp_accel.1; 259 | acceleration.2 += tmp_accel.2; 260 | } 261 | } else if self.theta_exceeded(node, theta) { 262 | // otherwise, if theta is exceeded, calculate the entire node as a big boi particle 263 | let tmp_accel = self.get_gravitational_acceleration(Right(node)); 264 | acceleration.0 += tmp_accel.0; 265 | acceleration.1 += tmp_accel.1; 266 | acceleration.2 += tmp_accel.2; 267 | } else { 268 | // otherwise, theta has not been exceeded and this is not a leaf. recurse 269 | let res = self.get_acceleration_without_collisions(node, theta); 270 | let tmp_accel = res.gravitational_acceleration; 271 | acceleration.0 += tmp_accel.0; 272 | acceleration.1 += tmp_accel.1; 273 | acceleration.2 += tmp_accel.2; 274 | } 275 | }; 276 | SimulationResult { 277 | collisions: vec![], 278 | gravitational_acceleration: ( 279 | acceleration.0 + acceleration.0, 280 | acceleration.1 + acceleration.1, 281 | acceleration.2 + acceleration.2, 282 | ), 283 | } 284 | } 285 | } 286 | -------------------------------------------------------------------------------- /bigbang/src/node.rs: -------------------------------------------------------------------------------- 1 | use crate::as_entity::AsEntity; 2 | use crate::dimension::Dimension; 3 | use crate::entity::Entity; 4 | use crate::utilities::{find_median, max_min_xyz, xyz_distances}; 5 | use serde::{Deserialize, Serialize}; 6 | 7 | /// This is internal to the tree and is not exposed to the consumer. 8 | /// 9 | /// A [[Node]] is either a leaf or an internal node. If it is an internal node, it contains _no_ entities. Instead, 10 | /// it is purely structural and contains aggregate statistics of its children. An internal node will sometimes be treated 11 | /// as an [[Entity]] of its own via `as_entity()` (not to be confused with the trait [[AsEntity]] -- this is just a method on 12 | /// [[Node]]. 13 | /// 14 | /// If a [[Node]] is a leaf, then it contains up to `max_entities` particles, as swell as the aggregate values of these particles. 15 | /// These aggregate values are the center of mass, the total mass, and max/min values for each dimension. 16 | #[derive(Serialize, Deserialize, Clone)] 17 | pub(crate) struct Node { 18 | split_dimension: Option, // Dimension that this node splits at. 19 | split_value: f64, // Value that this node splits at. 20 | pub(crate) left: Option>>, // Left subtree. 21 | pub(crate) right: Option>>, // Right subtree. 22 | pub(crate) points: Option>, // Vector of the points if this node is a Leaf. 23 | pub(crate) center_of_mass: (f64, f64, f64), /* The center of mass for this node and it's children all 24 | * together. (x, y, z). */ 25 | total_mass: f64, // Total mass of all entities under this node. 26 | r_max: f64, // Maximum radius that is a child of this node. 27 | x_min: f64, 28 | x_max: f64, 29 | y_min: f64, 30 | y_max: f64, 31 | z_min: f64, 32 | z_max: f64, 33 | } 34 | 35 | impl Node { 36 | pub(crate) fn new() -> Node { 37 | Node { 38 | split_dimension: None, 39 | split_value: 0.0, 40 | left: None, 41 | right: None, 42 | points: None, 43 | center_of_mass: (0.0, 0.0, 0.0), 44 | total_mass: 0.0, 45 | r_max: 0.0, 46 | x_min: 0.0, 47 | x_max: 0.0, 48 | y_min: 0.0, 49 | y_max: 0.0, 50 | z_min: 0.0, 51 | z_max: 0.0, 52 | } 53 | } 54 | /// Looks into its own children's maximum and minimum values, setting its own 55 | /// values accordingly. 56 | pub(crate) fn set_max_mins(&mut self) { 57 | let xmin = f64::min( 58 | self.left.as_ref().unwrap().x_min, 59 | self.right.as_ref().unwrap().x_min, 60 | ); 61 | let xmax = f64::max( 62 | self.left.as_ref().unwrap().x_max, 63 | self.right.as_ref().unwrap().x_max, 64 | ); 65 | let ymin = f64::min( 66 | self.left.as_ref().unwrap().y_min, 67 | self.right.as_ref().unwrap().y_min, 68 | ); 69 | let ymax = f64::max( 70 | self.left.as_ref().unwrap().y_max, 71 | self.right.as_ref().unwrap().y_max, 72 | ); 73 | let zmin = f64::min( 74 | self.left.as_ref().unwrap().z_min, 75 | self.right.as_ref().unwrap().z_min, 76 | ); 77 | let zmax = f64::max( 78 | self.left.as_ref().unwrap().z_max, 79 | self.right.as_ref().unwrap().z_max, 80 | ); 81 | let left_r_max = self.left.as_ref().expect("unexpected null node #7").r_max; 82 | let right_r_max = self.right.as_ref().expect("unexpected null node #8").r_max; 83 | self.r_max = f64::max(left_r_max, right_r_max); 84 | self.x_min = xmin; 85 | self.x_max = xmax; 86 | self.y_min = ymin; 87 | self.y_max = ymax; 88 | self.z_min = zmin; 89 | self.z_max = zmax; 90 | } 91 | // Used when treating a node as the sum of its parts in gravity calculations. 92 | /// Converts a node into an entity with the x, y, z, and mass being derived from the center of 93 | /// mass and the total mass of the entities it contains. 94 | pub(crate) fn as_entity(&self) -> Entity { 95 | // Construct a "super radius" of the largest dimension / 2 + a radius. 96 | let (range_x, range_y, range_z) = ( 97 | self.x_max - self.x_min, 98 | self.y_max - self.y_min, 99 | self.z_max - self.z_min, 100 | ); 101 | let max_dimension_range = f64::max(range_x, f64::max(range_y, range_z)); 102 | let super_radius = max_dimension_range / 2f64 + self.r_max; 103 | // Center of mass is NaN a lot 104 | Entity { 105 | x: self.center_of_mass.0, 106 | y: self.center_of_mass.1, 107 | z: self.center_of_mass.2, 108 | vx: 0.0, 109 | vy: 0.0, 110 | vz: 0.0, 111 | mass: self.total_mass, 112 | radius: super_radius, 113 | } 114 | } 115 | 116 | pub(crate) fn max_distance(&self) -> f64 { 117 | let x_distance = self.x_max - self.x_min; 118 | let y_distance = self.y_max - self.y_min; 119 | let z_distance = self.z_max - self.z_min; 120 | f64::max(x_distance, f64::max(y_distance, z_distance)) 121 | } 122 | 123 | /// Traverses tree and returns first child found with points. 124 | pub(crate) fn traverse_tree_helper(&self) -> Vec { 125 | let mut to_return: Vec = Vec::new(); 126 | if let Some(node) = &self.left { 127 | to_return.append(&mut node.traverse_tree_helper()); 128 | } 129 | if let Some(node) = &self.right { 130 | to_return.append(&mut node.traverse_tree_helper()); 131 | } else { 132 | to_return.append( 133 | &mut (self 134 | .points 135 | .as_ref() 136 | .expect("unexpected null node #10") 137 | .clone()), 138 | ); 139 | } 140 | to_return 141 | } 142 | 143 | /// Takes in a mutable slice of entities and creates a recursive 3d tree structure. 144 | pub(crate) fn new_root_node(pts: &[T], max_entities: i32) -> Node { 145 | // Start and end are probably 0 and pts.len(), respectively. 146 | let length_of_points = pts.len() as i32; 147 | let mut entities = pts.iter().map(|x| x.as_entity()).collect::>(); 148 | let (xdistance, ydistance, zdistance) = xyz_distances(entities.as_slice()); 149 | // If our current collection is small enough to become a leaf (it has less than 150 | // max_entities entities) 151 | if length_of_points <= max_entities { 152 | // then we convert it into a leaf node. 153 | 154 | // we calculate the center of mass and total mass for each axis and store it as a three-tuple. 155 | // This admittedly terse `fold` used to be a for loop. I refactored it for the sake of immutability. 156 | // I'm still unsure if this was optimal. 157 | let (x_total, y_total, z_total, max_radius, total_mass) = 158 | // making this iterator parallel negatively impacts performance, at least for 159 | // bench_05 and bench_10 160 | pts.iter().fold((0.0, 0.0, 0.0, 0.0, 0.0), |acc, pt| { 161 | let pt = pt.as_entity(); 162 | ( 163 | acc.0 + (pt.x * pt.mass), 164 | acc.1 + (pt.y * pt.mass), 165 | acc.2 + (pt.z * pt.mass), 166 | if acc.3 > pt.radius { acc.3 } else { pt.radius }, 167 | acc.4 + pt.mass, 168 | ) 169 | }); 170 | 171 | let (x_max, x_min, y_max, y_min, z_max, z_min) = max_min_xyz(&entities); 172 | Node { 173 | center_of_mass: ( 174 | x_total / total_mass, 175 | y_total / total_mass, 176 | z_total / total_mass, 177 | ), 178 | total_mass, 179 | r_max: max_radius, 180 | points: Some(pts.to_vec()), 181 | left: None, 182 | right: None, 183 | split_dimension: None, 184 | split_value: 0.0, 185 | x_max: *x_max, 186 | x_min: *x_min, 187 | y_max: *y_max, 188 | y_min: *y_min, 189 | z_max: *z_max, 190 | z_min: *z_min, 191 | } 192 | // So the objective here is to find the median value for whatever axis has the greatest disparity in distance. 193 | // It is more efficient to pick three random values and pick the median of those as the pivot point, so that is 194 | // done if the vector has enough points. Otherwise, it picks the first element. FindMiddle just returns the middle 195 | // value of the three f64's given to it. Hopefully there is a more idomatic way to do this. 196 | } else { 197 | let mut root_node = Node::new(); 198 | let split_index; 199 | let (split_dimension, split_value) = if zdistance > ydistance && zdistance > xdistance { 200 | // "If the z distance is the greatest" 201 | // split on Z 202 | let (split_value, tmp) = find_median(Dimension::Z, &mut entities); 203 | split_index = tmp; 204 | (Dimension::Z, split_value) 205 | } else if ydistance > xdistance && ydistance > zdistance { 206 | // "If the y distance is the greatest" 207 | // split on Y 208 | let (split_value, tmp) = find_median(Dimension::Y, &mut entities); 209 | split_index = tmp; 210 | (Dimension::Y, split_value) 211 | } else { 212 | // "If the x distance is the greatest" 213 | // split on X 214 | let (split_value, tmp) = find_median(Dimension::X, &mut entities); 215 | split_index = tmp; 216 | (Dimension::X, split_value) 217 | }; 218 | root_node.split_dimension = Some(split_dimension); 219 | root_node.split_value = *split_value; 220 | let (below_split, above_split) = pts.split_at(split_index); 221 | 222 | // Now we construct the left and right children based on this split into lower and upper halves. 223 | let left = Node::new_root_node(below_split, max_entities); 224 | let right = Node::new_root_node(above_split, max_entities); 225 | // The center of mass is a recursive definition. This finds the average COM for 226 | // each node. 227 | let left_mass = left.total_mass; 228 | let right_mass = right.total_mass; 229 | let (left_x, left_y, left_z) = left.center_of_mass; 230 | let (right_x, right_y, right_z) = right.center_of_mass; 231 | let total_mass = left_mass + right_mass; 232 | assert!(total_mass != 0., "invalid mass of 0"); 233 | 234 | let (center_x, center_y, center_z) = ( 235 | ((left_mass * left_x) + (right_mass * right_x)) / total_mass, 236 | ((left_mass * left_y) + (right_mass * right_y)) / total_mass, 237 | ((left_mass * left_z) + (right_mass * right_z)) / total_mass, 238 | ); 239 | root_node.left = Some(Box::new(left)); 240 | root_node.right = Some(Box::new(right)); 241 | root_node.center_of_mass = (center_x, center_y, center_z); 242 | root_node.set_max_mins(); 243 | root_node.total_mass = total_mass; 244 | root_node 245 | } 246 | } 247 | } 248 | 249 | /// This tests the recursive node construction used to create a new gravtree. It tests some private 250 | /// fields so it is located within the same module as the node itself. 251 | #[test] 252 | fn test() { 253 | use crate::{collisions::soft_body, Responsive, SimulationResult}; 254 | impl Responsive for Entity { 255 | fn respond(&self, simulation_result: SimulationResult, time_step: f64) -> Self { 256 | let mut vx = self.vx; 257 | let mut vy = self.vy; 258 | let mut vz = self.vz; 259 | let (mut ax, mut ay, mut az) = simulation_result.gravitational_acceleration; 260 | for other in simulation_result.collisions { 261 | let (collision_ax, collision_ay, collision_az) = soft_body(self, other, 50f64); 262 | ax += collision_ax; 263 | ay += collision_ay; 264 | az += collision_az; 265 | } 266 | vx += ax * time_step; 267 | vy += ay * time_step; 268 | vz += az * time_step; 269 | 270 | Entity { 271 | vx, 272 | vy, 273 | vz, 274 | x: self.x + (vx * time_step), 275 | y: self.y + (vy * time_step), 276 | z: self.z + (vz * time_step), 277 | radius: self.radius, 278 | mass: self.mass, 279 | } 280 | } 281 | } 282 | let mut test_vec: Vec = Vec::new(); 283 | for i in 0..10 { 284 | test_vec.push(Entity { 285 | x: i as f64, 286 | y: (10 - i) as f64, 287 | z: i as f64, 288 | vx: i as f64, 289 | vy: i as f64, 290 | vz: i as f64, 291 | mass: i as f64, 292 | radius: i as f64, 293 | }); 294 | } 295 | 296 | let check_vec = test_vec.clone(); 297 | let tree = crate::GravTree::new(&test_vec, 0.2, 3, 0.2); 298 | let root_node = tree.root.clone(); 299 | 300 | let mut nodes: Vec> = Vec::new(); 301 | let mut traversal_stack: Vec>>> = Vec::new(); 302 | let mut rover = Some(Box::new(root_node)); 303 | while !traversal_stack.is_empty() || rover.is_some() { 304 | if rover.is_some() { 305 | traversal_stack.push(rover.clone()); 306 | nodes.push(*rover.clone().unwrap()); 307 | rover = rover.unwrap().left; 308 | } else { 309 | rover = traversal_stack.pop().unwrap(); 310 | rover = rover.unwrap().right; 311 | } 312 | } 313 | 314 | let post_tree_vec = tree.as_vec(); 315 | // The tree should contain all of the elements we put into it. 316 | for i in check_vec.iter() { 317 | assert!(post_tree_vec.contains(i)); 318 | } 319 | 320 | // In this example, there should be exactly 8 nodes. 321 | assert_eq!(8, nodes.len()); 322 | 323 | // No node should have zero mass, except for the first one which is the "phantom parent". 324 | for node in nodes.iter().skip(1) { 325 | assert!(node.total_mass > 0.); 326 | } 327 | 328 | // The total mass of the root node should be the sum of all of their masses. 329 | let total_mass = check_vec.iter().fold(0., |acc, x| acc + x.mass); 330 | assert_eq!(total_mass, tree.root.left.unwrap().total_mass); 331 | } 332 | -------------------------------------------------------------------------------- /bigbang/test_files/test_output.txt: -------------------------------------------------------------------------------- 1 | 999 999 999 999 999 999 5 5 2 | 998 998 998 998 998 998 5 5 3 | 997 997 997 997 997 997 5 5 4 | 996 996 996 996 996 996 5 5 5 | 995 995 995 995 995 995 5 5 6 | 994 994 994 994 994 994 5 5 7 | 993 993 993 993 993 993 5 5 8 | 992 992 992 992 992 992 5 5 9 | 991 991 991 991 991 991 5 5 10 | 990 990 990 990 990 990 5 5 11 | 989 989 989 989 989 989 5 5 12 | 988 988 988 988 988 988 5 5 13 | 987 987 987 987 987 987 5 5 14 | 986 986 986 986 986 986 5 5 15 | 985 985 985 985 985 985 5 5 16 | 984 984 984 984 984 984 5 5 17 | 983 983 983 983 983 983 5 5 18 | 982 982 982 982 982 982 5 5 19 | 981 981 981 981 981 981 5 5 20 | 980 980 980 980 980 980 5 5 21 | 979 979 979 979 979 979 5 5 22 | 978 978 978 978 978 978 5 5 23 | 977 977 977 977 977 977 5 5 24 | 976 976 976 976 976 976 5 5 25 | 975 975 975 975 975 975 5 5 26 | 974 974 974 974 974 974 5 5 27 | 973 973 973 973 973 973 5 5 28 | 972 972 972 972 972 972 5 5 29 | 971 971 971 971 971 971 5 5 30 | 970 970 970 970 970 970 5 5 31 | 969 969 969 969 969 969 5 5 32 | 968 968 968 968 968 968 5 5 33 | 967 967 967 967 967 967 5 5 34 | 966 966 966 966 966 966 5 5 35 | 965 965 965 965 965 965 5 5 36 | 964 964 964 964 964 964 5 5 37 | 963 963 963 963 963 963 5 5 38 | 962 962 962 962 962 962 5 5 39 | 961 961 961 961 961 961 5 5 40 | 960 960 960 960 960 960 5 5 41 | 959 959 959 959 959 959 5 5 42 | 958 958 958 958 958 958 5 5 43 | 957 957 957 957 957 957 5 5 44 | 956 956 956 956 956 956 5 5 45 | 955 955 955 955 955 955 5 5 46 | 954 954 954 954 954 954 5 5 47 | 953 953 953 953 953 953 5 5 48 | 952 952 952 952 952 952 5 5 49 | 951 951 951 951 951 951 5 5 50 | 950 950 950 950 950 950 5 5 51 | 949 949 949 949 949 949 5 5 52 | 948 948 948 948 948 948 5 5 53 | 947 947 947 947 947 947 5 5 54 | 946 946 946 946 946 946 5 5 55 | 945 945 945 945 945 945 5 5 56 | 944 944 944 944 944 944 5 5 57 | 943 943 943 943 943 943 5 5 58 | 942 942 942 942 942 942 5 5 59 | 941 941 941 941 941 941 5 5 60 | 940 940 940 940 940 940 5 5 61 | 939 939 939 939 939 939 5 5 62 | 938 938 938 938 938 938 5 5 63 | 937 937 937 937 937 937 5 5 64 | 936 936 936 936 936 936 5 5 65 | 935 935 935 935 935 935 5 5 66 | 934 934 934 934 934 934 5 5 67 | 933 933 933 933 933 933 5 5 68 | 932 932 932 932 932 932 5 5 69 | 931 931 931 931 931 931 5 5 70 | 930 930 930 930 930 930 5 5 71 | 929 929 929 929 929 929 5 5 72 | 928 928 928 928 928 928 5 5 73 | 927 927 927 927 927 927 5 5 74 | 926 926 926 926 926 926 5 5 75 | 925 925 925 925 925 925 5 5 76 | 924 924 924 924 924 924 5 5 77 | 923 923 923 923 923 923 5 5 78 | 922 922 922 922 922 922 5 5 79 | 921 921 921 921 921 921 5 5 80 | 920 920 920 920 920 920 5 5 81 | 919 919 919 919 919 919 5 5 82 | 918 918 918 918 918 918 5 5 83 | 917 917 917 917 917 917 5 5 84 | 916 916 916 916 916 916 5 5 85 | 915 915 915 915 915 915 5 5 86 | 914 914 914 914 914 914 5 5 87 | 913 913 913 913 913 913 5 5 88 | 912 912 912 912 912 912 5 5 89 | 911 911 911 911 911 911 5 5 90 | 910 910 910 910 910 910 5 5 91 | 909 909 909 909 909 909 5 5 92 | 908 908 908 908 908 908 5 5 93 | 907 907 907 907 907 907 5 5 94 | 906 906 906 906 906 906 5 5 95 | 905 905 905 905 905 905 5 5 96 | 904 904 904 904 904 904 5 5 97 | 903 903 903 903 903 903 5 5 98 | 902 902 902 902 902 902 5 5 99 | 901 901 901 901 901 901 5 5 100 | 900 900 900 900 900 900 5 5 101 | 899 899 899 899 899 899 5 5 102 | 898 898 898 898 898 898 5 5 103 | 897 897 897 897 897 897 5 5 104 | 896 896 896 896 896 896 5 5 105 | 895 895 895 895 895 895 5 5 106 | 894 894 894 894 894 894 5 5 107 | 893 893 893 893 893 893 5 5 108 | 892 892 892 892 892 892 5 5 109 | 891 891 891 891 891 891 5 5 110 | 890 890 890 890 890 890 5 5 111 | 889 889 889 889 889 889 5 5 112 | 888 888 888 888 888 888 5 5 113 | 887 887 887 887 887 887 5 5 114 | 886 886 886 886 886 886 5 5 115 | 885 885 885 885 885 885 5 5 116 | 884 884 884 884 884 884 5 5 117 | 883 883 883 883 883 883 5 5 118 | 882 882 882 882 882 882 5 5 119 | 881 881 881 881 881 881 5 5 120 | 880 880 880 880 880 880 5 5 121 | 879 879 879 879 879 879 5 5 122 | 878 878 878 878 878 878 5 5 123 | 877 877 877 877 877 877 5 5 124 | 876 876 876 876 876 876 5 5 125 | 875 875 875 875 875 875 5 5 126 | 874 874 874 874 874 874 5 5 127 | 873 873 873 873 873 873 5 5 128 | 872 872 872 872 872 872 5 5 129 | 871 871 871 871 871 871 5 5 130 | 870 870 870 870 870 870 5 5 131 | 869 869 869 869 869 869 5 5 132 | 868 868 868 868 868 868 5 5 133 | 867 867 867 867 867 867 5 5 134 | 866 866 866 866 866 866 5 5 135 | 865 865 865 865 865 865 5 5 136 | 864 864 864 864 864 864 5 5 137 | 863 863 863 863 863 863 5 5 138 | 862 862 862 862 862 862 5 5 139 | 861 861 861 861 861 861 5 5 140 | 860 860 860 860 860 860 5 5 141 | 859 859 859 859 859 859 5 5 142 | 858 858 858 858 858 858 5 5 143 | 857 857 857 857 857 857 5 5 144 | 856 856 856 856 856 856 5 5 145 | 855 855 855 855 855 855 5 5 146 | 854 854 854 854 854 854 5 5 147 | 853 853 853 853 853 853 5 5 148 | 852 852 852 852 852 852 5 5 149 | 851 851 851 851 851 851 5 5 150 | 850 850 850 850 850 850 5 5 151 | 849 849 849 849 849 849 5 5 152 | 848 848 848 848 848 848 5 5 153 | 847 847 847 847 847 847 5 5 154 | 846 846 846 846 846 846 5 5 155 | 845 845 845 845 845 845 5 5 156 | 844 844 844 844 844 844 5 5 157 | 843 843 843 843 843 843 5 5 158 | 842 842 842 842 842 842 5 5 159 | 841 841 841 841 841 841 5 5 160 | 840 840 840 840 840 840 5 5 161 | 839 839 839 839 839 839 5 5 162 | 838 838 838 838 838 838 5 5 163 | 837 837 837 837 837 837 5 5 164 | 836 836 836 836 836 836 5 5 165 | 835 835 835 835 835 835 5 5 166 | 834 834 834 834 834 834 5 5 167 | 833 833 833 833 833 833 5 5 168 | 832 832 832 832 832 832 5 5 169 | 831 831 831 831 831 831 5 5 170 | 830 830 830 830 830 830 5 5 171 | 829 829 829 829 829 829 5 5 172 | 828 828 828 828 828 828 5 5 173 | 827 827 827 827 827 827 5 5 174 | 826 826 826 826 826 826 5 5 175 | 825 825 825 825 825 825 5 5 176 | 824 824 824 824 824 824 5 5 177 | 823 823 823 823 823 823 5 5 178 | 822 822 822 822 822 822 5 5 179 | 821 821 821 821 821 821 5 5 180 | 820 820 820 820 820 820 5 5 181 | 819 819 819 819 819 819 5 5 182 | 818 818 818 818 818 818 5 5 183 | 817 817 817 817 817 817 5 5 184 | 816 816 816 816 816 816 5 5 185 | 815 815 815 815 815 815 5 5 186 | 814 814 814 814 814 814 5 5 187 | 813 813 813 813 813 813 5 5 188 | 812 812 812 812 812 812 5 5 189 | 811 811 811 811 811 811 5 5 190 | 810 810 810 810 810 810 5 5 191 | 809 809 809 809 809 809 5 5 192 | 808 808 808 808 808 808 5 5 193 | 807 807 807 807 807 807 5 5 194 | 806 806 806 806 806 806 5 5 195 | 805 805 805 805 805 805 5 5 196 | 804 804 804 804 804 804 5 5 197 | 803 803 803 803 803 803 5 5 198 | 802 802 802 802 802 802 5 5 199 | 801 801 801 801 801 801 5 5 200 | 800 800 800 800 800 800 5 5 201 | 799 799 799 799 799 799 5 5 202 | 798 798 798 798 798 798 5 5 203 | 797 797 797 797 797 797 5 5 204 | 796 796 796 796 796 796 5 5 205 | 795 795 795 795 795 795 5 5 206 | 794 794 794 794 794 794 5 5 207 | 793 793 793 793 793 793 5 5 208 | 792 792 792 792 792 792 5 5 209 | 791 791 791 791 791 791 5 5 210 | 790 790 790 790 790 790 5 5 211 | 789 789 789 789 789 789 5 5 212 | 788 788 788 788 788 788 5 5 213 | 787 787 787 787 787 787 5 5 214 | 786 786 786 786 786 786 5 5 215 | 785 785 785 785 785 785 5 5 216 | 784 784 784 784 784 784 5 5 217 | 783 783 783 783 783 783 5 5 218 | 782 782 782 782 782 782 5 5 219 | 781 781 781 781 781 781 5 5 220 | 780 780 780 780 780 780 5 5 221 | 779 779 779 779 779 779 5 5 222 | 778 778 778 778 778 778 5 5 223 | 777 777 777 777 777 777 5 5 224 | 776 776 776 776 776 776 5 5 225 | 775 775 775 775 775 775 5 5 226 | 774 774 774 774 774 774 5 5 227 | 773 773 773 773 773 773 5 5 228 | 772 772 772 772 772 772 5 5 229 | 771 771 771 771 771 771 5 5 230 | 770 770 770 770 770 770 5 5 231 | 769 769 769 769 769 769 5 5 232 | 768 768 768 768 768 768 5 5 233 | 767 767 767 767 767 767 5 5 234 | 766 766 766 766 766 766 5 5 235 | 765 765 765 765 765 765 5 5 236 | 764 764 764 764 764 764 5 5 237 | 763 763 763 763 763 763 5 5 238 | 762 762 762 762 762 762 5 5 239 | 761 761 761 761 761 761 5 5 240 | 760 760 760 760 760 760 5 5 241 | 759 759 759 759 759 759 5 5 242 | 758 758 758 758 758 758 5 5 243 | 757 757 757 757 757 757 5 5 244 | 756 756 756 756 756 756 5 5 245 | 755 755 755 755 755 755 5 5 246 | 754 754 754 754 754 754 5 5 247 | 753 753 753 753 753 753 5 5 248 | 752 752 752 752 752 752 5 5 249 | 751 751 751 751 751 751 5 5 250 | 750 750 750 750 750 750 5 5 251 | 749 749 749 749 749 749 5 5 252 | 748 748 748 748 748 748 5 5 253 | 747 747 747 747 747 747 5 5 254 | 746 746 746 746 746 746 5 5 255 | 745 745 745 745 745 745 5 5 256 | 744 744 744 744 744 744 5 5 257 | 743 743 743 743 743 743 5 5 258 | 742 742 742 742 742 742 5 5 259 | 741 741 741 741 741 741 5 5 260 | 740 740 740 740 740 740 5 5 261 | 739 739 739 739 739 739 5 5 262 | 738 738 738 738 738 738 5 5 263 | 737 737 737 737 737 737 5 5 264 | 736 736 736 736 736 736 5 5 265 | 735 735 735 735 735 735 5 5 266 | 734 734 734 734 734 734 5 5 267 | 733 733 733 733 733 733 5 5 268 | 732 732 732 732 732 732 5 5 269 | 731 731 731 731 731 731 5 5 270 | 730 730 730 730 730 730 5 5 271 | 729 729 729 729 729 729 5 5 272 | 728 728 728 728 728 728 5 5 273 | 727 727 727 727 727 727 5 5 274 | 726 726 726 726 726 726 5 5 275 | 725 725 725 725 725 725 5 5 276 | 724 724 724 724 724 724 5 5 277 | 723 723 723 723 723 723 5 5 278 | 722 722 722 722 722 722 5 5 279 | 721 721 721 721 721 721 5 5 280 | 720 720 720 720 720 720 5 5 281 | 719 719 719 719 719 719 5 5 282 | 718 718 718 718 718 718 5 5 283 | 717 717 717 717 717 717 5 5 284 | 716 716 716 716 716 716 5 5 285 | 715 715 715 715 715 715 5 5 286 | 714 714 714 714 714 714 5 5 287 | 713 713 713 713 713 713 5 5 288 | 712 712 712 712 712 712 5 5 289 | 711 711 711 711 711 711 5 5 290 | 710 710 710 710 710 710 5 5 291 | 709 709 709 709 709 709 5 5 292 | 708 708 708 708 708 708 5 5 293 | 707 707 707 707 707 707 5 5 294 | 706 706 706 706 706 706 5 5 295 | 705 705 705 705 705 705 5 5 296 | 704 704 704 704 704 704 5 5 297 | 703 703 703 703 703 703 5 5 298 | 702 702 702 702 702 702 5 5 299 | 701 701 701 701 701 701 5 5 300 | 700 700 700 700 700 700 5 5 301 | 699 699 699 699 699 699 5 5 302 | 698 698 698 698 698 698 5 5 303 | 697 697 697 697 697 697 5 5 304 | 696 696 696 696 696 696 5 5 305 | 695 695 695 695 695 695 5 5 306 | 694 694 694 694 694 694 5 5 307 | 693 693 693 693 693 693 5 5 308 | 692 692 692 692 692 692 5 5 309 | 691 691 691 691 691 691 5 5 310 | 690 690 690 690 690 690 5 5 311 | 689 689 689 689 689 689 5 5 312 | 688 688 688 688 688 688 5 5 313 | 687 687 687 687 687 687 5 5 314 | 686 686 686 686 686 686 5 5 315 | 685 685 685 685 685 685 5 5 316 | 684 684 684 684 684 684 5 5 317 | 683 683 683 683 683 683 5 5 318 | 682 682 682 682 682 682 5 5 319 | 681 681 681 681 681 681 5 5 320 | 680 680 680 680 680 680 5 5 321 | 679 679 679 679 679 679 5 5 322 | 678 678 678 678 678 678 5 5 323 | 677 677 677 677 677 677 5 5 324 | 676 676 676 676 676 676 5 5 325 | 675 675 675 675 675 675 5 5 326 | 674 674 674 674 674 674 5 5 327 | 673 673 673 673 673 673 5 5 328 | 672 672 672 672 672 672 5 5 329 | 671 671 671 671 671 671 5 5 330 | 670 670 670 670 670 670 5 5 331 | 669 669 669 669 669 669 5 5 332 | 668 668 668 668 668 668 5 5 333 | 667 667 667 667 667 667 5 5 334 | 666 666 666 666 666 666 5 5 335 | 665 665 665 665 665 665 5 5 336 | 664 664 664 664 664 664 5 5 337 | 663 663 663 663 663 663 5 5 338 | 662 662 662 662 662 662 5 5 339 | 661 661 661 661 661 661 5 5 340 | 660 660 660 660 660 660 5 5 341 | 659 659 659 659 659 659 5 5 342 | 658 658 658 658 658 658 5 5 343 | 657 657 657 657 657 657 5 5 344 | 656 656 656 656 656 656 5 5 345 | 655 655 655 655 655 655 5 5 346 | 654 654 654 654 654 654 5 5 347 | 653 653 653 653 653 653 5 5 348 | 652 652 652 652 652 652 5 5 349 | 651 651 651 651 651 651 5 5 350 | 650 650 650 650 650 650 5 5 351 | 649 649 649 649 649 649 5 5 352 | 648 648 648 648 648 648 5 5 353 | 647 647 647 647 647 647 5 5 354 | 646 646 646 646 646 646 5 5 355 | 645 645 645 645 645 645 5 5 356 | 644 644 644 644 644 644 5 5 357 | 643 643 643 643 643 643 5 5 358 | 642 642 642 642 642 642 5 5 359 | 641 641 641 641 641 641 5 5 360 | 640 640 640 640 640 640 5 5 361 | 639 639 639 639 639 639 5 5 362 | 638 638 638 638 638 638 5 5 363 | 637 637 637 637 637 637 5 5 364 | 636 636 636 636 636 636 5 5 365 | 635 635 635 635 635 635 5 5 366 | 634 634 634 634 634 634 5 5 367 | 633 633 633 633 633 633 5 5 368 | 632 632 632 632 632 632 5 5 369 | 631 631 631 631 631 631 5 5 370 | 630 630 630 630 630 630 5 5 371 | 629 629 629 629 629 629 5 5 372 | 628 628 628 628 628 628 5 5 373 | 627 627 627 627 627 627 5 5 374 | 626 626 626 626 626 626 5 5 375 | 625 625 625 625 625 625 5 5 376 | 624 624 624 624 624 624 5 5 377 | 623 623 623 623 623 623 5 5 378 | 622 622 622 622 622 622 5 5 379 | 621 621 621 621 621 621 5 5 380 | 620 620 620 620 620 620 5 5 381 | 619 619 619 619 619 619 5 5 382 | 618 618 618 618 618 618 5 5 383 | 617 617 617 617 617 617 5 5 384 | 616 616 616 616 616 616 5 5 385 | 615 615 615 615 615 615 5 5 386 | 614 614 614 614 614 614 5 5 387 | 613 613 613 613 613 613 5 5 388 | 612 612 612 612 612 612 5 5 389 | 611 611 611 611 611 611 5 5 390 | 610 610 610 610 610 610 5 5 391 | 609 609 609 609 609 609 5 5 392 | 608 608 608 608 608 608 5 5 393 | 607 607 607 607 607 607 5 5 394 | 606 606 606 606 606 606 5 5 395 | 605 605 605 605 605 605 5 5 396 | 604 604 604 604 604 604 5 5 397 | 603 603 603 603 603 603 5 5 398 | 602 602 602 602 602 602 5 5 399 | 601 601 601 601 601 601 5 5 400 | 600 600 600 600 600 600 5 5 401 | 599 599 599 599 599 599 5 5 402 | 598 598 598 598 598 598 5 5 403 | 597 597 597 597 597 597 5 5 404 | 596 596 596 596 596 596 5 5 405 | 595 595 595 595 595 595 5 5 406 | 594 594 594 594 594 594 5 5 407 | 593 593 593 593 593 593 5 5 408 | 592 592 592 592 592 592 5 5 409 | 591 591 591 591 591 591 5 5 410 | 590 590 590 590 590 590 5 5 411 | 589 589 589 589 589 589 5 5 412 | 588 588 588 588 588 588 5 5 413 | 587 587 587 587 587 587 5 5 414 | 586 586 586 586 586 586 5 5 415 | 585 585 585 585 585 585 5 5 416 | 584 584 584 584 584 584 5 5 417 | 583 583 583 583 583 583 5 5 418 | 582 582 582 582 582 582 5 5 419 | 581 581 581 581 581 581 5 5 420 | 580 580 580 580 580 580 5 5 421 | 579 579 579 579 579 579 5 5 422 | 578 578 578 578 578 578 5 5 423 | 577 577 577 577 577 577 5 5 424 | 576 576 576 576 576 576 5 5 425 | 575 575 575 575 575 575 5 5 426 | 574 574 574 574 574 574 5 5 427 | 573 573 573 573 573 573 5 5 428 | 572 572 572 572 572 572 5 5 429 | 571 571 571 571 571 571 5 5 430 | 570 570 570 570 570 570 5 5 431 | 569 569 569 569 569 569 5 5 432 | 568 568 568 568 568 568 5 5 433 | 567 567 567 567 567 567 5 5 434 | 566 566 566 566 566 566 5 5 435 | 565 565 565 565 565 565 5 5 436 | 564 564 564 564 564 564 5 5 437 | 563 563 563 563 563 563 5 5 438 | 562 562 562 562 562 562 5 5 439 | 561 561 561 561 561 561 5 5 440 | 560 560 560 560 560 560 5 5 441 | 559 559 559 559 559 559 5 5 442 | 558 558 558 558 558 558 5 5 443 | 557 557 557 557 557 557 5 5 444 | 556 556 556 556 556 556 5 5 445 | 555 555 555 555 555 555 5 5 446 | 554 554 554 554 554 554 5 5 447 | 553 553 553 553 553 553 5 5 448 | 552 552 552 552 552 552 5 5 449 | 551 551 551 551 551 551 5 5 450 | 550 550 550 550 550 550 5 5 451 | 549 549 549 549 549 549 5 5 452 | 548 548 548 548 548 548 5 5 453 | 547 547 547 547 547 547 5 5 454 | 546 546 546 546 546 546 5 5 455 | 545 545 545 545 545 545 5 5 456 | 544 544 544 544 544 544 5 5 457 | 543 543 543 543 543 543 5 5 458 | 542 542 542 542 542 542 5 5 459 | 541 541 541 541 541 541 5 5 460 | 540 540 540 540 540 540 5 5 461 | 539 539 539 539 539 539 5 5 462 | 538 538 538 538 538 538 5 5 463 | 537 537 537 537 537 537 5 5 464 | 536 536 536 536 536 536 5 5 465 | 535 535 535 535 535 535 5 5 466 | 534 534 534 534 534 534 5 5 467 | 533 533 533 533 533 533 5 5 468 | 532 532 532 532 532 532 5 5 469 | 531 531 531 531 531 531 5 5 470 | 530 530 530 530 530 530 5 5 471 | 529 529 529 529 529 529 5 5 472 | 528 528 528 528 528 528 5 5 473 | 527 527 527 527 527 527 5 5 474 | 526 526 526 526 526 526 5 5 475 | 525 525 525 525 525 525 5 5 476 | 524 524 524 524 524 524 5 5 477 | 523 523 523 523 523 523 5 5 478 | 522 522 522 522 522 522 5 5 479 | 521 521 521 521 521 521 5 5 480 | 520 520 520 520 520 520 5 5 481 | 519 519 519 519 519 519 5 5 482 | 518 518 518 518 518 518 5 5 483 | 517 517 517 517 517 517 5 5 484 | 516 516 516 516 516 516 5 5 485 | 515 515 515 515 515 515 5 5 486 | 514 514 514 514 514 514 5 5 487 | 513 513 513 513 513 513 5 5 488 | 512 512 512 512 512 512 5 5 489 | 511 511 511 511 511 511 5 5 490 | 510 510 510 510 510 510 5 5 491 | 509 509 509 509 509 509 5 5 492 | 508 508 508 508 508 508 5 5 493 | 507 507 507 507 507 507 5 5 494 | 506 506 506 506 506 506 5 5 495 | 505 505 505 505 505 505 5 5 496 | 504 504 504 504 504 504 5 5 497 | 503 503 503 503 503 503 5 5 498 | 502 502 502 502 502 502 5 5 499 | 501 501 501 501 501 501 5 5 500 | 500 500 500 500 500 500 5 5 501 | 499 499 499 499 499 499 5 5 502 | 498 498 498 498 498 498 5 5 503 | 497 497 497 497 497 497 5 5 504 | 496 496 496 496 496 496 5 5 505 | 495 495 495 495 495 495 5 5 506 | 494 494 494 494 494 494 5 5 507 | 493 493 493 493 493 493 5 5 508 | 492 492 492 492 492 492 5 5 509 | 491 491 491 491 491 491 5 5 510 | 490 490 490 490 490 490 5 5 511 | 489 489 489 489 489 489 5 5 512 | 488 488 488 488 488 488 5 5 513 | 487 487 487 487 487 487 5 5 514 | 486 486 486 486 486 486 5 5 515 | 485 485 485 485 485 485 5 5 516 | 484 484 484 484 484 484 5 5 517 | 483 483 483 483 483 483 5 5 518 | 482 482 482 482 482 482 5 5 519 | 481 481 481 481 481 481 5 5 520 | 480 480 480 480 480 480 5 5 521 | 479 479 479 479 479 479 5 5 522 | 478 478 478 478 478 478 5 5 523 | 477 477 477 477 477 477 5 5 524 | 476 476 476 476 476 476 5 5 525 | 475 475 475 475 475 475 5 5 526 | 474 474 474 474 474 474 5 5 527 | 473 473 473 473 473 473 5 5 528 | 472 472 472 472 472 472 5 5 529 | 471 471 471 471 471 471 5 5 530 | 470 470 470 470 470 470 5 5 531 | 469 469 469 469 469 469 5 5 532 | 468 468 468 468 468 468 5 5 533 | 467 467 467 467 467 467 5 5 534 | 466 466 466 466 466 466 5 5 535 | 465 465 465 465 465 465 5 5 536 | 464 464 464 464 464 464 5 5 537 | 463 463 463 463 463 463 5 5 538 | 462 462 462 462 462 462 5 5 539 | 461 461 461 461 461 461 5 5 540 | 460 460 460 460 460 460 5 5 541 | 459 459 459 459 459 459 5 5 542 | 458 458 458 458 458 458 5 5 543 | 457 457 457 457 457 457 5 5 544 | 456 456 456 456 456 456 5 5 545 | 455 455 455 455 455 455 5 5 546 | 454 454 454 454 454 454 5 5 547 | 453 453 453 453 453 453 5 5 548 | 452 452 452 452 452 452 5 5 549 | 451 451 451 451 451 451 5 5 550 | 450 450 450 450 450 450 5 5 551 | 449 449 449 449 449 449 5 5 552 | 448 448 448 448 448 448 5 5 553 | 447 447 447 447 447 447 5 5 554 | 446 446 446 446 446 446 5 5 555 | 445 445 445 445 445 445 5 5 556 | 444 444 444 444 444 444 5 5 557 | 443 443 443 443 443 443 5 5 558 | 442 442 442 442 442 442 5 5 559 | 441 441 441 441 441 441 5 5 560 | 440 440 440 440 440 440 5 5 561 | 439 439 439 439 439 439 5 5 562 | 438 438 438 438 438 438 5 5 563 | 437 437 437 437 437 437 5 5 564 | 436 436 436 436 436 436 5 5 565 | 435 435 435 435 435 435 5 5 566 | 434 434 434 434 434 434 5 5 567 | 433 433 433 433 433 433 5 5 568 | 432 432 432 432 432 432 5 5 569 | 431 431 431 431 431 431 5 5 570 | 430 430 430 430 430 430 5 5 571 | 429 429 429 429 429 429 5 5 572 | 428 428 428 428 428 428 5 5 573 | 427 427 427 427 427 427 5 5 574 | 426 426 426 426 426 426 5 5 575 | 425 425 425 425 425 425 5 5 576 | 424 424 424 424 424 424 5 5 577 | 423 423 423 423 423 423 5 5 578 | 422 422 422 422 422 422 5 5 579 | 421 421 421 421 421 421 5 5 580 | 420 420 420 420 420 420 5 5 581 | 419 419 419 419 419 419 5 5 582 | 418 418 418 418 418 418 5 5 583 | 417 417 417 417 417 417 5 5 584 | 416 416 416 416 416 416 5 5 585 | 415 415 415 415 415 415 5 5 586 | 414 414 414 414 414 414 5 5 587 | 413 413 413 413 413 413 5 5 588 | 412 412 412 412 412 412 5 5 589 | 411 411 411 411 411 411 5 5 590 | 410 410 410 410 410 410 5 5 591 | 409 409 409 409 409 409 5 5 592 | 408 408 408 408 408 408 5 5 593 | 407 407 407 407 407 407 5 5 594 | 406 406 406 406 406 406 5 5 595 | 405 405 405 405 405 405 5 5 596 | 404 404 404 404 404 404 5 5 597 | 403 403 403 403 403 403 5 5 598 | 402 402 402 402 402 402 5 5 599 | 401 401 401 401 401 401 5 5 600 | 400 400 400 400 400 400 5 5 601 | 399 399 399 399 399 399 5 5 602 | 398 398 398 398 398 398 5 5 603 | 397 397 397 397 397 397 5 5 604 | 396 396 396 396 396 396 5 5 605 | 395 395 395 395 395 395 5 5 606 | 394 394 394 394 394 394 5 5 607 | 393 393 393 393 393 393 5 5 608 | 392 392 392 392 392 392 5 5 609 | 391 391 391 391 391 391 5 5 610 | 390 390 390 390 390 390 5 5 611 | 389 389 389 389 389 389 5 5 612 | 388 388 388 388 388 388 5 5 613 | 387 387 387 387 387 387 5 5 614 | 386 386 386 386 386 386 5 5 615 | 385 385 385 385 385 385 5 5 616 | 384 384 384 384 384 384 5 5 617 | 383 383 383 383 383 383 5 5 618 | 382 382 382 382 382 382 5 5 619 | 381 381 381 381 381 381 5 5 620 | 380 380 380 380 380 380 5 5 621 | 379 379 379 379 379 379 5 5 622 | 378 378 378 378 378 378 5 5 623 | 377 377 377 377 377 377 5 5 624 | 376 376 376 376 376 376 5 5 625 | 375 375 375 375 375 375 5 5 626 | 374 374 374 374 374 374 5 5 627 | 373 373 373 373 373 373 5 5 628 | 372 372 372 372 372 372 5 5 629 | 371 371 371 371 371 371 5 5 630 | 370 370 370 370 370 370 5 5 631 | 369 369 369 369 369 369 5 5 632 | 368 368 368 368 368 368 5 5 633 | 367 367 367 367 367 367 5 5 634 | 366 366 366 366 366 366 5 5 635 | 365 365 365 365 365 365 5 5 636 | 364 364 364 364 364 364 5 5 637 | 363 363 363 363 363 363 5 5 638 | 362 362 362 362 362 362 5 5 639 | 361 361 361 361 361 361 5 5 640 | 360 360 360 360 360 360 5 5 641 | 359 359 359 359 359 359 5 5 642 | 358 358 358 358 358 358 5 5 643 | 357 357 357 357 357 357 5 5 644 | 356 356 356 356 356 356 5 5 645 | 355 355 355 355 355 355 5 5 646 | 354 354 354 354 354 354 5 5 647 | 353 353 353 353 353 353 5 5 648 | 352 352 352 352 352 352 5 5 649 | 351 351 351 351 351 351 5 5 650 | 350 350 350 350 350 350 5 5 651 | 349 349 349 349 349 349 5 5 652 | 348 348 348 348 348 348 5 5 653 | 347 347 347 347 347 347 5 5 654 | 346 346 346 346 346 346 5 5 655 | 345 345 345 345 345 345 5 5 656 | 344 344 344 344 344 344 5 5 657 | 343 343 343 343 343 343 5 5 658 | 342 342 342 342 342 342 5 5 659 | 341 341 341 341 341 341 5 5 660 | 340 340 340 340 340 340 5 5 661 | 339 339 339 339 339 339 5 5 662 | 338 338 338 338 338 338 5 5 663 | 337 337 337 337 337 337 5 5 664 | 336 336 336 336 336 336 5 5 665 | 335 335 335 335 335 335 5 5 666 | 334 334 334 334 334 334 5 5 667 | 333 333 333 333 333 333 5 5 668 | 332 332 332 332 332 332 5 5 669 | 331 331 331 331 331 331 5 5 670 | 330 330 330 330 330 330 5 5 671 | 329 329 329 329 329 329 5 5 672 | 328 328 328 328 328 328 5 5 673 | 327 327 327 327 327 327 5 5 674 | 326 326 326 326 326 326 5 5 675 | 325 325 325 325 325 325 5 5 676 | 324 324 324 324 324 324 5 5 677 | 323 323 323 323 323 323 5 5 678 | 322 322 322 322 322 322 5 5 679 | 321 321 321 321 321 321 5 5 680 | 320 320 320 320 320 320 5 5 681 | 319 319 319 319 319 319 5 5 682 | 318 318 318 318 318 318 5 5 683 | 317 317 317 317 317 317 5 5 684 | 316 316 316 316 316 316 5 5 685 | 315 315 315 315 315 315 5 5 686 | 314 314 314 314 314 314 5 5 687 | 313 313 313 313 313 313 5 5 688 | 312 312 312 312 312 312 5 5 689 | 311 311 311 311 311 311 5 5 690 | 310 310 310 310 310 310 5 5 691 | 309 309 309 309 309 309 5 5 692 | 308 308 308 308 308 308 5 5 693 | 307 307 307 307 307 307 5 5 694 | 306 306 306 306 306 306 5 5 695 | 305 305 305 305 305 305 5 5 696 | 304 304 304 304 304 304 5 5 697 | 303 303 303 303 303 303 5 5 698 | 302 302 302 302 302 302 5 5 699 | 301 301 301 301 301 301 5 5 700 | 300 300 300 300 300 300 5 5 701 | 299 299 299 299 299 299 5 5 702 | 298 298 298 298 298 298 5 5 703 | 297 297 297 297 297 297 5 5 704 | 296 296 296 296 296 296 5 5 705 | 295 295 295 295 295 295 5 5 706 | 294 294 294 294 294 294 5 5 707 | 293 293 293 293 293 293 5 5 708 | 292 292 292 292 292 292 5 5 709 | 291 291 291 291 291 291 5 5 710 | 290 290 290 290 290 290 5 5 711 | 289 289 289 289 289 289 5 5 712 | 288 288 288 288 288 288 5 5 713 | 287 287 287 287 287 287 5 5 714 | 286 286 286 286 286 286 5 5 715 | 285 285 285 285 285 285 5 5 716 | 284 284 284 284 284 284 5 5 717 | 283 283 283 283 283 283 5 5 718 | 282 282 282 282 282 282 5 5 719 | 281 281 281 281 281 281 5 5 720 | 280 280 280 280 280 280 5 5 721 | 279 279 279 279 279 279 5 5 722 | 278 278 278 278 278 278 5 5 723 | 277 277 277 277 277 277 5 5 724 | 276 276 276 276 276 276 5 5 725 | 275 275 275 275 275 275 5 5 726 | 274 274 274 274 274 274 5 5 727 | 273 273 273 273 273 273 5 5 728 | 272 272 272 272 272 272 5 5 729 | 271 271 271 271 271 271 5 5 730 | 270 270 270 270 270 270 5 5 731 | 269 269 269 269 269 269 5 5 732 | 268 268 268 268 268 268 5 5 733 | 267 267 267 267 267 267 5 5 734 | 266 266 266 266 266 266 5 5 735 | 265 265 265 265 265 265 5 5 736 | 264 264 264 264 264 264 5 5 737 | 263 263 263 263 263 263 5 5 738 | 262 262 262 262 262 262 5 5 739 | 261 261 261 261 261 261 5 5 740 | 260 260 260 260 260 260 5 5 741 | 259 259 259 259 259 259 5 5 742 | 258 258 258 258 258 258 5 5 743 | 257 257 257 257 257 257 5 5 744 | 256 256 256 256 256 256 5 5 745 | 255 255 255 255 255 255 5 5 746 | 254 254 254 254 254 254 5 5 747 | 253 253 253 253 253 253 5 5 748 | 252 252 252 252 252 252 5 5 749 | 251 251 251 251 251 251 5 5 750 | 250 250 250 250 250 250 5 5 751 | 249 249 249 249 249 249 5 5 752 | 248 248 248 248 248 248 5 5 753 | 247 247 247 247 247 247 5 5 754 | 246 246 246 246 246 246 5 5 755 | 245 245 245 245 245 245 5 5 756 | 244 244 244 244 244 244 5 5 757 | 243 243 243 243 243 243 5 5 758 | 242 242 242 242 242 242 5 5 759 | 241 241 241 241 241 241 5 5 760 | 240 240 240 240 240 240 5 5 761 | 239 239 239 239 239 239 5 5 762 | 238 238 238 238 238 238 5 5 763 | 237 237 237 237 237 237 5 5 764 | 236 236 236 236 236 236 5 5 765 | 235 235 235 235 235 235 5 5 766 | 234 234 234 234 234 234 5 5 767 | 233 233 233 233 233 233 5 5 768 | 232 232 232 232 232 232 5 5 769 | 231 231 231 231 231 231 5 5 770 | 230 230 230 230 230 230 5 5 771 | 229 229 229 229 229 229 5 5 772 | 228 228 228 228 228 228 5 5 773 | 227 227 227 227 227 227 5 5 774 | 226 226 226 226 226 226 5 5 775 | 225 225 225 225 225 225 5 5 776 | 224 224 224 224 224 224 5 5 777 | 223 223 223 223 223 223 5 5 778 | 222 222 222 222 222 222 5 5 779 | 221 221 221 221 221 221 5 5 780 | 220 220 220 220 220 220 5 5 781 | 219 219 219 219 219 219 5 5 782 | 218 218 218 218 218 218 5 5 783 | 217 217 217 217 217 217 5 5 784 | 216 216 216 216 216 216 5 5 785 | 215 215 215 215 215 215 5 5 786 | 214 214 214 214 214 214 5 5 787 | 213 213 213 213 213 213 5 5 788 | 212 212 212 212 212 212 5 5 789 | 211 211 211 211 211 211 5 5 790 | 210 210 210 210 210 210 5 5 791 | 209 209 209 209 209 209 5 5 792 | 208 208 208 208 208 208 5 5 793 | 207 207 207 207 207 207 5 5 794 | 206 206 206 206 206 206 5 5 795 | 205 205 205 205 205 205 5 5 796 | 204 204 204 204 204 204 5 5 797 | 203 203 203 203 203 203 5 5 798 | 202 202 202 202 202 202 5 5 799 | 201 201 201 201 201 201 5 5 800 | 200 200 200 200 200 200 5 5 801 | 199 199 199 199 199 199 5 5 802 | 198 198 198 198 198 198 5 5 803 | 197 197 197 197 197 197 5 5 804 | 196 196 196 196 196 196 5 5 805 | 195 195 195 195 195 195 5 5 806 | 194 194 194 194 194 194 5 5 807 | 193 193 193 193 193 193 5 5 808 | 192 192 192 192 192 192 5 5 809 | 191 191 191 191 191 191 5 5 810 | 190 190 190 190 190 190 5 5 811 | 189 189 189 189 189 189 5 5 812 | 188 188 188 188 188 188 5 5 813 | 187 187 187 187 187 187 5 5 814 | 186 186 186 186 186 186 5 5 815 | 185 185 185 185 185 185 5 5 816 | 184 184 184 184 184 184 5 5 817 | 183 183 183 183 183 183 5 5 818 | 182 182 182 182 182 182 5 5 819 | 181 181 181 181 181 181 5 5 820 | 180 180 180 180 180 180 5 5 821 | 179 179 179 179 179 179 5 5 822 | 178 178 178 178 178 178 5 5 823 | 177 177 177 177 177 177 5 5 824 | 176 176 176 176 176 176 5 5 825 | 175 175 175 175 175 175 5 5 826 | 174 174 174 174 174 174 5 5 827 | 173 173 173 173 173 173 5 5 828 | 172 172 172 172 172 172 5 5 829 | 171 171 171 171 171 171 5 5 830 | 170 170 170 170 170 170 5 5 831 | 169 169 169 169 169 169 5 5 832 | 168 168 168 168 168 168 5 5 833 | 167 167 167 167 167 167 5 5 834 | 166 166 166 166 166 166 5 5 835 | 165 165 165 165 165 165 5 5 836 | 164 164 164 164 164 164 5 5 837 | 163 163 163 163 163 163 5 5 838 | 162 162 162 162 162 162 5 5 839 | 161 161 161 161 161 161 5 5 840 | 160 160 160 160 160 160 5 5 841 | 159 159 159 159 159 159 5 5 842 | 158 158 158 158 158 158 5 5 843 | 157 157 157 157 157 157 5 5 844 | 156 156 156 156 156 156 5 5 845 | 155 155 155 155 155 155 5 5 846 | 154 154 154 154 154 154 5 5 847 | 153 153 153 153 153 153 5 5 848 | 152 152 152 152 152 152 5 5 849 | 151 151 151 151 151 151 5 5 850 | 150 150 150 150 150 150 5 5 851 | 149 149 149 149 149 149 5 5 852 | 148 148 148 148 148 148 5 5 853 | 147 147 147 147 147 147 5 5 854 | 146 146 146 146 146 146 5 5 855 | 145 145 145 145 145 145 5 5 856 | 144 144 144 144 144 144 5 5 857 | 143 143 143 143 143 143 5 5 858 | 142 142 142 142 142 142 5 5 859 | 141 141 141 141 141 141 5 5 860 | 140 140 140 140 140 140 5 5 861 | 139 139 139 139 139 139 5 5 862 | 138 138 138 138 138 138 5 5 863 | 137 137 137 137 137 137 5 5 864 | 136 136 136 136 136 136 5 5 865 | 135 135 135 135 135 135 5 5 866 | 134 134 134 134 134 134 5 5 867 | 133 133 133 133 133 133 5 5 868 | 132 132 132 132 132 132 5 5 869 | 131 131 131 131 131 131 5 5 870 | 130 130 130 130 130 130 5 5 871 | 129 129 129 129 129 129 5 5 872 | 128 128 128 128 128 128 5 5 873 | 127 127 127 127 127 127 5 5 874 | 126 126 126 126 126 126 5 5 875 | 125 125 125 125 125 125 5 5 876 | 124 124 124 124 124 124 5 5 877 | 123 123 123 123 123 123 5 5 878 | 122 122 122 122 122 122 5 5 879 | 121 121 121 121 121 121 5 5 880 | 120 120 120 120 120 120 5 5 881 | 119 119 119 119 119 119 5 5 882 | 118 118 118 118 118 118 5 5 883 | 117 117 117 117 117 117 5 5 884 | 116 116 116 116 116 116 5 5 885 | 115 115 115 115 115 115 5 5 886 | 114 114 114 114 114 114 5 5 887 | 113 113 113 113 113 113 5 5 888 | 112 112 112 112 112 112 5 5 889 | 111 111 111 111 111 111 5 5 890 | 110 110 110 110 110 110 5 5 891 | 109 109 109 109 109 109 5 5 892 | 108 108 108 108 108 108 5 5 893 | 107 107 107 107 107 107 5 5 894 | 106 106 106 106 106 106 5 5 895 | 105 105 105 105 105 105 5 5 896 | 104 104 104 104 104 104 5 5 897 | 103 103 103 103 103 103 5 5 898 | 102 102 102 102 102 102 5 5 899 | 101 101 101 101 101 101 5 5 900 | 100 100 100 100 100 100 5 5 901 | 99 99 99 99 99 99 5 5 902 | 98 98 98 98 98 98 5 5 903 | 97 97 97 97 97 97 5 5 904 | 96 96 96 96 96 96 5 5 905 | 95 95 95 95 95 95 5 5 906 | 94 94 94 94 94 94 5 5 907 | 93 93 93 93 93 93 5 5 908 | 92 92 92 92 92 92 5 5 909 | 91 91 91 91 91 91 5 5 910 | 90 90 90 90 90 90 5 5 911 | 89 89 89 89 89 89 5 5 912 | 88 88 88 88 88 88 5 5 913 | 87 87 87 87 87 87 5 5 914 | 86 86 86 86 86 86 5 5 915 | 85 85 85 85 85 85 5 5 916 | 84 84 84 84 84 84 5 5 917 | 83 83 83 83 83 83 5 5 918 | 82 82 82 82 82 82 5 5 919 | 81 81 81 81 81 81 5 5 920 | 80 80 80 80 80 80 5 5 921 | 79 79 79 79 79 79 5 5 922 | 78 78 78 78 78 78 5 5 923 | 77 77 77 77 77 77 5 5 924 | 76 76 76 76 76 76 5 5 925 | 75 75 75 75 75 75 5 5 926 | 74 74 74 74 74 74 5 5 927 | 73 73 73 73 73 73 5 5 928 | 72 72 72 72 72 72 5 5 929 | 71 71 71 71 71 71 5 5 930 | 70 70 70 70 70 70 5 5 931 | 69 69 69 69 69 69 5 5 932 | 68 68 68 68 68 68 5 5 933 | 67 67 67 67 67 67 5 5 934 | 66 66 66 66 66 66 5 5 935 | 65 65 65 65 65 65 5 5 936 | 64 64 64 64 64 64 5 5 937 | 63 63 63 63 63 63 5 5 938 | 62 62 62 62 62 62 5 5 939 | 61 61 61 61 61 61 5 5 940 | 60 60 60 60 60 60 5 5 941 | 59 59 59 59 59 59 5 5 942 | 58 58 58 58 58 58 5 5 943 | 57 57 57 57 57 57 5 5 944 | 56 56 56 56 56 56 5 5 945 | 55 55 55 55 55 55 5 5 946 | 54 54 54 54 54 54 5 5 947 | 53 53 53 53 53 53 5 5 948 | 52 52 52 52 52 52 5 5 949 | 51 51 51 51 51 51 5 5 950 | 50 50 50 50 50 50 5 5 951 | 49 49 49 49 49 49 5 5 952 | 48 48 48 48 48 48 5 5 953 | 47 47 47 47 47 47 5 5 954 | 46 46 46 46 46 46 5 5 955 | 45 45 45 45 45 45 5 5 956 | 44 44 44 44 44 44 5 5 957 | 43 43 43 43 43 43 5 5 958 | 42 42 42 42 42 42 5 5 959 | 41 41 41 41 41 41 5 5 960 | 40 40 40 40 40 40 5 5 961 | 39 39 39 39 39 39 5 5 962 | 38 38 38 38 38 38 5 5 963 | 37 37 37 37 37 37 5 5 964 | 36 36 36 36 36 36 5 5 965 | 35 35 35 35 35 35 5 5 966 | 34 34 34 34 34 34 5 5 967 | 33 33 33 33 33 33 5 5 968 | 32 32 32 32 32 32 5 5 969 | 31 31 31 31 31 31 5 5 970 | 30 30 30 30 30 30 5 5 971 | 29 29 29 29 29 29 5 5 972 | 28 28 28 28 28 28 5 5 973 | 27 27 27 27 27 27 5 5 974 | 26 26 26 26 26 26 5 5 975 | 25 25 25 25 25 25 5 5 976 | 24 24 24 24 24 24 5 5 977 | 23 23 23 23 23 23 5 5 978 | 22 22 22 22 22 22 5 5 979 | 21 21 21 21 21 21 5 5 980 | 20 20 20 20 20 20 5 5 981 | 19 19 19 19 19 19 5 5 982 | 18 18 18 18 18 18 5 5 983 | 17 17 17 17 17 17 5 5 984 | 16 16 16 16 16 16 5 5 985 | 15 15 15 15 15 15 5 5 986 | 14 14 14 14 14 14 5 5 987 | 13 13 13 13 13 13 5 5 988 | 12 12 12 12 12 12 5 5 989 | 11 11 11 11 11 11 5 5 990 | 10 10 10 10 10 10 5 5 991 | 9 9 9 9 9 9 5 5 992 | 8 8 8 8 8 8 5 5 993 | 7 7 7 7 7 7 5 5 994 | 6 6 6 6 6 6 5 5 995 | 5 5 5 5 5 5 5 5 996 | 4 4 4 4 4 4 5 5 997 | 3 3 3 3 3 3 5 5 998 | 2 2 2 2 2 2 5 5 999 | 1 1 1 1 1 1 5 5 1000 | 0 0 0 0 0 0 5 5 1001 | -------------------------------------------------------------------------------- /bigbang/LICENSE.md: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . --------------------------------------------------------------------------------