teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

2

文言修正

2020/07/03 19:01

投稿

SHOMI
SHOMI

スコア4079

answer CHANGED
@@ -37,7 +37,7 @@
37
37
  //Rectangleに対する出力用の演算子
38
38
  std::ostream& operator<<(std::ostream& out, Rectangle r)
39
39
  {
40
- out << "左辺のx座標" << r.lx->x << " 右辺のx座標" << r.rx->x << "下辺のx座標" << r.dy->y << "上辺のx座標" << r.uy->y;
40
+ out << "左辺のx座標" << r.lx->x << " 右辺のx座標" << r.rx->x << "下辺のy座標" << r.dy->y << "上辺のy座標" << r.uy->y;
41
41
  return out;
42
42
  }
43
43
 

1

コード追記

2020/07/03 19:01

投稿

SHOMI
SHOMI

スコア4079

answer CHANGED
@@ -17,4 +17,38 @@
17
17
  + it.uy=std::max_element(points.begin(),points.end(),compare_y)->y; //上辺のy座標
18
18
  return it;
19
19
  }
20
+ ```
21
+
22
+ ---
23
+
24
+ > 反復子itを長方形のメンバとしたい
25
+
26
+ `Rectangle`のメンバを`std::vector<Point>::iterator`にしたいということでしょうか?
27
+ x,y両方へアクセスできるのでバグの原因となりそうですが…
28
+ ```C++
29
+ struct Rectangle
30
+ {
31
+ std::vector<Point>::iterator lx;
32
+ std::vector<Point>::iterator rx;
33
+ std::vector<Point>::iterator dy;
34
+ std::vector<Point>::iterator uy;
35
+ };
36
+
37
+ //Rectangleに対する出力用の演算子
38
+ std::ostream& operator<<(std::ostream& out, Rectangle r)
39
+ {
40
+ out << "左辺のx座標" << r.lx->x << " 右辺のx座標" << r.rx->x << "下辺のx座標" << r.dy->y << "上辺のx座標" << r.uy->y;
41
+ return out;
42
+ }
43
+
44
+ //点集合の包囲長方形を計算する関数
45
+ Rectangle bounding_rectangle(std::vector<Point>& points)
46
+ {
47
+ Rectangle it;
48
+ it.lx = std::min_element(points.begin(), points.end(), compare_x); //左辺のx座標
49
+ it.rx = std::max_element(points.begin(), points.end(), compare_x); //右辺のx座標
50
+ it.dy = std::min_element(points.begin(), points.end(), compare_y); //下辺のy座標
51
+ it.uy = std::max_element(points.begin(), points.end(), compare_y); //上辺のy座標
52
+ return it;
53
+ }
20
54
  ```