1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//mod crate::coordinates::gen_coordinate;
//mod crate::gen_coordinate;
//use src::gen_coordinate;
//use crate::gen_coordinate::coordinate;


use super::gen_coordinate::CoordinateBasics;
use super::gen_coordinate::MutableCoordinate;


pub struct UnsafeCoordinate{
    x: f32,
    y: f32
}
impl CoordinateBasics<f32> for UnsafeCoordinate {
    fn new (x: f32, y: f32) -> UnsafeCoordinate{return UnsafeCoordinate{x:x,y:y};}
    fn get_x(&self) -> f32 { self.x }
    fn get_y(&self) -> f32 { self.y }
    fn destroy(&self) ->() {drop(self)}

}



impl MutableCoordinate<f32> for UnsafeCoordinate {
    
    fn negative(&mut self)-> (){
        self.x = -self.x;
        self.y = -self.y;
    }
    fn add(&mut self, altcoordinate: &Self) {
        self.x+=altcoordinate.x;
        self.y+=altcoordinate.y;
    }
    fn sub(&mut self, altcoordinate: &Self) -> () {
        self.x-=altcoordinate.x;
        self.y-=altcoordinate.y;
    }
    fn product(&mut self, altcoordinate: &Self) -> () {
        self.x*=altcoordinate.x;
        self.y*=altcoordinate.y;
    }
    
    fn true_div(&mut self, altcoordinate: &Self) -> () {
        self.x*=altcoordinate.x;
        self.y*=-altcoordinate.y;
    }
    fn set_x(&mut self, x: f32) -> () {
        self.x = x;
    }
    fn set_y(&mut self, y: f32) -> () {
        self.y= y;
    }
}

/*
impl OpCoordinates<f32> for UnsafeCoordinate{
    fn distancia(&self, otro: &UnsafeCoordinate) -> f32 {
        let difx:f32 = self.x - otro.x;
        let dify:f32= self.y - otro.y;
        (difx.powi(2) + dify.powi(2)).sqrt()
    }
    fn equal(&self, altcoordinate: &Self) -> bool {
        return self.x == altcoordinate.x && self.y== altcoordinate.y;
    }
    fn equiv(&self, altcoordinate: &Self) -> bool {
        let x:f32;
        let y:f32;
        if altcoordinate.x!=0.0 {
            x = self.x/altcoordinate.x;
        }
        else if self.x!=0.0 {
            x = altcoordinate.x/self.x;
        }
        else {
            x=0.0;
        }
        if altcoordinate.y!=0.0 {
            y= self.y/altcoordinate.y;
        }
        else if self.y!=0.0 {
            y = altcoordinate.y/self.y;
        }
        else {
            y=0.0;
         }

        return x==y;
    }
}

#[test]
fn test_safe_coordinate_operations() {
    let var_x1:f32=14.0;
    let var_y1:f32=20.0;
    let var_x2:f32=-13.0;
    let var_y2:f32=12.0;
    //En los tests no se ponen los tipos
    let coord1 :UnsafeCoordinate=UnsafeCoordinate::new(var_x1,var_y1);
    let coord2 :UnsafeCoordinate=UnsafeCoordinate::new(var_x2,var_y2);
    let distancia: f32=coord1.distancia(&coord2);
    let ne:bool=coord1.equal(&coord2);
    let eq:bool=coord1.equal(&coord1);
    let c_mod:bool=coord1.equiv(&coord2);
    let c_mod_reg:bool=coord1.equiv(&coord1);

    assert_eq!(28.160255, distancia);
    assert_eq!(false,ne);
    assert_eq!(true,eq);
    assert_eq!(false,c_mod);
    assert_eq!(true,c_mod_reg);
    


}*/

#[test]
fn test_unsafe_coordinate_basics() {
    //En los tests no se ponen los tipos
    let coord :UnsafeCoordinate=UnsafeCoordinate::new(1.0,2.0);
    assert_eq!(1.0, coord.get_x());
    assert_eq!(2.0, coord.get_y());
    coord.destroy();
}
#[test]
fn test_unsafe_coordinate_core() {
    let var_x: f32 = 1.0;
    let var_y: f32 = 2.0;
    let coordb: UnsafeCoordinate = UnsafeCoordinate::new(var_x, var_y);
    let mut coord: UnsafeCoordinate = UnsafeCoordinate::new(var_x, var_y);
    coord.negative();
    assert_eq!(-var_x, coord.get_x());
    assert_eq!(-var_y, coord.get_y());

    let mut coord: UnsafeCoordinate = UnsafeCoordinate::new(var_x, var_y);
    coord.add(&coordb);
    assert_eq!(2.0 * var_x, coord.get_x());
    assert_eq!(2.0 * var_y, coord.get_y());

    let mut coord: UnsafeCoordinate = UnsafeCoordinate::new(var_x, var_y);
    coord.sub(&coordb);
    assert_eq!(0.0, coord.get_x());
    assert_eq!(0.0, coord.get_y());

    coord.sub(&coordb);
    assert_eq!(-var_x, coord.get_x());
    assert_eq!(-var_y, coord.get_y());

    coord.set_x(var_x);
    coord.set_y(var_y);
    coord.product(&coordb);
    assert_eq!(var_x * var_x, coord.get_x());
    assert_eq!(var_y * var_y, coord.get_y());

    coord.set_x(var_x);
    coord.set_y(var_y);
    coord.true_div(&coordb);
    assert_eq!(var_x*var_x, coord.get_x());
    assert_eq!(var_y*(-var_y), coord.get_y());

    coord.destroy();
    coordb.destroy();
}

#[test]
fn test_unsafe_coordinate_core2() {
    let var_x: f32 = 54.0;
    let var_y: f32 = -32.0;
    let coordb: UnsafeCoordinate = UnsafeCoordinate::new(var_x, var_y);
    let mut coord: UnsafeCoordinate = UnsafeCoordinate::new(var_x, var_y);
    coord.negative();
    assert_eq!(-var_x, coord.get_x());
    assert_eq!(-var_y, coord.get_y());

    let mut coord: UnsafeCoordinate = UnsafeCoordinate::new(var_x, var_y);
    coord.add(&coordb);
    assert_eq!(2.0 * var_x, coord.get_x());
    assert_eq!(2.0 * var_y, coord.get_y());

    let mut coord: UnsafeCoordinate = UnsafeCoordinate::new(var_x, var_y);
    coord.sub(&coordb);
    assert_eq!(0.0, coord.get_x());
    assert_eq!(0.0, coord.get_y());

    coord.sub(&coordb);
    assert_eq!(-var_x, coord.get_x());
    assert_eq!(-var_y, coord.get_y());

    coord.set_x(var_x);
    coord.set_y(var_y);
    coord.product(&coordb);
    assert_eq!(var_x * var_x, coord.get_x());
    assert_eq!(var_y * var_y, coord.get_y());

    coord.set_x(var_x);
    coord.set_y(var_y);
    coord.true_div(&coordb);
    assert_eq!(var_x*var_x, coord.get_x());
    assert_eq!(var_y*(-var_y), coord.get_y());

    coord.destroy();
    coordb.destroy();
}