File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package DataMining_KDTree ;
2+
3+ /**
4+ * 空间矢量,表示所代表的空间范围
5+ *
6+ * @author lyq
7+ *
8+ */
9+ public class Range {
10+ // 边界左边界
11+ double left ;
12+ // 边界右边界
13+ double right ;
14+ // 边界上边界
15+ double top ;
16+ // 边界下边界
17+ double bottom ;
18+
19+ public Range () {
20+ this .left = -Integer .MAX_VALUE ;
21+ this .right = Integer .MAX_VALUE ;
22+ this .top = Integer .MAX_VALUE ;
23+ this .bottom = -Integer .MAX_VALUE ;
24+ }
25+
26+ public Range (int left , int right , int top , int bottom ) {
27+ this .left = left ;
28+ this .right = right ;
29+ this .top = top ;
30+ this .bottom = bottom ;
31+ }
32+
33+ /**
34+ * 空间矢量进行并操作
35+ *
36+ * @param range
37+ * @return
38+ */
39+ public Range crossOperation (Range r ) {
40+ Range range = new Range ();
41+
42+ // 取靠近右侧的左边界
43+ if (r .left > this .left ) {
44+ range .left = r .left ;
45+ } else {
46+ range .left = this .left ;
47+ }
48+
49+ // 取靠近左侧的右边界
50+ if (r .right < this .right ) {
51+ range .right = r .right ;
52+ } else {
53+ range .right = this .right ;
54+ }
55+
56+ // 取靠近下侧的上边界
57+ if (r .top < this .top ) {
58+ range .top = r .top ;
59+ } else {
60+ range .top = this .top ;
61+ }
62+
63+ // 取靠近上侧的下边界
64+ if (r .bottom > this .bottom ) {
65+ range .bottom = r .bottom ;
66+ } else {
67+ range .bottom = this .bottom ;
68+ }
69+
70+ return range ;
71+ }
72+
73+ /**
74+ * 根据坐标点分割方向确定左侧空间矢量
75+ *
76+ * @param p
77+ * 数据矢量
78+ * @param dir
79+ * 分割方向
80+ * @return
81+ */
82+ public static Range initLeftRange (Point p , int dir ) {
83+ Range range = new Range ();
84+
85+ if (dir == KDTreeTool .DIRECTION_X ) {
86+ range .right = p .x ;
87+ } else {
88+ range .bottom = p .y ;
89+ }
90+
91+ return range ;
92+ }
93+
94+ /**
95+ * 根据坐标点分割方向确定右侧空间矢量
96+ *
97+ * @param p
98+ * 数据矢量
99+ * @param dir
100+ * 分割方向
101+ * @return
102+ */
103+ public static Range initRightRange (Point p , int dir ) {
104+ Range range = new Range ();
105+
106+ if (dir == KDTreeTool .DIRECTION_X ) {
107+ range .left = p .x ;
108+ } else {
109+ range .top = p .y ;
110+ }
111+
112+ return range ;
113+ }
114+ }
You can’t perform that action at this time.
0 commit comments