use rustfmt.toml

This commit is contained in:
shenjack 2023-04-08 23:57:39 +08:00
parent 4e9cc31401
commit 7f41403b70
7 changed files with 96 additions and 193 deletions

View File

@ -16,9 +16,7 @@ mod types;
use pyo3::prelude::*;
#[pyfunction]
fn get_version_str() -> String {
return "0.2.6.1".to_string();
}
fn get_version_str() -> String { return "0.2.6.1".to_string(); }
#[pyfunction]
fn test_call(py_obj: &PyAny) -> PyResult<bool> {

View File

@ -25,20 +25,14 @@ pub mod data {
#[pymethods]
impl PySR1PartType {
#[getter]
fn get_name(&self) -> String {
self.data.name.clone()
}
fn get_name(&self) -> String { self.data.name.clone() }
#[getter]
fn get_mass(&self) -> f64 {
self.data.mass
}
fn get_mass(&self) -> f64 { self.data.mass }
}
impl PySR1PartType {
pub fn new(data: SR1PartType) -> Self {
Self { data }
}
pub fn new(data: SR1PartType) -> Self { Self { data } }
}
#[pyclass]
@ -60,10 +54,7 @@ pub mod data {
fn as_dict(&self) -> HashMap<String, PySR1PartType> {
let mut dict = HashMap::new();
for part_type in self.part_list.types.iter() {
dict.insert(
part_type.name.clone(),
PySR1PartType::new(part_type.clone()),
);
dict.insert(part_type.name.clone(), PySR1PartType::new(part_type.clone()));
}
dict
}
@ -81,9 +72,7 @@ pub mod data {
#[pyclass]
#[pyo3(name = "SR1Ship_rs")]
#[pyo3(
text_signature = "(file_path = './configs/dock1.xml', part_list = './configs/PartList.xml', ship_name = 'NewShip')"
)]
#[pyo3(text_signature = "(file_path = './configs/dock1.xml', part_list = './configs/PartList.xml', ship_name = 'NewShip')")]
pub struct PySR1Ship {
pub ship: SR1Ship,
pub part_list: SR1PartList,

View File

@ -32,14 +32,7 @@ pub mod camera {
impl CenterCameraRs {
#[new]
#[pyo3(signature = (window, zoom=1.0, dx=1.0, dy=1.0, min_zoom=1.0, max_zoom=1.0))]
pub fn py_new(
window: &PyAny,
zoom: f64,
dx: f64,
dy: f64,
min_zoom: f64,
max_zoom: f64,
) -> PyResult<(Self, CameraRs)> {
pub fn py_new(window: &PyAny, zoom: f64, dx: f64, dy: f64, min_zoom: f64, max_zoom: f64) -> PyResult<(Self, CameraRs)> {
return Ok((
CenterCameraRs {},
CameraRs {
@ -66,14 +59,8 @@ pub mod camera {
Python::with_gil(|py| -> PyResult<()> {
let view = super_.window.getattr(py, intern!(py, "view"))?;
// 获取存储的 view
let x: f64 = super_
.window
.getattr(py, intern!(py, "width"))?
.extract(py)?;
let y: f64 = super_
.window
.getattr(py, intern!(py, "height"))?
.extract(py)?;
let x: f64 = super_.window.getattr(py, intern!(py, "width"))?.extract(py)?;
let y: f64 = super_.window.getattr(py, intern!(py, "height"))?.extract(py)?;
let x: f64 = x / 2.0 / super_.zoom + (super_.dx / super_.zoom);
let y: f64 = y / 2.0 / super_.zoom + (super_.dy / super_.zoom);
// 计算中心点
@ -89,9 +76,7 @@ pub mod camera {
let view_matrix = view_matrix.call_method1(py, intern!(py, "scale"), args)?;
// view_matrix = view_matrix.scale((zoom, zoom, 1))
super_
.window
.setattr(py, intern!(py, "view"), view_matrix)?;
super_.window.setattr(py, intern!(py, "view"), view_matrix)?;
// self.view = view_matrix
Ok(())
})?;
@ -103,14 +88,7 @@ pub mod camera {
impl CameraRs {
#[new]
#[pyo3(signature = (window, zoom=1.0, dx=1.0, dy=1.0, min_zoom=1.0, max_zoom=1.0))]
pub fn py_new(
window: &PyAny,
zoom: f64,
dx: f64,
dy: f64,
min_zoom: f64,
max_zoom: f64,
) -> PyResult<Self> {
pub fn py_new(window: &PyAny, zoom: f64, dx: f64, dy: f64, min_zoom: f64, max_zoom: f64) -> PyResult<Self> {
return Ok(CameraRs {
dx,
dy,
@ -128,9 +106,7 @@ pub mod camera {
}
#[getter]
pub fn get_position(&self) -> (f64, f64) {
return (self.dx, self.dy);
}
pub fn get_position(&self) -> (f64, f64) { return (self.dx, self.dy); }
#[setter]
pub fn set_position(&mut self, value: (f64, f64)) -> () {
@ -139,9 +115,7 @@ pub mod camera {
}
#[getter]
pub fn get_zoom(&self) -> PyResult<f64> {
Ok(self.zoom)
}
pub fn get_zoom(&self) -> PyResult<f64> { Ok(self.zoom) }
#[setter]
pub fn set_zoom(&mut self, value: f64) -> PyResult<()> {
@ -154,10 +128,7 @@ pub mod camera {
let view = self.window.getattr(py, intern!(py, "view"))?;
let x: f64 = self.window.getattr(py, intern!(py, "width"))?.extract(py)?;
let y: f64 = self
.window
.getattr(py, intern!(py, "height"))?
.extract(py)?;
let y: f64 = self.window.getattr(py, intern!(py, "height"))?.extract(py)?;
let x: f64 = x / 2.0 / self.zoom + (self.dx / self.zoom);
let y: f64 = y / 2.0 / self.zoom + (self.dy / self.zoom);
// use to get center of the screen
@ -182,10 +153,7 @@ pub mod camera {
let view = self.window.getattr(py, intern!(py, "view"))?;
let x: f64 = self.window.getattr(py, intern!(py, "width"))?.extract(py)?;
let y: f64 = self
.window
.getattr(py, intern!(py, "height"))?
.extract(py)?;
let y: f64 = self.window.getattr(py, intern!(py, "height"))?.extract(py)?;
let x: f64 = x / 2.0 / self.zoom + (self.dx / self.zoom);
let y: f64 = y / 2.0 / self.zoom + (self.dy / self.zoom);
@ -209,12 +177,7 @@ pub mod camera {
Ok(py_self)
}
pub fn __exit__(
&self,
_exc_type: PyObject,
_exc_value: PyObject,
_traceback: PyObject,
) -> PyResult<()> {
pub fn __exit__(&self, _exc_type: PyObject, _exc_value: PyObject, _traceback: PyObject) -> PyResult<()> {
// println!("exit!");
self.end()?;
return Ok(());

View File

@ -0,0 +1,22 @@
# cargo fmt config
# 最大行长
max_width = 150
# 链式调用的最大长度
chain_width = 100
# 数组的最大长度
array_width = 100
# 函数参数的最大长度
attr_fn_like_width = 100
# 函数调用参数的最大长度
fn_call_width = 80
# 简单函数格式化为单行
fn_single_line = true
# 自动对齐最大长度
enum_discrim_align_threshold = 5
# 是否使用彩色输出
color = "Always"
edition = "2021"

View File

@ -20,9 +20,7 @@ pub fn simluation() -> PyResult<()> {
collider_set.insert(collider);
/* Create the bouncing ball. */
let rigid_body = RigidBodyBuilder::dynamic()
.translation(vector![0.0, 10.0])
.build();
let rigid_body = RigidBodyBuilder::dynamic().translation(vector![0.0, 10.0]).build();
let collider = ColliderBuilder::ball(0.5).restitution(0.7).build();
let ball_body_handle = rigid_body_set.insert(rigid_body);
collider_set.insert_with_parent(collider, ball_body_handle, &mut rigid_body_set);

View File

@ -101,19 +101,13 @@ pub mod part_list {
impl AttachPoints {
#[inline]
pub fn new(attaches: Vec<AttachPoint>) -> Self {
AttachPoints { points: attaches }
}
pub fn new(attaches: Vec<AttachPoint>) -> Self { AttachPoints { points: attaches } }
#[inline]
pub fn insert(&mut self, attach: AttachPoint) {
self.points.push(attach);
}
pub fn insert(&mut self, attach: AttachPoint) { self.points.push(attach); }
#[inline]
pub fn unzip(&self) -> Vec<AttachPoint> {
self.points.clone()
}
pub fn unzip(&self) -> Vec<AttachPoint> { self.points.clone() }
}
#[derive(Debug, Serialize, Deserialize, Copy, Clone)]
@ -294,12 +288,11 @@ pub mod part_list {
explosion_power: Some(0u32),
explosion_size: Some(0u32),
});
let attach_points: Option<Vec<AttachPoint>> =
if let Some(attach_points) = &self.attach_points {
Some(attach_points.unzip())
} else {
None
};
let attach_points: Option<Vec<AttachPoint>> = if let Some(attach_points) = &self.attach_points {
Some(attach_points.unzip())
} else {
None
};
SR1PartType {
id: self.id.clone(),
name: self.name.clone(),
@ -325,16 +318,12 @@ pub mod part_list {
attr: part_attr,
}
}
fn to_raw_part_type(&self) -> RawPartType {
self.clone()
}
fn to_raw_part_type(&self) -> RawPartType { self.clone() }
}
impl RawPartList {
#[inline]
pub fn new(parts: Vec<RawPartType>) -> Self {
RawPartList { part_types: parts }
}
pub fn new(parts: Vec<RawPartType>) -> Self { RawPartList { part_types: parts } }
#[inline]
pub fn from_file(file_name: String) -> Option<RawPartList> {
@ -361,9 +350,7 @@ pub mod part_list {
SR1PartList::part_types_new(types, name)
}
fn to_raw_part_list(&self) -> RawPartList {
return self.clone();
}
fn to_raw_part_list(&self) -> RawPartList { return self.clone(); }
}
#[inline]
@ -544,14 +531,10 @@ pub mod ship {
impl SR1ShipTrait for RawShip {
#[inline]
fn to_sr_ship(&self, name: Option<String>) -> SR1Ship {
todo!()
}
fn to_sr_ship(&self, name: Option<String>) -> SR1Ship { todo!() }
#[inline]
fn to_raw_ship(&self) -> RawShip {
self.clone()
}
fn to_raw_ship(&self) -> RawShip { self.clone() }
}
impl RawShip {

View File

@ -10,15 +10,11 @@ pub mod sr1 {
use std::collections::HashMap;
use crate::sr1_data::part_list::Damage as RawDamage;
use crate::sr1_data::part_list::{
AttachPoint, AttachPoints, Engine, Lander, Rcs, Shape as RawShape, Solar, Tank,
};
use crate::sr1_data::part_list::{AttachPoint, AttachPoints, Engine, Lander, Rcs, Shape as RawShape, Solar, Tank};
use crate::sr1_data::part_list::{RawPartList, RawPartType, SR1PartTypeEnum};
use crate::sr1_data::ship::{
Activate as RawActivate, Connection, Connections, DisconnectedPart as RawDisconnectedPart,
DisconnectedParts as RawDisconnectedParts, Engine as RawEngine, Part as RawPartData,
Parts as RawParts, Pod as RawPod, RawShip, Staging as RawStaging, Step as RawStep,
Tank as RawTank,
Activate as RawActivate, Connection, Connections, DisconnectedPart as RawDisconnectedPart, DisconnectedParts as RawDisconnectedParts,
Engine as RawEngine, Part as RawPartData, Parts as RawParts, Pod as RawPod, RawShip, Staging as RawStaging, Step as RawStep, Tank as RawTank,
};
#[inline]
@ -232,21 +228,13 @@ pub mod sr1 {
impl SR1PartList {
#[inline]
pub fn new(name: String, types: Vec<SR1PartType>) -> Self {
SR1PartList {
name,
cache: None,
types,
}
}
pub fn new(name: String, types: Vec<SR1PartType>) -> Self { SR1PartList { name, cache: None, types } }
pub fn part_types_new(part_types: Vec<SR1PartType>, name: Option<String>) -> Self {
SR1PartList::new(name.unwrap_or("NewPartList".to_string()), part_types)
}
pub fn insert_part(&mut self, part: SR1PartType) -> () {
self.types.insert(0, part);
}
pub fn insert_part(&mut self, part: SR1PartType) -> () { self.types.insert(0, part); }
}
impl SR1PartListTrait for SR1PartList {
@ -270,18 +258,12 @@ pub mod sr1 {
}
impl SR1PartTypeData for SR1PartType {
fn to_sr_part_type(&self) -> SR1PartType {
self.clone()
}
fn to_sr_part_type(&self) -> SR1PartType { self.clone() }
fn to_raw_part_type(&self) -> RawPartType {
let tank: Option<Tank> = match &self.attr {
Some(attr) => match attr {
SR1PartTypeAttr::Tank {
fuel,
dry_mass,
fuel_type,
} => Some(Tank {
SR1PartTypeAttr::Tank { fuel, dry_mass, fuel_type } => Some(Tank {
fuel: *fuel,
dry_mass: *dry_mass,
fuel_type: Some(*fuel_type),
@ -313,11 +295,7 @@ pub mod sr1 {
};
let rcs: Option<Rcs> = match &self.attr {
Some(attr) => match attr {
SR1PartTypeAttr::Rcs {
power,
consumption,
size,
} => Some(Rcs {
SR1PartTypeAttr::Rcs { power, consumption, size } => Some(Rcs {
power: *power,
consumption: *consumption,
size: *size,
@ -328,9 +306,7 @@ pub mod sr1 {
};
let solar: Option<Solar> = match &self.attr {
Some(attr) => match attr {
SR1PartTypeAttr::Solar { charge_rate } => Some(Solar {
charge_rate: *charge_rate,
}),
SR1PartTypeAttr::Solar { charge_rate } => Some(Solar { charge_rate: *charge_rate }),
_ => None,
},
_ => None,
@ -419,9 +395,7 @@ pub mod sr1 {
impl SR1PartDataTrait for SR1PartData {
#[inline]
fn to_sr_part_data(&self) -> SR1PartData {
self.clone()
}
fn to_sr_part_data(&self) -> SR1PartData { self.clone() }
#[inline]
fn to_raw_part_data(&self) -> RawPartData {
@ -472,32 +446,31 @@ pub mod sr1 {
},
_ => None,
};
let (chute_x, chute_y, chute_angle, chute_height, inflate, inflation, deployed, rope) =
match &self.attr {
Some(attr) => match attr {
SR1PartDataAttr::Parachute {
chute_x,
chute_y,
chute_angle,
chute_height,
inflate,
inflation,
deployed,
rope,
} => (
Some(*chute_x),
Some(*chute_y),
Some(*chute_angle),
Some(*chute_height),
Some(bool_to_i8(*inflate)),
Some(bool_to_i8(*inflation)),
Some(bool_to_i8(*deployed)),
Some(bool_to_i8(*rope)),
),
_ => (None, None, None, None, None, None, None, None),
},
let (chute_x, chute_y, chute_angle, chute_height, inflate, inflation, deployed, rope) = match &self.attr {
Some(attr) => match attr {
SR1PartDataAttr::Parachute {
chute_x,
chute_y,
chute_angle,
chute_height,
inflate,
inflation,
deployed,
rope,
} => (
Some(*chute_x),
Some(*chute_y),
Some(*chute_angle),
Some(*chute_height),
Some(bool_to_i8(*inflate)),
Some(bool_to_i8(*inflation)),
Some(bool_to_i8(*deployed)),
Some(bool_to_i8(*rope)),
),
_ => (None, None, None, None, None, None, None, None),
};
},
_ => (None, None, None, None, None, None, None, None),
};
let extension = match &self.attr {
Some(attr) => match attr {
SR1PartDataAttr::Solar { extension } => Some(*extension),
@ -608,9 +581,7 @@ pub mod sr1 {
},
});
}
Some(RawDisconnectedParts {
parts: disconnected_vec,
})
Some(RawDisconnectedParts { parts: disconnected_vec })
}
_ => None,
};
@ -644,14 +615,10 @@ pub mod math {
}
impl Point2D {
pub fn new(x: f64, y: f64) -> Self {
Point2D { x, y }
}
pub fn new(x: f64, y: f64) -> Self { Point2D { x, y } }
#[inline]
pub fn new_00() -> Self {
Point2D { x: 0.0, y: 0.0 }
}
pub fn new_00() -> Self { Point2D { x: 0.0, y: 0.0 } }
#[inline]
pub fn distance(&self, other: &Point2D) -> f64 {
@ -661,16 +628,12 @@ pub mod math {
}
#[inline]
pub fn distance_00(&self) -> f64 {
self.distance(&Point2D::new(0.0, 0.0))
}
pub fn distance_00(&self) -> f64 { self.distance(&Point2D::new(0.0, 0.0)) }
}
impl Rotatable for Point2D {
#[inline]
fn rotate(&self, angle: f64) -> Self {
self.rotate_radius(angle.to_radians())
}
fn rotate(&self, angle: f64) -> Self { self.rotate_radius(angle.to_radians()) }
#[inline]
fn rotate_radius(&self, radius: f64) -> Self {
@ -707,16 +670,9 @@ pub mod math {
}
impl Rotatable for OneTimeLine {
fn rotate(&self, angle: f64) -> Self {
self.rotate_radius(angle.to_radians())
}
fn rotate(&self, angle: f64) -> Self { self.rotate_radius(angle.to_radians()) }
fn rotate_radius(&self, radius: f64) -> Self {
OneTimeLine::point_new(
&self.start.rotate_radius(radius),
&self.end.rotate_radius(radius),
)
}
fn rotate_radius(&self, radius: f64) -> Self { OneTimeLine::point_new(&self.start.rotate_radius(radius), &self.end.rotate_radius(radius)) }
}
#[derive(Clone, Copy)]
@ -802,9 +758,7 @@ pub mod math {
}
#[inline]
pub fn point_new(a: &Point2D, b: &Point2D) -> Self {
OneTimeLine::pos_new(a.x, a.y, b.x, b.y)
}
pub fn point_new(a: &Point2D, b: &Point2D) -> Self { OneTimeLine::pos_new(a.x, a.y, b.x, b.y) }
pub fn point1_k_b_new(point: &Point2D, k: Option<f64>, b: Option<f64>) -> Self {
let mut k_: f64;
@ -833,9 +787,7 @@ pub mod math {
}
}
pub fn point_d() -> f64 {
1.0
}
pub fn point_d() -> f64 { 1.0 }
}
}
@ -890,8 +842,6 @@ pub mod dr {
}
impl DRPartData {
pub fn get_textures(&self) -> String {
"aaa".to_string()
}
pub fn get_textures(&self) -> String { "aaa".to_string() }
}
}