astroimsim-geometry 0.1.12

Geometry package for astroimsim
Documentation
use std::ops::{Add, Mul};
use plotpy::{Curve, Plot};
use serde::Serialize;
use crate::coordinate_system::{Coordinates};

#[derive(Clone, Debug,Serialize)]
pub struct Point{
    pub x: f64,
    pub y: f64,
    pub coordinates: Coordinates
}

impl Point{
    pub fn new(x:f64,y:f64,coordinates: Coordinates) -> Point{
        Point{x,y,coordinates}
    }
    pub fn to_absolute(&self) -> Point{
        match &self.coordinates{
            Coordinates::ABSOLUTE => {
                //println!("already in absolute");
                self.clone()}
            Coordinates::RELATIVE(coordinate_system) => {
                let absolute_x =  self.x * coordinate_system.x_axis.0 + self.y *coordinate_system.y_axis.0;
                let absolute_y = self.x * coordinate_system.x_axis.1 + self.y * coordinate_system.y_axis.1;
                Point::new(absolute_x,absolute_y,Coordinates::ABSOLUTE)
            }
        }
    }
    pub fn convert(&self, coordinate_system: &Coordinates) -> Point{
        let absolute = self.to_absolute();
        match coordinate_system{
            Coordinates::ABSOLUTE => { absolute }
            Coordinates::RELATIVE(coordinate_system  ) => {
                coordinate_system.point_from_absolute(absolute)
            }
        }
    }
    pub fn values(&self)-> (f64,f64){
        (self.x,self.y)
    }

    pub fn plot(&self, plot:&mut Plot,color:&str){

        let mut point = Curve::new();
        point.set_line_style("none")
            .set_marker_color(color)
            .set_marker_every(1)
            .set_marker_size(7.0)
            .set_marker_style("*");
        point.points_begin();
        let (x,y) = self.to_absolute().values();
        point.points_add(x,y);
        point.points_end();
        plot.add(&point);






    }
}


impl Add for Point{
    type Output = Point;
    fn add(self, rhs: Point) -> Self::Output {

        Point{
            x: self.to_absolute().x + rhs.to_absolute().x,
            y: self.to_absolute().y + rhs.to_absolute().y,
            coordinates:Coordinates::ABSOLUTE

        }
    }
}