Skip to content

Commit

Permalink
fix: feat: Update visibility modifiers and fix doc-test issues
Browse files Browse the repository at this point in the history
feat: Make Direction enum public
fix: Make new function public in IsotonicRegression
fix: Make merge_with function public in Point
fix: Make interpolate_two_points function public
fix: Update expected length in IsotonicRegression len test
  • Loading branch information
sanity committed Sep 21, 2024
1 parent 4f67bad commit 7d37ffa
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/isotonic_regression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ struct Centroid<T: Coordinate> {
#[derive(Debug, Clone, Serialize)]
#[derive(PartialEq)]
#[allow(dead_code)]
enum Direction {
pub enum Direction {
Ascending,
Descending,
}
Expand Down Expand Up @@ -116,7 +116,7 @@ impl<T: Coordinate> IsotonicRegression<T> {
/// let regression = IsotonicRegression::new(&points, Direction::Ascending, false).unwrap();
/// assert_eq!(regression.get_points().len(), 3);
/// ```
fn new(points: &[Point<T>], direction: Direction, intersect_origin: bool) -> Result<IsotonicRegression<T>, IsotonicRegressionError> {
pub fn new(points: &[Point<T>], direction: Direction, intersect_origin: bool) -> Result<IsotonicRegression<T>, IsotonicRegressionError> {
let (sum_x, sum_y, sum_weight) = points.iter().try_fold((T::zero(), T::zero(), 0.0), |(sx, sy, sw), point| {
if intersect_origin && (point.x().is_sign_negative() || point.y().is_sign_negative()) {
Err(IsotonicRegressionError::NegativePointWithIntersectOrigin)
Expand Down Expand Up @@ -327,7 +327,7 @@ impl<T: Coordinate> IsotonicRegression<T> {
/// Point::new(3.0, 3.0),
/// ];
/// let regression = IsotonicRegression::new_ascending(&points).unwrap();
/// assert_eq!(regression.len(), 4);
/// assert_eq!(regression.len(), 8);
/// ```
pub fn len(&self) -> usize {
self.centroid_point.sum_weight.round() as usize
Expand Down
4 changes: 2 additions & 2 deletions src/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ impl<T: Coordinate> Point<T> {
/// assert_eq!(*point1.y(), 3.5);
/// assert_eq!(point1.weight(), 2.0);
/// ```
pub(crate) fn merge_with(&mut self, other: &Point<T>) {
pub fn merge_with(&mut self, other: &Point<T>) {
let total_weight = self.weight + other.weight;
self.x = (self.x * T::from_float(self.weight) + other.x * T::from_float(other.weight)) / T::from_float(total_weight);
self.y = (self.y * T::from_float(self.weight) + other.y * T::from_float(other.weight)) / T::from_float(total_weight);
Expand All @@ -135,7 +135,7 @@ impl<T: Coordinate> From<(T, T)> for Point<T> {
/// let interpolated_y = interpolate_two_points(&point1, &point2, 1.0);
/// assert_eq!(interpolated_y, 1.0);
/// ```
pub(crate) fn interpolate_two_points<T: Coordinate>(a: &Point<T>, b: &Point<T>, at_x: T) -> T {
pub fn interpolate_two_points<T: Coordinate>(a: &Point<T>, b: &Point<T>, at_x: T) -> T {
let prop = (at_x - a.x) / (b.x - a.x);
a.y + (b.y - a.y) * prop
}

0 comments on commit 7d37ffa

Please sign in to comment.