Привет, ребята, я новичок в C ++. У меня есть следующая функция в C ++, но она всегда выдает ошибку из-за функции "двойного перекрытия", и я не знаю почему. Может кто-нибудь сказать мне, что я делаю не так?
double overlap(vector<double> &R1, vector<double> &R2) {
// overlap in the x dimension
double xmin = max(R1[0], R2[0]);
double xmax = min(R1[2], R2[2]);
if (xmin >= xmax) return 0;
// overlap in the y dimension
double ymin = max(R1[1], R2[1]);
double ymax = min(R1[3], R2[3]);
if (ymin >= ymax) return 0;
double overlap_area = (xmax-xmin)*(ymax-ymin)
return overlap_area;
}
int main() {
vector<int> R1;
vector<int> R2;
// Coordinates of the rectangles
// with the .push_back() function we are adding the rectangles to our vector to give it to the algorithm.
// x: x-coordinate, y: y-coordinate, w: weidth, h: height - (w,h: distance from left/botton to right/top side of the rectangle)
int x1 = 0, y1 = 0, w1 = 6, h1 = 9;
R1.push_back(x1);
R1.push_back(y1);
R1.push_back(w1);
R1.push_back(h1);
int x2 = 3, y2 = 4, w2 = 3, h2 = 3;
R2.push_back(x2);
R2.push_back(y2);
R2.push_back(w2);
R2.push_back(h2);
cout << "Overlap = " << overlap(R1, R2) << endl;
}