mirror of
				https://github.com/rm-dr/daisy
				synced 2025-11-04 02:02:57 -08:00 
			
		
		
		
	Added no_space parameter for units
This commit is contained in:
		@@ -31,6 +31,7 @@ fn write_wholeunit_main(mut file: &File, units: &Vec<Value>) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	writeln!(file, "}}\n").unwrap();
 | 
						writeln!(file, "}}\n").unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// ToString
 | 
				
			||||||
	writeln!(file,
 | 
						writeln!(file,
 | 
				
			||||||
		concat!(
 | 
							concat!(
 | 
				
			||||||
			"impl ToString for WholeUnit {{\n",
 | 
								"impl ToString for WholeUnit {{\n",
 | 
				
			||||||
@@ -47,7 +48,30 @@ fn write_wholeunit_main(mut file: &File, units: &Vec<Value>) {
 | 
				
			|||||||
		).unwrap();
 | 
							).unwrap();
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	writeln!(file, "\t\t}})\n\t}}\n}}").unwrap();
 | 
						writeln!(file, "\t\t}})\n\t}}\n}}\n").unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// Properties
 | 
				
			||||||
 | 
						writeln!(file,
 | 
				
			||||||
 | 
							concat!(
 | 
				
			||||||
 | 
								"impl WholeUnit {{\n",
 | 
				
			||||||
 | 
								"\tfn no_space(&self) -> bool {{\n",
 | 
				
			||||||
 | 
								"\t\tmatch self {{"
 | 
				
			||||||
 | 
							)
 | 
				
			||||||
 | 
						).unwrap();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						for u in units {
 | 
				
			||||||
 | 
							if u.as_table().unwrap().contains_key("no_space") {
 | 
				
			||||||
 | 
								if u.as_table().unwrap()["no_space"].as_bool().unwrap() {
 | 
				
			||||||
 | 
									writeln!(file,
 | 
				
			||||||
 | 
										"\t\t\tWholeUnit::{} => true,",
 | 
				
			||||||
 | 
										u["enum_name"].as_str().unwrap()
 | 
				
			||||||
 | 
									).unwrap();
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						writeln!(file, "\t\t\t_ => false\n\t\t}}\n\t}}\n}}").unwrap();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -223,9 +247,6 @@ fn write_freeunit_from_string(mut file: &File, units: &Vec<Value>) {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn main() -> Result<(), ()>{
 | 
					fn main() -> Result<(), ()>{
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	let out_dir = env::var_os("OUT_DIR").unwrap();
 | 
						let out_dir = env::var_os("OUT_DIR").unwrap();
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -318,10 +318,18 @@ impl Operator {
 | 
				
			|||||||
				};
 | 
									};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
				if no_times {
 | 
									if no_times {
 | 
				
			||||||
					return format!("{} {}",
 | 
										let Token::Quantity(u) = b else {panic!()};
 | 
				
			||||||
						self.add_parens_to_arg_strict(a),
 | 
										if u.unit.no_space() {
 | 
				
			||||||
						self.add_parens_to_arg_strict(b)
 | 
											return format!("{}{}",
 | 
				
			||||||
					);
 | 
												self.add_parens_to_arg_strict(a),
 | 
				
			||||||
 | 
												self.add_parens_to_arg_strict(b)
 | 
				
			||||||
 | 
											);
 | 
				
			||||||
 | 
										} else {
 | 
				
			||||||
 | 
											return format!("{} {}",
 | 
				
			||||||
 | 
												self.add_parens_to_arg_strict(a),
 | 
				
			||||||
 | 
												self.add_parens_to_arg_strict(b)
 | 
				
			||||||
 | 
											);
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
				} else {
 | 
									} else {
 | 
				
			||||||
					return format!("{} × {}",
 | 
										return format!("{} × {}",
 | 
				
			||||||
						self.add_parens_to_arg_strict(a),
 | 
											self.add_parens_to_arg_strict(a),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -29,7 +29,11 @@ impl ToString for Quantity {
 | 
				
			|||||||
		let u = self.unit.to_string();
 | 
							let u = self.unit.to_string();
 | 
				
			||||||
		if self.is_one() { return u; };
 | 
							if self.is_one() { return u; };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return format!("{n} {u}");
 | 
							if self.unit.no_space() {
 | 
				
			||||||
 | 
								return format!("{n}{u}");
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								return format!("{n} {u}");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -39,7 +43,11 @@ impl Quantity {
 | 
				
			|||||||
		if self.unitless() { return n; }
 | 
							if self.unitless() { return n; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		let u = self.unit.to_string();
 | 
							let u = self.unit.to_string();
 | 
				
			||||||
		return format!("{n} {u}");
 | 
							if self.unit.no_space() {
 | 
				
			||||||
 | 
								return format!("{n}{u}");
 | 
				
			||||||
 | 
							} else {
 | 
				
			||||||
 | 
								return format!("{n} {u}");
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pub fn new_float(f: f64) -> Option<Quantity> {
 | 
						pub fn new_float(f: f64) -> Option<Quantity> {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -86,6 +86,12 @@ impl Unit {
 | 
				
			|||||||
	pub fn get_val_mut(&mut self) -> &mut HashMap<FreeUnit, Scalar> { &mut self.val }
 | 
						pub fn get_val_mut(&mut self) -> &mut HashMap<FreeUnit, Scalar> { &mut self.val }
 | 
				
			||||||
	pub fn unitless(&self) -> bool { self.get_val().len() == 0 }
 | 
						pub fn unitless(&self) -> bool { self.get_val().len() == 0 }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						pub fn no_space(&self) -> bool {
 | 
				
			||||||
 | 
							if self.get_val().len() == 1 {
 | 
				
			||||||
 | 
								return self.get_val().keys().next().unwrap().whole.no_space();
 | 
				
			||||||
 | 
							} else { return false; }
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	pub fn from_array(a: &[(FreeUnit, Scalar)]) -> Unit {
 | 
						pub fn from_array(a: &[(FreeUnit, Scalar)]) -> Unit {
 | 
				
			||||||
		let mut n = Unit::new();
 | 
							let mut n = Unit::new();
 | 
				
			||||||
		for (u, p) in a.iter() {
 | 
							for (u, p) in a.iter() {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user