physdes/merge_obj.rs
1// use super::Vector2;
2use super::Point;
3use std::cmp;
4// use crate::generic::{Contain, Displacement, MinDist, Overlap};
5use crate::generic::MinDist;
6// #[cfg(any(test, feature = "std"))]
7// #[cfg(test)]
8// use core::hash;
9// use core::ops::{Add, Neg, Sub};
10// use num_traits::Num;
11// use std::cmp::Ordering;
12
13#[derive(PartialEq, Eq, Copy, Clone, Hash, Debug, Default)]
14pub struct MergeObj<T1, T2> {
15 impl_: Point<T1, T2>,
16}
17
18impl<T1, T2> MergeObj<T1, T2> {
19 pub fn new(xcoord: T1, ycoord: T2) -> MergeObj<T1, T2> {
20 MergeObj {
21 impl_: Point::new(xcoord, ycoord),
22 }
23 }
24
25 pub fn construct(xcoord: i32, ycoord: i32) -> MergeObj<i32, i32> {
26 let impl_ = Point::new(xcoord + ycoord, xcoord - ycoord);
27 MergeObj { impl_ }
28 }
29}
30
31impl<T1: MinDist<T1>, T2: MinDist<T2>> MergeObj<T1, T2> {
32 pub fn min_dist_with(&self, other: &MergeObj<T1, T2>) -> u32 {
33 cmp::max(
34 self.impl_.xcoord.min_dist_with(&other.impl_.xcoord),
35 self.impl_.ycoord.min_dist_with(&other.impl_.ycoord),
36 )
37 }
38
39 // fn enlarge_with(&self, alpha: i32) -> MergeObj<T1, T2> {
40 // let xcoord = enlarge(self.impl_.xcoord, alpha);
41 // let ycoord = enlarge(self.impl_.ycoord, alpha);
42 // MergeObj::new(xcoord, ycoord)
43 // }
44 //
45 // fn intersect_with(&self, other: &MergeObj<T1, T2>) -> MergeObj<T1, T2> {
46 // let point = self.impl_.intersect_with(&other.impl_);
47 // MergeObj::new(point.xcoord, point.ycoord)
48 // }
49 //
50 // fn merge_with(&self, other: &MergeObj<T1, T2>) -> MergeObj<T1, T2> {
51 // let alpha = self.min_dist_with(other);
52 // let half = alpha / 2;
53 // let trr1 = enlarge(&self.impl_, half);
54 // let trr2 = enlarge(&other.impl_, alpha - half);
55 // let impl_ = intersection(&trr1, &trr2);
56 // MergeObj::new(impl_.xcoord, impl_.ycoord)
57 // }
58}
59
60#[cfg(test)]
61mod test {
62 // #![allow(non_upper_case_globals)]
63
64 use super::*;
65 // use crate::generic::Overlap;
66 // use crate::interval::Interval;
67
68 // use core::i32;
69
70 #[test]
71 fn test_merge_obj() {
72 let r1 = MergeObj::<i32, i32>::construct(4, 5);
73 let r2 = MergeObj::<i32, i32>::construct(7, 9);
74
75 assert_ne!(r1, r2);
76 assert_eq!(r1.min_dist_with(&r2), 7);
77 // assert_eq!(min_dist(&r1, &r2), 7);
78 }
79
80 // #[test]
81 // fn test_merge() {
82 // let s1 = MergeObj::new(200 + 600, 200 - 600);
83 // let s2 = MergeObj::new(500 + 900, 500 - 900);
84 // let m1 = s1.merge_with(&s2);
85 // println!("{:?}", m1);
86 // assert_eq!(m1, MergeObj::new(Interval::new(1100, 1100), Interval::new(-700, -100)));
87 // }
88 //
89 // #[test]
90 // fn test_merge_2() {
91 // let mut a = MergeObj::new(4 + 5, 4 - 5);
92 // let b = MergeObj::new(7 + 9, 7 - 9);
93 // let v = Vector2(2, 3);
94 // a += &v;
95 // a -= &v;
96 // assert_eq!(a, MergeObj::new(4 + 5, 4 - 5));
97 // let r1 = a.enlarge_with(3);
98 // assert_eq!(r1, MergeObj::new(Interval::new(6, 12), Interval::new(-4, 2)));
99 // let r2 = b.enlarge_with(4);
100 // assert_eq!(r2, MergeObj::new(Interval::new(12, 20), Interval::new(-6, 2)));
101 // let r3 = r1.intersect_with(&r2);
102 // assert_eq!(r3, MergeObj::new(Interval::new(12, 12), Interval::new(-4, 2)));
103 // }
104}