Skip to content

Commit

Permalink
prepare for publishing
Browse files Browse the repository at this point in the history
- update Cargo.toml.
- bump glam to 0.20.
- add .rustfmt.toml & rustfmt.
- update docs & readme.
  • Loading branch information
joseluis committed Dec 14, 2021
1 parent 96ed71a commit c9c6b33
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 293 deletions.
17 changes: 8 additions & 9 deletions .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@
# - only stable config settings are included.
# - * indicates the default value of a setting.
# - CHECK indicates the use of a non-default value.
################################################################################


# Maximum width of an array literal before falling back to vertical formatting.
# https://rust-lang.github.io/rustfmt/?search=#array_width
array_width = 60 # *60
array_width = 92 # *60 CHECK

# Maximum width of the args of a function-like attributes before falling back
# to vertical formatting.
# https://rust-lang.github.io/rustfmt/?search=#attr_fn_like_width
attr_fn_like_width = 70 # *70

attr_fn_like_width = 92 # *70 CHECK

# Maximum width of a chain to fit on one line.
# https://rust-lang.github.io/rustfmt/?search=#chain_width
chain_width = 60 # *60
chain_width = 92 # *60 CHECK

# Specifies which edition is used by the parser.
# https://rust-lang.github.io/rustfmt/?search=#
Expand All @@ -32,7 +31,7 @@ fn_args_layout = "Tall" # *"Tall", "Compressed", "Vertical"
# Maximum width of the args of a function call before falling back to vertical
# formatting.
# https://rust-lang.github.io/rustfmt/?search=#fn_call_width
fn_call_width = 60 # *60
fn_call_width = 92 # *60 CHECK

# Always print the abi for extern items.
# https://rust-lang.github.io/rustfmt/?search=#force_explicit_abi
Expand Down Expand Up @@ -75,19 +74,19 @@ reorder_modules = true # *true
# results in if-else expressions always being broken into multiple lines. Note
# this occurs when use_small_heuristics is set to Off.
# https://rust-lang.github.io/rustfmt/?search=#single_line_if_else_max_width
single_line_if_else_max_width = 50 # *50 CHECK TODO
single_line_if_else_max_width = 92 # *50

# Maximum width in the body of a struct literal before falling back to vertical
# formatting. A value of 0 (zero) results in struct literals always being broken
# into multiple lines. Note this occurs when use_small_heuristics is set to Off.
# https://rust-lang.github.io/rustfmt/?search=#struct_lit_width
struct_lit_width = 18 # *18 CHECK TODO
struct_lit_width = 92 # *18 CHECK

# Maximum width in the body of a struct variant before falling back to vertical
# formatting. A value of 0 (zero) results in struct literals always being broken
# into multiple lines. Note this occurs when use_small_heuristics is set to Off.
# https://rust-lang.github.io/rustfmt/?search=#struct_variant_width
struct_variant_width = 35 # *35
struct_variant_width = 92 # *35 CHECK

# Number of spaces per tab.
# https://rust-lang.github.io/rustfmt/?search=#tab_spaces
Expand Down
17 changes: 6 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fisica"
description = "Physics"
description = "A physics library"
version = "0.1.0"
edition = "2021"
rust-version = "1.57"
Expand All @@ -14,29 +14,24 @@ include = [
"LICENSE*",
"README.md",
]
categories = []
keywords = []
publish = false
categories = [ "science" ]
keywords = [ "physics" ]

[dependencies]
paste = "1.0.5"
glam = "0.17.*" # CHECK
glam = "^0.20"

# itoa = "1.0.1"
# dtoa = "1.0.1"
ryu = "1.0.9"

# ryu = "1.0.9"
# pretty_dtoa = "0.3.0"
# num = "0.4.0"


[dev-dependencies]
float_eq = "0.6.0"
# approx = "*" # MAYBE?
# macroquad = "0.3.8"
# approx = "*"

[build-dependencies]
# docima ="*"

[package.metadata.docs.rs]
rustdoc-args = [ "--html-in-header", "./src/docs-header.html" ]
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# fisica

