Skip to content

Commit

Permalink
Merge pull request #1 from Karuzzzo/add_waypoints
Browse files Browse the repository at this point in the history
Add waypoints
  • Loading branch information
Karuzzzo authored Sep 22, 2021
2 parents 4faf915 + 2dcd154 commit 3e6c3fe
Show file tree
Hide file tree
Showing 6 changed files with 923 additions and 33 deletions.
45 changes: 44 additions & 1 deletion dsky-utils/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![cfg_attr(not(feature = "std"), no_std)]

use substrate_fixed::types::I10F22;
use substrate_fixed::{types::{I10F22, I42F22}, traits::FromFixed};
// Set of traits, required for Coord struct, used in maps pallet

pub trait IntDiv<RHS = Self> {
fn integer_division_u16(self, rhs: RHS) -> u16;
Expand All @@ -9,6 +10,7 @@ pub trait IntDiv<RHS = Self> {

pub trait Signed {
fn abs(self) -> Self;
fn signum(self) -> Self;
}

pub trait FromRaw {
Expand All @@ -19,6 +21,22 @@ pub trait CastToType {
fn to_u32_with_frac_part(self, cell_size: u32, max_digits_in_frac_part: u8) -> u32;
}

// TODO consider naming of two traits, as they are used in pair
pub trait ToBigCoord {
type Output;
fn try_into(self) -> Self::Output;
}

pub trait FromBigCoord {
type Output;
fn try_from(self) -> Self::Output;
}

pub trait GetEpsilon {
fn get_epsilon() -> Self;
}

// Here comes the implementations
// Want to change Coord type => impl trait for it here
impl IntDiv for I10F22 {
fn integer_division_u16(self, rhs: I10F22) -> u16 {
Expand All @@ -40,6 +58,10 @@ impl Signed for I10F22 {
fn abs(self) -> Self {
self.abs()
}
/// returns sign (-1, 1, 0)
fn signum(self) -> Self {
self.signum()
}
}

impl CastToType for I10F22 {
Expand All @@ -63,3 +85,24 @@ impl CastToType for I10F22 {
integer_part + frac_part
}
}

impl ToBigCoord for I10F22 {
type Output = I42F22;
fn try_into(self) -> Self::Output {
self.into()
}
}

// TODO handle possible errors through checked_from_fixed()
impl FromBigCoord for I42F22 {
type Output = I10F22;
fn try_from(self) -> Self::Output {
I10F22::from_fixed(self)
}
}

impl GetEpsilon for I42F22 {
fn get_epsilon() -> I42F22 {
I42F22::from_num(0.00001f64)
}
}
4 changes: 3 additions & 1 deletion pallets/ds-maps/src/default_weight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ impl crate::WeightInfo for () {
fn change_area_type() -> Weight {
100_000_u64.saturating_add(DbWeight::get().writes(1))
}

fn route_add() -> Weight {
100_000_u64.saturating_add(DbWeight::get().writes(1))
}
}
Loading

0 comments on commit 3e6c3fe

Please sign in to comment.