--- /dev/null
+use common::{Point, Intersection};
+use core::app::{AppState, StateChange};
+use core::controller::ControllerManager;
+use core::render::Renderer;
+use point; // defined in common, but loaded from main...
+use sdl2::event::Event;
+use sprites::SpriteManager;
+use time::{Duration, Instant};
+
+pub struct TestState {
+ start: Instant,
+}
+
+impl TestState {
+ pub fn new() -> TestState {
+ TestState {
+ start: Instant::now(),
+ }
+ }
+
+ fn draw_intersecting_lines(&self, renderer: &mut Renderer, p1: (i32, i32), p2: (i32, i32), p3: (i32, i32), p4: (i32, i32)) {
+ let color = match Intersection::lines(
+ point!(p1.0 as f64, p1.1 as f64),
+ point!(p2.0 as f64, p2.1 as f64),
+ point!(p3.0 as f64, p3.1 as f64),
+ point!(p4.0 as f64, p4.1 as f64)
+ ) {
+ Intersection::Point(p) => {
+ renderer.circle((p.x as i16, p.y as i16), 3, (255, 255, 0));
+ (0, 255, 0)
+ }
+ Intersection::None => (255, 0, 0)
+ };
+ renderer.draw_line(p1, p2, color);
+ renderer.draw_line(p3, p4, color);
+ }
+}
+
+impl AppState for TestState {
+ fn enter(&mut self, _ctrl_man: &ControllerManager) {}
+
+ fn update(&mut self, _dt: Duration) -> Option<StateChange> {
+ None
+ }
+
+ fn render(&mut self, renderer: &mut Renderer, _sprites: &SpriteManager) {
+ // crossing
+ self.draw_intersecting_lines(renderer, (0, 0), (20, 20), (20, 0), (0, 20));
+ self.draw_intersecting_lines(renderer, (30, 10), (50, 10), (40, 0), (40, 20));
+
+ // just touching
+ self.draw_intersecting_lines(renderer, (70, 0), (70, 10), (60, 10), (80, 10));
+ self.draw_intersecting_lines(renderer, (90, 0), (100, 10), (90, 20), (110, 0));
+ self.draw_intersecting_lines(renderer, (120, 0), (140, 20), (120, 20), (130, 10));
+ self.draw_intersecting_lines(renderer, (170, 10), (160, 10), (160, 0), (160, 20));
+
+ // not touching
+ self.draw_intersecting_lines(renderer, (190, 0), (210, 20), (195, 20), (200, 15));
+
+ let a = self.start.elapsed().as_seconds_f64().sin() * std::f64::consts::FRAC_PI_2;
+ let (ax, ay) = ((a.cos() * 200.0) as i32, (a.sin() * 200.0) as i32);
+ self.draw_intersecting_lines(renderer, (10, 400), (10 + ax, 400 + ay), (30, 200), (30, 600));
+
+ let x = (self.start.elapsed().as_seconds_f64().cos() * 60.0) as i32;
+ let y = (self.start.elapsed().as_seconds_f64().sin() * 60.0) as i32;
+ let x2 = ((self.start.elapsed().as_seconds_f64() + std::f64::consts::FRAC_PI_4).cos() * 60.0) as i32;
+ let y2 = ((self.start.elapsed().as_seconds_f64() + std::f64::consts::FRAC_PI_4).sin() * 60.0) as i32;
+ self.draw_intersecting_lines(renderer, (100 + x, 100 + y), (150 + x, 150 + y), (100 + x2, 150 + y2), (150 + x2, 100 + y2));
+ self.draw_intersecting_lines(renderer, (250 + x, 85 + y), (250 + x, 165 + y), (210 + x2, 125 + y2), (290 + x2, 125 + y2));
+ }
+
+ fn leave(&mut self) {
+ }
+
+ fn handle_event(&mut self, _event: Event) -> Option<StateChange> {
+ None
+ }
+}