<!--
[![Crate](https://img.shields.io/crates/v/fisica.svg)](https://crates.io/crates/fisica)
[![API](https://docs.rs/fisica/badge.svg)](https://docs.rs/fisica/)
[![Lines Of Code](https://tokei.rs/b1/github/andamira/fisica?category=code)](https://github.com/andamira/fisica)
-->

6 changes: 0 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
//! A physics library
//!
// waiting for:
// - feature(const_fn_floating_point_arithmetic):
// https://github.com/rust-lang/rust/issues/57241
// - handle impl section of type definitions:
// https://github.com/rust-lang/rust/issues/32077

#[macro_use]
mod auto_impls;

Expand Down
28 changes: 7 additions & 21 deletions src/math/vectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ pub type Position = Direction;
impl Direction {
/// New `Direction`.
pub fn new(x: Magnitude, y: Magnitude, z: Magnitude) -> Self {
Self {
v: V3::new(x, y, z),
}
Self { v: V3::new(x, y, z) }
}

pub fn to_array(&self) -> [Magnitude; 3] {
Expand Down Expand Up @@ -82,9 +80,7 @@ impl Direction {
/// \frac{\bm{a}}{|\bm{a}|}
/// $$
pub fn normalize(&self) -> Direction {
Self {
v: self.v.normalize(),
}
Self { v: self.v.normalize() }
}

/// Returns the cross product.
Expand All @@ -103,9 +99,7 @@ impl Direction {
/// \end{bmatrix}
/// $$
pub fn cross(&self, other: Self) -> Self {
Self {
v: self.v.cross(other.v),
}
Self { v: self.v.cross(other.v) }
}

/// Returns the dot product.
Expand Down Expand Up @@ -142,16 +136,12 @@ impl Direction {
impl Add for Direction {
type Output = Self;
fn add(self, other: Self) -> Self {
Self {
v: self.v + other.v,
}
Self { v: self.v + other.v }
}
}
impl AddAssign for Direction {
fn add_assign(&mut self, other: Self) {
*self = Self {
v: self.v + other.v,
};
*self = Self { v: self.v + other.v };
}
}

Expand All @@ -160,16 +150,12 @@ impl Sub for Direction {
type Output = Self;

fn sub(self, other: Self) -> Self {
Self {
v: self.v - other.v,
}
Self { v: self.v - other.v }
}
}
impl SubAssign for Direction {
fn sub_assign(&mut self, other: Self) {
*self = Self {
v: self.v - other.v,
};
*self = Self { v: self.v - other.v };
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/units/acceleration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,7 @@ mod tests {
assert_float_eq!(2., acceleration.m(), r2nd <= Magnitude::EPSILON);
assert_float_eq!(
5.,
acceleration
.calc_mass(Force::new(Direction::new(10., 0., 0.)))
.m(),
acceleration.calc_mass(Force::new(Direction::new(10., 0., 0.))).m(),
r2nd <= Magnitude::EPSILON
);
assert_float_eq!(
Expand Down
12 changes: 6 additions & 6 deletions src/units/charge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,34 +27,34 @@ impl Charge {
///
/// <https://en.wikipedia.org/wiki/Orders_of_magnitude_(charge)>
impl Charge {
/// (10e-19) The [elementary charge][1] of the [proton][0].
/// (10e-19) The [*elementary charge*][1] of the [*proton*][0].
///
/// [0]: https://en.wikipedia.org/wiki/Proton
/// [1]: https://en.wikipedia.org/wiki/Elementary_charge
pub const PROTON: Self = Self::new(1.602176634e-19);

/// (10e-19) The [elementary charge][1] of the [electron][0].
/// (10e-19) The [*elementary charge*][1] of the [*electron*][0].
///
/// [0]: https://en.wikipedia.org/wiki/Electron
/// [1]: https://en.wikipedia.org/wiki/Elementary_charge
pub const ELECTRON: Self = Self::new(-1.602176634e-19);

/// (10e-6) [Static electricity][0] from rubbing materials together (1 µC).
/// (10e-6) [*Static electricity*][0] from rubbing materials together (1 µC).
///
/// [0]: https://en.wikipedia.org/wiki/Static_electricity
pub const STATIC_RUBBING: Self = Self::new(1e-6);

/// (10e1) Charge in a typical [thundercloud][0] (15-350 C).
/// (10e1) Charge in a typical [*thundercloud*][0] (15-350 C).
///
/// [0]: https://en.wikipedia.org/wiki/Cumulonimbus_cloud
pub const THUNDERCLOUD: Self = Self::new(2.6e1);

/// (10e3) Typical alkaline [AA battery][0] is about 5000 C ≈ 1.4 Ah.
/// (10e3) Typical alkaline [*AA battery*][0] is about 5000 C ≈ 1.4 Ah.
///
/// [0]: https://en.wikipedia.org/wiki/AA_battery
pub const AA_BATTERY: Self = Self::new(5e3);

/// (10e4) The [Faraday constant] represents the charge per mole of electrons.
/// (10e4) The [*Faraday constant*][0] represents the charge per mole of electrons.
///
/// [0]: https://en.wikipedia.org/wiki/Faraday_constant
pub const FARADAY: Self = Self::new(9.648_533_212_33e4);
Expand Down
14 changes: 3 additions & 11 deletions src/units/energy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl Energy {
Time::new(self.m() / p.m())
}

/// Returns the `Energy` [equivalent][0] to the given [`Mass`] (`E = mc²`).
/// Returns the `Energy` [*equivalent*][0] to the given [`Mass`] (`E = mc²`).
///
/// [0]:https://en.wikipedia.org/wiki/Mass%E2%80%93energy_equivalence
#[inline]
Expand All @@ -84,21 +84,13 @@ mod tests {
fn energy_formulas() {
// Energy, Power & Time
let energy = Energy::from_power_time(Power::new(800.), Time::in_min(3.));
assert_float_eq!(
Energy::in_kJ(144.).m(),
energy.m(),
r2nd <= Magnitude::EPSILON
);
assert_float_eq!(Energy::in_kJ(144.).m(), energy.m(), r2nd <= Magnitude::EPSILON);
assert_float_eq!(
energy.m(),
Energy::from_time_power(Time::in_min(3.), Power::new(800.)).m(),
r2nd <= Magnitude::EPSILON,
);
assert_float_eq!(
800.,
energy.calc_power(Time::in_min(3.)).m(),
r2nd <= Magnitude::EPSILON
);
assert_float_eq!(800., energy.calc_power(Time::in_min(3.)).m(), r2nd <= Magnitude::EPSILON);
assert_float_eq!(
Time::in_min(3.).m,
energy.calc_time(Power::new(800.)).m(),
Expand Down
14 changes: 3 additions & 11 deletions src/units/force.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,7 @@ mod tests {
assert_float_eq!(10., force.m(), r2nd <= Magnitude::EPSILON);
assert_float_eq!(
5.,
force
.calc_mass(Acceleration::new(Direction::new(2., 0., 0.)))
.m(),
force.calc_mass(Acceleration::new(Direction::new(2., 0., 0.))).m(),
r2nd <= Magnitude::EPSILON
);
assert_float_eq!(
Expand All @@ -161,15 +159,9 @@ mod tests {
assert_float_eq!(30., force.m(), r2nd <= Magnitude::EPSILON);
assert_float_eq!(
0.2,
force
.calc_distance(Moment::new(Direction::new(6., 0., 0.)))
.m(),
r2nd <= Magnitude::EPSILON
);
assert_float_eq!(
6.,
force.calc_moment(Length::new(0.2)).m(),
force.calc_distance(Moment::new(Direction::new(6., 0., 0.))).m(),
r2nd <= Magnitude::EPSILON
);
assert_float_eq!(6., force.calc_moment(Length::new(0.2)).m(), r2nd <= Magnitude::EPSILON);
}
}
Loading

0 comments on commit c9c6b33

Please sign in to comment.