mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-11-28 12:12:00 +03:00
make renderables return Bounds, not the aabb type
This commit is contained in:
parent
1050d86e67
commit
2c7e281a8e
@ -1,10 +1,9 @@
|
||||
use aabb_quadtree::geom::Rect;
|
||||
use colors::Colors;
|
||||
use ezgui::GfxCtx;
|
||||
use geom::{Polygon, Pt2D};
|
||||
use geom::{Bounds, Polygon, Pt2D};
|
||||
use map_model::{Area, AreaID, AreaType, Map};
|
||||
use objects::{Ctx, ID};
|
||||
use render::{get_bbox, RenderOptions, Renderable};
|
||||
use render::{RenderOptions, Renderable};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DrawArea {
|
||||
@ -39,8 +38,8 @@ impl Renderable for DrawArea {
|
||||
);
|
||||
}
|
||||
|
||||
fn get_bbox(&self) -> Rect {
|
||||
get_bbox(&self.fill_polygon.get_bounds())
|
||||
fn get_bounds(&self) -> Bounds {
|
||||
self.fill_polygon.get_bounds()
|
||||
}
|
||||
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
|
@ -1,12 +1,11 @@
|
||||
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
use aabb_quadtree::geom::Rect;
|
||||
use colors::Colors;
|
||||
use ezgui::GfxCtx;
|
||||
use geom::{Line, PolyLine, Polygon, Pt2D};
|
||||
use geom::{Bounds, Line, PolyLine, Polygon, Pt2D};
|
||||
use map_model::{Building, BuildingID, Map};
|
||||
use objects::{Ctx, ID};
|
||||
use render::{get_bbox, RenderOptions, Renderable, BUILDING_BOUNDARY_THICKNESS};
|
||||
use render::{RenderOptions, Renderable, BUILDING_BOUNDARY_THICKNESS};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DrawBuilding {
|
||||
@ -46,11 +45,11 @@ impl Renderable for DrawBuilding {
|
||||
g.draw_rounded_line(ctx.cs.get(Colors::BuildingPath), 1.0, &self.front_path);
|
||||
}
|
||||
|
||||
fn get_bbox(&self) -> Rect {
|
||||
fn get_bounds(&self) -> Bounds {
|
||||
let mut b = self.fill_polygon.get_bounds();
|
||||
b.update_pt(self.front_path.pt1());
|
||||
b.update_pt(self.front_path.pt2());
|
||||
get_bbox(&b)
|
||||
b
|
||||
}
|
||||
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
|
@ -1,11 +1,10 @@
|
||||
use aabb_quadtree::geom::Rect;
|
||||
use colors::Colors;
|
||||
use dimensioned::si;
|
||||
use ezgui::GfxCtx;
|
||||
use geom::{PolyLine, Polygon, Pt2D};
|
||||
use geom::{Bounds, PolyLine, Polygon, Pt2D};
|
||||
use map_model::{geometry, BusStop, BusStopID, Map};
|
||||
use objects::{Ctx, ID};
|
||||
use render::{get_bbox, RenderOptions, Renderable};
|
||||
use render::{RenderOptions, Renderable};
|
||||
|
||||
pub struct DrawBusStop {
|
||||
pub id: BusStopID,
|
||||
@ -48,8 +47,8 @@ impl Renderable for DrawBusStop {
|
||||
);
|
||||
}
|
||||
|
||||
fn get_bbox(&self) -> Rect {
|
||||
get_bbox(&self.polygon.get_bounds())
|
||||
fn get_bounds(&self) -> Bounds {
|
||||
self.polygon.get_bounds()
|
||||
}
|
||||
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
|
@ -1,11 +1,10 @@
|
||||
use aabb_quadtree::geom::Rect;
|
||||
use colors::Colors;
|
||||
use dimensioned::si;
|
||||
use ezgui::{shift_color, GfxCtx};
|
||||
use geom::{Line, Polygon, Pt2D};
|
||||
use geom::{Bounds, Line, Polygon, Pt2D};
|
||||
use map_model::{geometry, Map};
|
||||
use objects::{Ctx, ID};
|
||||
use render::{get_bbox, RenderOptions, Renderable};
|
||||
use render::{RenderOptions, Renderable};
|
||||
use sim::{CarID, CarState, DrawCarInput};
|
||||
|
||||
const CAR_WIDTH: f64 = 2.0;
|
||||
@ -121,8 +120,8 @@ impl Renderable for DrawCar {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_bbox(&self) -> Rect {
|
||||
get_bbox(&self.body_polygon.get_bounds())
|
||||
fn get_bounds(&self) -> Bounds {
|
||||
self.body_polygon.get_bounds()
|
||||
}
|
||||
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
|
@ -1,13 +1,10 @@
|
||||
use aabb_quadtree::geom::Rect;
|
||||
use colors::Colors;
|
||||
use ezgui::GfxCtx;
|
||||
use geom::{Circle, Polygon, Pt2D};
|
||||
use geom::{Bounds, Circle, Polygon, Pt2D};
|
||||
use kml::{ExtraShape, ExtraShapeGeom, ExtraShapeID};
|
||||
use map_model::Map;
|
||||
use objects::{Ctx, ID};
|
||||
use render::{
|
||||
get_bbox, RenderOptions, Renderable, EXTRA_SHAPE_POINT_RADIUS, EXTRA_SHAPE_THICKNESS,
|
||||
};
|
||||
use render::{RenderOptions, Renderable, EXTRA_SHAPE_POINT_RADIUS, EXTRA_SHAPE_THICKNESS};
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -53,10 +50,10 @@ impl Renderable for DrawExtraShape {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_bbox(&self) -> Rect {
|
||||
fn get_bounds(&self) -> Bounds {
|
||||
match self.shape {
|
||||
Shape::Polygon(ref p) => get_bbox(&p.get_bounds()),
|
||||
Shape::Circle(ref c) => get_bbox(&c.get_bounds()),
|
||||
Shape::Polygon(ref p) => p.get_bounds(),
|
||||
Shape::Circle(ref c) => c.get_bounds(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,13 +1,12 @@
|
||||
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
use aabb_quadtree::geom::Rect;
|
||||
use colors::Colors;
|
||||
use dimensioned::si;
|
||||
use ezgui::GfxCtx;
|
||||
use geom::{Circle, Line, Polygon, Pt2D};
|
||||
use geom::{Bounds, Circle, Line, Polygon, Pt2D};
|
||||
use map_model::{geometry, Intersection, IntersectionID, LaneType, Map};
|
||||
use objects::{Ctx, ID};
|
||||
use render::{get_bbox, DrawLane, RenderOptions, Renderable};
|
||||
use render::{DrawLane, RenderOptions, Renderable};
|
||||
use std::f64;
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -127,8 +126,8 @@ impl Renderable for DrawIntersection {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_bbox(&self) -> Rect {
|
||||
get_bbox(&self.polygon.get_bounds())
|
||||
fn get_bounds(&self) -> Bounds {
|
||||
self.polygon.get_bounds()
|
||||
}
|
||||
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
|
@ -1,15 +1,14 @@
|
||||
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
use aabb_quadtree::geom::Rect;
|
||||
use colors::Colors;
|
||||
use control::ControlMap;
|
||||
use dimensioned::si;
|
||||
use ezgui::GfxCtx;
|
||||
use geom::{Circle, Line, Polygon, Pt2D};
|
||||
use geom::{Bounds, Circle, Line, Polygon, Pt2D};
|
||||
use map_model;
|
||||
use map_model::{geometry, LaneID};
|
||||
use objects::{Ctx, ID};
|
||||
use render::{get_bbox, RenderOptions, Renderable, PARCEL_BOUNDARY_THICKNESS};
|
||||
use render::{RenderOptions, Renderable, PARCEL_BOUNDARY_THICKNESS};
|
||||
|
||||
const MIN_ZOOM_FOR_LANE_MARKERS: f64 = 5.0;
|
||||
|
||||
@ -148,8 +147,8 @@ impl Renderable for DrawLane {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_bbox(&self) -> Rect {
|
||||
get_bbox(&self.polygon.get_bounds())
|
||||
fn get_bounds(&self) -> Bounds {
|
||||
self.polygon.get_bounds()
|
||||
}
|
||||
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
|
@ -3,7 +3,7 @@
|
||||
use aabb_quadtree::geom::{Point, Rect};
|
||||
use aabb_quadtree::QuadTree;
|
||||
use control::ControlMap;
|
||||
use geom::{LonLat, Pt2D};
|
||||
use geom::{Bounds, LonLat, Pt2D};
|
||||
use kml::{ExtraShape, ExtraShapeID};
|
||||
use map_model::{
|
||||
AreaID, BuildingID, BusStopID, IntersectionID, Lane, LaneID, Map, ParcelID, Turn, TurnID,
|
||||
@ -99,25 +99,25 @@ impl DrawMap {
|
||||
let mut quadtree = QuadTree::default(map_bbox);
|
||||
// TODO use iter chain if everything was boxed as a renderable...
|
||||
for obj in &lanes {
|
||||
quadtree.insert_with_box(obj.get_id(), obj.get_bbox());
|
||||
quadtree.insert_with_box(obj.get_id(), get_bbox(obj.get_bounds()));
|
||||
}
|
||||
for obj in &intersections {
|
||||
quadtree.insert_with_box(obj.get_id(), obj.get_bbox());
|
||||
quadtree.insert_with_box(obj.get_id(), get_bbox(obj.get_bounds()));
|
||||
}
|
||||
for obj in &buildings {
|
||||
quadtree.insert_with_box(obj.get_id(), obj.get_bbox());
|
||||
quadtree.insert_with_box(obj.get_id(), get_bbox(obj.get_bounds()));
|
||||
}
|
||||
for obj in &parcels {
|
||||
quadtree.insert_with_box(obj.get_id(), obj.get_bbox());
|
||||
quadtree.insert_with_box(obj.get_id(), get_bbox(obj.get_bounds()));
|
||||
}
|
||||
for obj in &extra_shapes {
|
||||
quadtree.insert_with_box(obj.get_id(), obj.get_bbox());
|
||||
quadtree.insert_with_box(obj.get_id(), get_bbox(obj.get_bounds()));
|
||||
}
|
||||
for obj in bus_stops.values() {
|
||||
quadtree.insert_with_box(obj.get_id(), obj.get_bbox());
|
||||
quadtree.insert_with_box(obj.get_id(), get_bbox(obj.get_bounds()));
|
||||
}
|
||||
for obj in &areas {
|
||||
quadtree.insert_with_box(obj.get_id(), obj.get_bbox());
|
||||
quadtree.insert_with_box(obj.get_id(), get_bbox(obj.get_bounds()));
|
||||
}
|
||||
|
||||
(
|
||||
@ -311,3 +311,16 @@ impl DrawMap {
|
||||
(borrows, returns)
|
||||
}
|
||||
}
|
||||
|
||||
fn get_bbox(b: Bounds) -> Rect {
|
||||
Rect {
|
||||
top_left: Point {
|
||||
x: b.min_x as f32,
|
||||
y: b.min_y as f32,
|
||||
},
|
||||
bottom_right: Point {
|
||||
x: b.max_x as f32,
|
||||
y: b.max_y as f32,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ mod parcel;
|
||||
mod pedestrian;
|
||||
mod turn;
|
||||
|
||||
use aabb_quadtree::geom::{Point, Rect};
|
||||
use ezgui::GfxCtx;
|
||||
use geom::{Bounds, Pt2D};
|
||||
use graphics::types::Color;
|
||||
@ -37,24 +36,10 @@ const BIG_ARROW_TIP_LENGTH: f64 = 1.0;
|
||||
const TURN_ICON_ARROW_TIP_LENGTH: f64 = BIG_ARROW_TIP_LENGTH * 0.8;
|
||||
const TURN_ICON_ARROW_LENGTH: f64 = 2.0;
|
||||
|
||||
pub fn get_bbox(b: &Bounds) -> Rect {
|
||||
Rect {
|
||||
top_left: Point {
|
||||
x: b.min_x as f32,
|
||||
y: b.min_y as f32,
|
||||
},
|
||||
bottom_right: Point {
|
||||
x: b.max_x as f32,
|
||||
y: b.max_y as f32,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Renderable {
|
||||
fn get_id(&self) -> ID;
|
||||
fn draw(&self, g: &mut GfxCtx, opts: RenderOptions, ctx: Ctx);
|
||||
// TODO Maybe return Bounds
|
||||
fn get_bbox(&self) -> Rect;
|
||||
fn get_bounds(&self) -> Bounds;
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool;
|
||||
fn tooltip_lines(&self, map: &Map) -> Vec<String>;
|
||||
}
|
||||
|
@ -1,13 +1,12 @@
|
||||
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
use aabb_quadtree::geom::Rect;
|
||||
use colors::Colors;
|
||||
use ezgui::GfxCtx;
|
||||
use geom::{PolyLine, Polygon, Pt2D};
|
||||
use geom::{Bounds, PolyLine, Polygon, Pt2D};
|
||||
use graphics::types::Color;
|
||||
use map_model::{Map, Parcel, ParcelID};
|
||||
use objects::{Ctx, ID};
|
||||
use render::{get_bbox, RenderOptions, Renderable, PARCEL_BOUNDARY_THICKNESS};
|
||||
use render::{RenderOptions, Renderable, PARCEL_BOUNDARY_THICKNESS};
|
||||
|
||||
const COLORS: [Color; 14] = [
|
||||
// TODO these are awful choices
|
||||
@ -61,8 +60,8 @@ impl Renderable for DrawParcel {
|
||||
g.draw_polygon(ctx.cs.get(Colors::ParcelBoundary), &self.boundary_polygon);
|
||||
}
|
||||
|
||||
fn get_bbox(&self) -> Rect {
|
||||
get_bbox(&self.fill_polygon.get_bounds())
|
||||
fn get_bounds(&self) -> Bounds {
|
||||
self.fill_polygon.get_bounds()
|
||||
}
|
||||
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
|
@ -1,10 +1,9 @@
|
||||
use aabb_quadtree::geom::Rect;
|
||||
use colors::Colors;
|
||||
use ezgui::{shift_color, GfxCtx};
|
||||
use geom::{Circle, Line, Pt2D};
|
||||
use geom::{Bounds, Circle, Line, Pt2D};
|
||||
use map_model::Map;
|
||||
use objects::{Ctx, ID};
|
||||
use render::{get_bbox, RenderOptions, Renderable};
|
||||
use render::{RenderOptions, Renderable};
|
||||
use sim::{DrawPedestrianInput, PedestrianID};
|
||||
|
||||
const RADIUS: f64 = 1.0;
|
||||
@ -51,8 +50,8 @@ impl Renderable for DrawPedestrian {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_bbox(&self) -> Rect {
|
||||
get_bbox(&self.circle.get_bounds())
|
||||
fn get_bounds(&self) -> Bounds {
|
||||
self.circle.get_bounds()
|
||||
}
|
||||
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
|
@ -1,15 +1,14 @@
|
||||
// Copyright 2018 Google LLC, licensed under http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
use aabb_quadtree::geom::Rect;
|
||||
use colors::Colors;
|
||||
use dimensioned::si;
|
||||
use ezgui::GfxCtx;
|
||||
use geom::{Circle, Line, Pt2D};
|
||||
use geom::{Bounds, Circle, Line, Pt2D};
|
||||
use graphics::types::Color;
|
||||
use map_model::{geometry, Map, Turn, TurnID};
|
||||
use objects::{Ctx, ID};
|
||||
use render::{
|
||||
get_bbox, RenderOptions, Renderable, BIG_ARROW_TIP_LENGTH, TURN_ICON_ARROW_LENGTH,
|
||||
RenderOptions, Renderable, BIG_ARROW_TIP_LENGTH, TURN_ICON_ARROW_LENGTH,
|
||||
TURN_ICON_ARROW_THICKNESS, TURN_ICON_ARROW_TIP_LENGTH,
|
||||
};
|
||||
use std::f64;
|
||||
@ -78,8 +77,8 @@ impl Renderable for DrawTurn {
|
||||
);
|
||||
}
|
||||
|
||||
fn get_bbox(&self) -> Rect {
|
||||
get_bbox(&self.icon_circle.get_bounds())
|
||||
fn get_bounds(&self) -> Bounds {
|
||||
self.icon_circle.get_bounds()
|
||||
}
|
||||
|
||||
fn contains_pt(&self, pt: Pt2D) -> bool {
|
||||
|
Loading…
Reference in New Issue
Block a user