The latter will always be rectangle.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
Rectangle(a) => a.contains(pos),
}
}
+
+ pub fn overlaps(&self, other: &Region<T>) -> bool where T: PartialOrd {
+ use Region::*;
+ match (self, other) {
+ (Rectangle(a), Rectangle(b)) => a.overlaps(b)
+ }
+ }
+
+ pub fn empty() -> Self where T: Copy + num_traits::Zero + num_traits::One {
+ Region::Rectangle(AreaC::empty())
+ }
+
}
});
let (region, views) = (||{
dbgc!("claiming region");
+ let area = self.shape.outline.area (gpc.pos)?;
let region = self.shape.outline.region(gpc.pos)?;
- let displace = OccDisplacement::Rect { area: region };
+ let displace = OccDisplacement::Rect { area };
let views = OwnerOccultationView {
owner: player,
owner_view: OccK::Visible,
#[derive(Clone,Debug,Serialize,Deserialize)]
pub struct Occultation {
- region: Area, // automatically affect pieces here
+ region: Region<Coord>, // automatically affect pieces here
occulter: PieceId, // kept in synch with PieceOccult::active
notches: Notches, // kept in synch with PieceOccult::passive
ppiece_use_size: Pos, // taken from first piece
ipieces: &IPieces,
ioccults: &IOccults,
to_recalculate: &mut ToRecalculate,
- region: Area,
+ region: Region<Coord>,
occulter: PieceId,
views: OccultationViews,
) -> Vec<(PieceId, PieceUpdateOps)> {
// that the affected pieces can know what the old situation was.
// So we set the region to empty, and do a recalculation of the
// relevant pieces. Only then can we get rid of the occultation.
- occ.region = Area::empty();
+ occ.region = Region::empty();
let pieces: Vec<_> = occ.notches.iter().collect();
for &ppiece in pieces.iter() {
pub const CLOCK_REALTIME : ClockId = ClockId::CLOCK_REALTIME ;
pub const CLOCK_MONOTONIC: ClockId = ClockId::CLOCK_MONOTONIC;
-pub use otter_base::geometry::{Coord,Pos,PosC,Area,AreaC};
-pub use otter_base::geometry::CoordinateOverflow;
+pub use otter_base::geometry::{self,Coord,Pos,PosC,Area,AreaC};
+pub use otter_base::geometry::{CoordinateOverflow,Region};
pub use otter_base::zcoord::{self, ZCoord};
pub use otter_base::misc as base_misc;
pub use base_misc::default;
impl Rectangle {
#[throws(CoordinateOverflow)]
- pub fn region(&self, centre: Pos) -> AreaC<Coord> {
+ pub fn area(&self, centre: Pos) -> AreaC<Coord> {
let offset = (self.xy * 0.5)?;
let offset = offset.try_map(
|c| c.floor().to_i32().ok_or(CoordinateOverflow)
);
region
}
+
+ #[throws(CoordinateOverflow)]
+ pub fn region(&self, centre: Pos) -> Region<Coord> {
+ Region::Rectangle(self.area(centre)?)
+ }
}
#[dyn_upcast]