use core::render::Renderer;
use sdl2::rect::Rect;
-use common::Point2D;
+use common::Point;
use sdl2::gfx::primitives::DrawRenderer;
use {SCREEN_HEIGHT, SCREEN_WIDTH};
}
pub struct SquareBoll {
- pub pos: Point2D<f64>,
- pub vel: Point2D<f64>,
+ pub pos: Point<f64>,
+ pub vel: Point<f64>,
}
impl Boll for SquareBoll {
}
impl CircleBoll {
- pub fn new(pos: Point2D<f64>, vel: Point2D<f64>) -> CircleBoll {
+ pub fn new(pos: Point<f64>, vel: Point<f64>) -> CircleBoll {
CircleBoll {
boll: SquareBoll { pos, vel },
}
#[macro_export]
macro_rules! point {
( $x:expr, $y:expr ) => {
- Point2D { x: $x, y: $y }
+ Point { x: $x, y: $y }
};
}
#[derive(Debug, Default, Copy, Clone, PartialEq)]
-pub struct Point2D<T> {
+pub struct Point<T> {
pub x: T,
pub y: T,
}
-impl Point2D<f64> {
+impl Point<f64> {
pub fn length(&self) -> f64 {
((self.x * self.x) + (self.y * self.y)).sqrt()
}
self.to_radians().to_degrees()
}
- pub fn to_i32(self) -> Point2D<i32> {
- Point2D {
+ pub fn to_i32(self) -> Point<i32> {
+ Point {
x: self.x as i32,
y: self.y as i32,
}
macro_rules! point_op {
($op:tt, $trait:ident($fn:ident), $trait_assign:ident($fn_assign:ident), $rhs:ident = $Rhs:ty => $x:expr, $y:expr) => {
- impl<T: $trait<Output = T>> $trait<$Rhs> for Point2D<T> {
+ impl<T: $trait<Output = T>> $trait<$Rhs> for Point<T> {
type Output = Self;
fn $fn(self, $rhs: $Rhs) -> Self {
}
}
- impl<T: $trait<Output = T> + Copy> $trait_assign<$Rhs> for Point2D<T> {
+ impl<T: $trait<Output = T> + Copy> $trait_assign<$Rhs> for Point<T> {
fn $fn_assign(&mut self, $rhs: $Rhs) {
*self = Self {
x: self.x $op $x,
}
}
-point_op!(+, Add(add), AddAssign(add_assign), rhs = Point2D<T> => rhs.x, rhs.y);
-point_op!(-, Sub(sub), SubAssign(sub_assign), rhs = Point2D<T> => rhs.x, rhs.y);
-point_op!(*, Mul(mul), MulAssign(mul_assign), rhs = Point2D<T> => rhs.x, rhs.y);
-point_op!(/, Div(div), DivAssign(div_assign), rhs = Point2D<T> => rhs.x, rhs.y);
+point_op!(+, Add(add), AddAssign(add_assign), rhs = Point<T> => rhs.x, rhs.y);
+point_op!(-, Sub(sub), SubAssign(sub_assign), rhs = Point<T> => rhs.x, rhs.y);
+point_op!(*, Mul(mul), MulAssign(mul_assign), rhs = Point<T> => rhs.x, rhs.y);
+point_op!(/, Div(div), DivAssign(div_assign), rhs = Point<T> => rhs.x, rhs.y);
point_op!(+, Add(add), AddAssign(add_assign), rhs = (T, T) => rhs.0, rhs.1);
point_op!(-, Sub(sub), SubAssign(sub_assign), rhs = (T, T) => rhs.0, rhs.1);
point_op!(*, Mul(mul), MulAssign(mul_assign), rhs = (T, T) => rhs.0, rhs.1);
point_op!(/, Div(div), DivAssign(div_assign), rhs = (T, T) => rhs.0, rhs.1);
////////// multiply point with scalar //////////////////////////////////////////
-impl<T: Mul<Output = T> + Copy> Mul<T> for Point2D<T> {
+impl<T: Mul<Output = T> + Copy> Mul<T> for Point<T> {
type Output = Self;
fn mul(self, rhs: T) -> Self {
}
}
-impl<T: Mul<Output = T> + Copy> MulAssign<T> for Point2D<T> {
+impl<T: Mul<Output = T> + Copy> MulAssign<T> for Point<T> {
fn mul_assign(&mut self, rhs: T) {
*self = Self {
x: self.x * rhs,
}
////////// divide point with scalar ////////////////////////////////////////////
-impl<T: Div<Output = T> + Copy> Div<T> for Point2D<T> {
+impl<T: Div<Output = T> + Copy> Div<T> for Point<T> {
type Output = Self;
fn div(self, rhs: T) -> Self {
}
}
-impl<T: Div<Output = T> + Copy> DivAssign<T> for Point2D<T> {
+impl<T: Div<Output = T> + Copy> DivAssign<T> for Point<T> {
fn div_assign(&mut self, rhs: T) {
*self = Self {
x: self.x / rhs,
}
}
-impl<T: Neg<Output = T>> Neg for Point2D<T> {
+impl<T: Neg<Output = T>> Neg for Point<T> {
type Output = Self;
fn neg(self) -> Self {
}
}
-impl<T> From<(T, T)> for Point2D<T> {
+impl<T> From<(T, T)> for Point<T> {
fn from(item: (T, T)) -> Self {
- Point2D {
+ Point {
x: item.0,
y: item.1,
}
}
}
-impl<T> From<Point2D<T>> for (T, T) {
- fn from(item: Point2D<T>) -> Self {
+impl<T> From<Point<T>> for (T, T) {
+ fn from(item: Point<T>) -> Self {
(item.x, item.y)
}
}
-impl From<Degrees> for Point2D<f64> {
+impl From<Degrees> for Point<f64> {
fn from(item: Degrees) -> Self {
let r = item.0.to_radians();
- Point2D {
+ Point {
x: r.cos(),
y: r.sin(),
}
}
}
-impl From<Radians> for Point2D<f64> {
+impl From<Radians> for Point<f64> {
fn from(item: Radians) -> Self {
- Point2D {
+ Point {
x: item.0.cos(),
y: item.0.sin(),
}
assert_eq!(Radians(0.0).to_degrees(), Degrees(0.0));
assert_eq!(Radians(std::f64::consts::PI).to_degrees(), Degrees(180.0));
assert_eq!(Degrees(180.0).to_radians(), Radians(std::f64::consts::PI));
- assert!((Point2D::from(Degrees(90.0)) - point!(0.0, 1.0)).length() < 0.001);
- assert!((Point2D::from(Radians(std::f64::consts::FRAC_PI_2)) - point!(0.0, 1.0)).length() < 0.001);
+ assert!((Point::from(Degrees(90.0)) - point!(0.0, 1.0)).length() < 0.001);
+ assert!((Point::from(Radians(std::f64::consts::FRAC_PI_2)) - point!(0.0, 1.0)).length() < 0.001);
}
#[test]
mod geometry;
-pub use common::geometry::Point2D;
+pub use common::geometry::Point;
pub use common::geometry::Rect;
pub use common::geometry::Radians;
pub use common::geometry::Degrees;
use boll::*;
-use common::{Point2D, Rect};
+use common::{Point, Rect};
use core::controller::ControllerManager;
use core::render::Renderer;
use point; // defined in common, but loaded from main...
-use common::Point2D;
+use common::Point;
use {hashmap, point};
use common::Radians;
use sdl2::HapticSubsystem;
#[inline(always)] #[allow(dead_code)] pub fn left(&self) -> bool { self.x < -0.99 }
#[inline(always)] #[allow(dead_code)] pub fn right(&self) -> bool { self.x > 0.99 }
- pub fn to_axis_point(&self) -> Point2D<f64> {
+ pub fn to_axis_point(&self) -> Point<f64> {
point!(self.x as f64, self.y as f64)
}
- pub fn to_point(&self) -> Point2D<f64> {
+ pub fn to_point(&self) -> Point<f64> {
let p = point!(self.x as f64, self.y as f64);
if p.length() > 1.0 {
p.normalized()
}
}
-impl From<&Stick> for Point2D<f64> {
+impl From<&Stick> for Point<f64> {
fn from(item: &Stick) -> Self {
Self {
x: item.x as f64,
use ActiveState;
use AppState;
-use common::{Point2D, Radians};
+use common::{Point, Radians};
use core::app::StateChange;
use core::controller::Controller;
use core::controller::ControllerManager;
pub struct Character {
ctrl: Rc<RefCell<Controller>>,
- pos: Point2D<f64>,
- vel: Point2D<f64>,
+ pos: Point<f64>,
+ vel: Point<f64>,
}
impl Character {
renderer.draw_line(pos, p, (0, 255, 0));
draw_cross(renderer, p);
// // circle values
- // let p = (self.pos + Point2D::from(ctrl.aim.a) * l).to_i32().into();
+ // let p = (self.pos + Point::from(ctrl.aim.a) * l).to_i32().into();
// renderer.draw_line(pos, p, (0, 0, 255));
// draw_cross(renderer, p);
}
////////// BOLL ////////////////////////////////////////////////////////////////
pub struct Boll {
- pos: Point2D<f64>,
- vel: Point2D<f64>,
+ pos: Point<f64>,
+ vel: Point<f64>,
bounces: u8,
}
let mut rng = rand::thread_rng();
let a = Radians(self.vel.to_radians().0 + Normal::new(0.0, 0.75).sample(&mut rng));
objects.push(Box::new(Boll {
- vel: Point2D::from(a) * Normal::new(1.0, 0.25).sample(&mut rng) * self.vel.length(),
+ vel: Point::from(a) * Normal::new(1.0, 0.25).sample(&mut rng) * self.vel.length(),
..*self
}));
}
use {point, time_scope};
-use common::Point2D;
+use common::Point;
use super::{Grid, Level};
use noise::{NoiseFn, OpenSimplex, Seedable};
use rand::Rng;
}
}
- fn find_walls(&self, grid: &Grid) -> Vec<Vec<Point2D<isize>>> {
+ fn find_walls(&self, grid: &Grid) -> Vec<Vec<Point<isize>>> {
let mut walls = vec!();
for r in self.find_regions(&grid) {
if r.value {
(min.0, min.1, 1 + max.0 - min.0, 1 + max.1 - min.1)
}
- pub fn outline(&self, scale: usize) -> Vec<Point2D<isize>> {
+ pub fn outline(&self, scale: usize) -> Vec<Point<isize>> {
let rect = self.enclosing_rect();
let (ox, oy, w, h) = rect;
let grid = self.grid(&rect);
grid
}
- fn find_first_point_of_outline(&self, rect: &(usize, usize, usize, usize), grid: &Vec<Vec<bool>>) -> Point2D<isize> {
+ fn find_first_point_of_outline(&self, rect: &(usize, usize, usize, usize), grid: &Vec<Vec<bool>>) -> Point<isize> {
let (ox, oy, w, h) = rect;
let is_outer_wall = (ox, oy) == (&0, &0); // we know this is always the outer wall of the level
for x in 0..*w {
panic!("no wall found!");
}
- fn find_next_point_of_outline(&self, grid: &Vec<Vec<bool>>, p: &mut Point2D<isize>, directions: &mut Vec<(isize, isize)>) {
+ fn find_next_point_of_outline(&self, grid: &Vec<Vec<bool>>, p: &mut Point<isize>, directions: &mut Vec<(isize, isize)>) {
directions.rotate_left(2);
loop {
let d = directions[0];
}
}
- fn check(&self, p: Point2D<isize>, grid: &Vec<Vec<bool>>) -> bool {
+ fn check(&self, p: Point<isize>, grid: &Vec<Vec<bool>>) -> bool {
if p.x < 0 || p.x >= grid.len() as isize || p.y < 0 || p.y >= grid[0].len() as isize {
false
} else {
-use common::Point2D;
+use common::Point;
use core::render::Renderer;
use sprites::SpriteManager;
#[derive(Default)]
pub struct Level {
- pub gravity: Point2D<f64>,
+ pub gravity: Point<f64>,
pub grid: Grid,
- walls: Vec<Vec<Point2D<isize>>>,
+ walls: Vec<Vec<Point<isize>>>,
}
impl Level {
- // pub fn new(gravity: Point2D<f64>) -> Self {
+ // pub fn new(gravity: Point<f64>) -> Self {
// let seed = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_secs() as u32;
// let mut lvl = Level { gravity, grid: Grid::generate(seed, 10), iterations: 10, walls: vec!() };
// lvl.filter_regions();