Skip to content

Commit

Permalink
use pub(crate) to clean up docs, closes #37
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex committed Jan 23, 2020
1 parent fc95fca commit 189ae25
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/entity.rs
Expand Up @@ -78,7 +78,7 @@ impl PartialEq for Entity {
impl Entity {
/// Returns a velocity vector which represents the velocity of the particle after it has interacted
/// with the rest of the tree. Also returns a boolean representing whether or not a collision happened.
pub fn interact_with<'a, T: AsEntity + Clone>(
pub(crate) fn interact_with<'a, T: AsEntity + Clone>(
&'a self,
node: &'a Node<T>,
) -> SimulationResult<'a, T> {
Expand Down Expand Up @@ -120,7 +120,7 @@ impl Entity {
(x_dist, y_dist, z_dist)
}

pub fn get_dim(&self, dim: &Dimension) -> &f64 {
pub(crate) fn get_dim(&self, dim: &Dimension) -> &f64 {
match *dim {
Dimension::X => &self.x,
Dimension::Y => &self.y,
Expand Down Expand Up @@ -176,7 +176,7 @@ impl Entity {
/// acceleration from every entity in that node, but if we reach a node that is not a leaf and
/// exceeds_theta() is true, then we treat the node as one giant entity and get the
/// acceleration from it.
pub fn get_acceleration_and_collisions<'a, T: AsEntity + Clone>(
pub(crate) fn get_acceleration_and_collisions<'a, T: AsEntity + Clone>(
&'a self,
node: &'a Node<T>,
) -> SimulationResult<T> {
Expand Down
2 changes: 1 addition & 1 deletion src/grav_tree.rs
Expand Up @@ -12,7 +12,7 @@ pub struct GravTree<T: AsEntity + Clone> {
/// A GravTree consists of a root [[Node]]. A [[Node]] is a recursive binary tree data structure.
/// Tragically must be public for now for testing reasons. Perhaps could be replaced by various
/// getter methods later.
pub root: Node<T>,
pub(crate) root: Node<T>,
/// This is just the number of entities in the tree. This is used in testing to verify that no
/// entities are being dropped.
number_of_entities: usize,
Expand Down
24 changes: 12 additions & 12 deletions src/node.rs
Expand Up @@ -14,14 +14,14 @@ const MAX_PTS: i32 = 3;
///
/// If a [[Node]] is a leaf, then it contains up to `MAX_PTS` particles, as swell as the aggregate values of these particles.
/// These aggregate values are the center of mass, the total mass, and max/min values for each dimension.
pub struct Node<T: AsEntity + Clone> {
pub(crate) struct Node<T: AsEntity + Clone> {
split_dimension: Option<Dimension>, // Dimension that this node splits at.
split_value: f64, // Value that this node splits at.
pub left: Option<Box<Node<T>>>, // Left subtree.
pub right: Option<Box<Node<T>>>, // Right subtree.
pub points: Option<Vec<T>>, // Vector of the points if this node is a Leaf.
pub center_of_mass: (f64, f64, f64), /* The center of mass for this node and it's children all
* together. (x, y, z). */
pub(crate) left: Option<Box<Node<T>>>, // Left subtree.
pub(crate) right: Option<Box<Node<T>>>, // Right subtree.
pub(crate) points: Option<Vec<T>>, // Vector of the points if this node is a Leaf.
pub(crate) center_of_mass: (f64, f64, f64), /* The center of mass for this node and it's children all
* together. (x, y, z). */
total_mass: f64, // Total mass of all entities under this node.
r_max: f64, // Maximum radius that is a child of this node.
x_min: f64,
Expand All @@ -33,7 +33,7 @@ pub struct Node<T: AsEntity + Clone> {
}

impl<T: AsEntity + Clone> Node<T> {
pub fn new() -> Node<T> {
pub(crate) fn new() -> Node<T> {
Node {
split_dimension: None,
split_value: 0.0,
Expand All @@ -53,7 +53,7 @@ impl<T: AsEntity + Clone> Node<T> {
}
/// Looks into its own children's maximum and minimum values, setting its own
/// values accordingly.
pub fn set_max_mins(&mut self) {
pub(crate) fn set_max_mins(&mut self) {
let xmin = f64::min(
self.left.as_ref().unwrap().x_min,
self.right.as_ref().unwrap().x_min,
Expand Down Expand Up @@ -91,7 +91,7 @@ impl<T: AsEntity + Clone> Node<T> {
// Used when treating a node as the sum of its parts in gravity calculations.
/// Converts a node into an entity with the x, y, z, and mass being derived from the center of
/// mass and the total mass of the entities it contains.
pub fn as_entity(&self) -> Entity {
pub(crate) fn as_entity(&self) -> Entity {
// Construct a "super radius" of the largest dimension / 2 + a radius.
let (range_x, range_y, range_z) = (
self.x_max - self.x_min,
Expand All @@ -113,15 +113,15 @@ impl<T: AsEntity + Clone> Node<T> {
}
}

pub fn max_distance(&self) -> f64 {
pub(crate) fn max_distance(&self) -> f64 {
let x_distance = self.x_max - self.x_min;
let y_distance = self.y_max - self.y_min;
let z_distance = self.z_max - self.z_min;
f64::max(x_distance, f64::max(y_distance, z_distance))
}

/// Traverses tree and returns first child found with points.
pub fn traverse_tree_helper(&self) -> Vec<T> {
pub(crate) fn traverse_tree_helper(&self) -> Vec<T> {
let mut to_return: Vec<T> = Vec::new();
if let Some(node) = &self.left {
to_return.append(&mut node.traverse_tree_helper());
Expand All @@ -141,7 +141,7 @@ impl<T: AsEntity + Clone> Node<T> {
}

/// Takes in a mutable slice of entities and creates a recursive 3d tree structure.
pub fn new_root_node(pts: &[T]) -> Node<T> {
pub(crate) fn new_root_node(pts: &[T]) -> Node<T> {
// Start and end are probably 0 and pts.len(), respectively.
let length_of_points = pts.len() as i32;
let mut entities = pts.iter().map(|x| x.as_entity()).collect::<Vec<Entity>>();
Expand Down
8 changes: 4 additions & 4 deletions src/utilities.rs
Expand Up @@ -4,7 +4,7 @@ use crate::entity::Entity;
use std::cmp::Ordering;
/// Returns the absolute distance in every dimension (the range in every dimension)
/// of an array slice of entities.
pub fn xyz_distances(entities: &[Entity]) -> (f64, f64, f64) {
pub(crate) fn xyz_distances(entities: &[Entity]) -> (f64, f64, f64) {
let (x_max, x_min, y_max, y_min, z_max, z_min) = max_min_xyz(entities);
let x_distance = x_max - x_min;
let y_distance = y_max - y_min;
Expand All @@ -14,15 +14,15 @@ pub fn xyz_distances(entities: &[Entity]) -> (f64, f64, f64) {

/// Given an array slice of entities, returns the maximum and minimum x, y, and z values as
/// a septuple.
pub fn max_min_xyz(entities: &[Entity]) -> (&f64, &f64, &f64, &f64, &f64, &f64) {
pub(crate) fn max_min_xyz(entities: &[Entity]) -> (&f64, &f64, &f64, &f64, &f64, &f64) {
let (x_max, x_min) = max_min(Dimension::X, entities);
let (y_max, y_min) = max_min(Dimension::Y, entities);
let (z_max, z_min) = max_min(Dimension::Z, entities);
(x_max, x_min, y_max, y_min, z_max, z_min)
}

/// Returns the maximum and minimum values in a slice of entities, given a dimension.
pub fn max_min(dim: Dimension, entities: &[Entity]) -> (&f64, &f64) {
pub(crate) fn max_min(dim: Dimension, entities: &[Entity]) -> (&f64, &f64) {
(
entities
.iter()
Expand All @@ -47,7 +47,7 @@ pub fn max_min(dim: Dimension, entities: &[Entity]) -> (&f64, &f64) {

/// Finds the median value for a given dimension in a slice of entities.
/// Making one that clones/uses immutability could be an interesting performance benchmark.
pub fn find_median(dim: Dimension, pts: &mut [Entity]) -> (&f64, usize) {
pub(crate) fn find_median(dim: Dimension, pts: &mut [Entity]) -> (&f64, usize) {
find_median_helper(dim, pts, 0, pts.len(), pts.len() / 2usize)
}

Expand Down

0 comments on commit 189ae25

Please sign in to comment.