50 |
int i0, j0; |
int i0, j0; |
51 |
Pt box = t->getSqSize(); |
Pt box = t->getSqSize(); |
52 |
float x1=0, y1=0, x2=0, y2=0; |
float x1=0, y1=0, x2=0, y2=0; |
53 |
|
|
54 |
DBG(dbg_intersect) << "Find bb "<<t<<" "<<box<<"\n"; |
DBG(dbg_intersect) << "Find bb "<<t<<" "<<box<<"\n"; |
55 |
for (i0=0; i0<=1; i0+=1) { |
for (i0=0; i0<=1; i0+=1) { |
56 |
for (j0=0; j0<=1; j0+=1) { |
for (j0=0; j0<=1; j0+=1) { |
57 |
float i = i0 * box.x; |
float i = i0 * box.x; |
58 |
float j = j0 * box.x; |
float j = j0 * box.y; |
59 |
if (i==0 && j==0) { |
if (i==0 && j==0) { |
60 |
/** Initializing. */ |
/** Initializing. */ |
61 |
ZPt tmpPt = t->transform(ZPt(i, j, 0)); |
ZPt tmpPt = t->transform(ZPt(i, j, 0)); |
75 |
p2 = ZPt(x2, y2, 0); |
p2 = ZPt(x2, y2, 0); |
76 |
DBG(dbg_intersect) << "Return "<<p1<<" "<<p2<<"\n"; |
DBG(dbg_intersect) << "Return "<<p1<<" "<<p2<<"\n"; |
77 |
} |
} |
78 |
|
|
79 |
void findDistortedBoundingBox(const Transform *t, ZPt &p1, ZPt &p2) { |
void findDistortedBoundingBox(const Transform *t, ZPt &p1, ZPt &p2) { |
80 |
double i, step_x, step_y; |
double i, step_x, step_y; |
81 |
Pt box = t->getSqSize(); |
Pt box = t->getSqSize(); |
82 |
float x1, y1, x2, y2; |
float x1=0, y1=0, x2=0, y2=0; |
83 |
int check_dist; |
int check_dist; |
84 |
DBG(dbg_intersect) << "Find distortedbb "<<t<<" "<<box<<"\n"; |
DBG(dbg_intersect) << "Find distortedbb "<<t<<" "<<box<<"\n"; |
85 |
|
|
86 |
/** Initializing. */ |
if (box.x>0 && box.y>0) { // box area must be positive |
87 |
check_dist = 100; // XXX Adjusts the scanning frequency. |
/** Initializing. */ |
88 |
|
check_dist = 100; // XXX Adjusts the scanning frequency. |
89 |
|
|
90 |
ZPt o = t->transform(ZPt(0, 0, 0)); |
ZPt o = t->transform(ZPt(0, 0, 0)); |
91 |
ZPt u = t->transform(ZPt(box.x, box.y, 0)); |
ZPt u = t->transform(ZPt(box.x, box.y, 0)); |
92 |
|
|
93 |
if (fabs(o.x - u.x) / check_dist > box.x) |
if (fabs(o.x - u.x) / check_dist > box.x) |
94 |
step_x = box.x/(fabs(o.x - u.x) / check_dist); |
step_x = box.x/(fabs(o.x - u.x) / check_dist); |
95 |
else step_x = box.x; |
else step_x = box.x; |
96 |
if (fabs(o.y - u.y) / check_dist > box.y) |
if (fabs(o.y - u.y) / check_dist > box.y) |
97 |
step_y = box.y/(fabs(o.y - u.y) / check_dist); |
step_y = box.y/(fabs(o.y - u.y) / check_dist); |
98 |
else step_y = box.y; |
else step_y = box.y; |
99 |
|
|
100 |
x1 = u.x; y1 = u.y; |
x1 = u.x; y1 = u.y; |
101 |
x2 = u.x; y2 = u.y; |
x2 = u.x; y2 = u.y; |
102 |
|
|
103 |
/** Sweeps the box's vertices. */ |
/** Sweeps the box's vertices. */ |
104 |
/** Vertice (0,0) -> (w,0). */ |
/** Vertice (0,0) -> (w,0). */ |
105 |
for (i=0; i < box.x; i+=step_x) { |
for (i=0; i < box.x; i+=step_x) { |
106 |
ZPt tmpPt = t->transform(ZPt(i, 0, 0)); |
ZPt tmpPt = t->transform(ZPt(i, 0, 0)); |
107 |
if (tmpPt.x < x1) x1 = tmpPt.x; |
if (tmpPt.x < x1) x1 = tmpPt.x; |
108 |
else if (tmpPt.x > x2) x2 = tmpPt.x; |
else if (tmpPt.x > x2) x2 = tmpPt.x; |
109 |
if (tmpPt.y < y1) y1 = tmpPt.y; |
if (tmpPt.y < y1) y1 = tmpPt.y; |
110 |
else if (tmpPt.y > y2) y2 = tmpPt.y; |
else if (tmpPt.y > y2) y2 = tmpPt.y; |
111 |
} |
} |
112 |
|
|
113 |
/** Vertice (0,0) -> (0,h). */ |
/** Vertice (0,0) -> (0,h). */ |
114 |
for (i=step_y; i < box.y; i+=step_y) { |
for (i=step_y; i < box.y; i+=step_y) { |
115 |
ZPt tmpPt = t->transform(ZPt(0, i, 0)); |
ZPt tmpPt = t->transform(ZPt(0, i, 0)); |
116 |
if (tmpPt.x < x1) x1 = tmpPt.x; |
if (tmpPt.x < x1) x1 = tmpPt.x; |
117 |
else if (tmpPt.x > x2) x2 = tmpPt.x; |
else if (tmpPt.x > x2) x2 = tmpPt.x; |
118 |
if (tmpPt.y < y1) y1 = tmpPt.y; |
if (tmpPt.y < y1) y1 = tmpPt.y; |
119 |
else if (tmpPt.y > y2) y2 = tmpPt.y; |
else if (tmpPt.y > y2) y2 = tmpPt.y; |
120 |
} |
} |
121 |
|
|
122 |
/** Vertice (0,h) -> (w,h) */ |
/** Vertice (0,h) -> (w,h). */ |
123 |
for (i=0; i < box.x; i+=step_x) { |
for (i=0; i < box.x; i+=step_x) { |
124 |
ZPt tmpPt = t->transform(ZPt(i, box.y, 0)); |
ZPt tmpPt = t->transform(ZPt(i, box.y, 0)); |
125 |
if (tmpPt.x < x1) x1 = tmpPt.x; |
if (tmpPt.x < x1) x1 = tmpPt.x; |
126 |
else if (tmpPt.x > x2) x2 = tmpPt.x; |
else if (tmpPt.x > x2) x2 = tmpPt.x; |
127 |
if (tmpPt.y < y1) y1 = tmpPt.y; |
if (tmpPt.y < y1) y1 = tmpPt.y; |
128 |
else if (tmpPt.y > y2) y2 = tmpPt.y; |
else if (tmpPt.y > y2) y2 = tmpPt.y; |
129 |
} |
} |
130 |
|
|
131 |
/** Vertice (w,0) -> (w,h) */ |
/** Vertice (w,0) -> (w,h). */ |
132 |
for (i=0; i < box.y; i+=step_y) { |
for (i=0; i < box.y; i+=step_y) { |
133 |
ZPt tmpPt = t->transform(ZPt(box.x, i, 0)); |
ZPt tmpPt = t->transform(ZPt(box.x, i, 0)); |
134 |
if (tmpPt.x < x1) x1 = tmpPt.x; |
if (tmpPt.x < x1) x1 = tmpPt.x; |
135 |
else if (tmpPt.x > x2) x2 = tmpPt.x; |
else if (tmpPt.x > x2) x2 = tmpPt.x; |
136 |
if (tmpPt.y < y1) y1 = tmpPt.y; |
if (tmpPt.y < y1) y1 = tmpPt.y; |
137 |
else if (tmpPt.y > y2) y2 = tmpPt.y; |
else if (tmpPt.y > y2) y2 = tmpPt.y; |
138 |
|
} |
139 |
} |
} |
|
|
|
140 |
p1 = ZPt(x1, y1, 0); |
p1 = ZPt(x1, y1, 0); |
141 |
p2 = ZPt(x2, y2, 0); |
p2 = ZPt(x2, y2, 0); |
142 |
DBG(dbg_intersect) << "Return "<<p1<<" "<<p2<<"\n"; |
DBG(dbg_intersect) << "Return "<<p1<<" "<<p2<<"\n"; |