Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# DV - Dimensional Variables

[![main](https://github.com/alextac98/dv/actions/workflows/main.yaml/badge.svg)](https://github.com/alextac98/dv/actions/workflows/main.yaml) ![Crates.io Version](https://img.shields.io/crates/v/dv) ![PyPI - Version](https://img.shields.io/pypi/v/dv_py)
[![main](https://github.com/alextac98/dv/actions/workflows/main.yaml/badge.svg)](https://github.com/alextac98/dv/actions/workflows/main.yaml) [![Crates.io Version](https://img.shields.io/crates/v/dv)](https://crates.io/crates/dv) [![PyPI - Version](https://img.shields.io/pypi/v/dv_py)](https://pypi.org/project/dv-py/)

> [!NOTE]
> Full information, documentation, examples, and more can be found on the project website: https://dv.alextac.com/
Expand Down
2 changes: 1 addition & 1 deletion VERSION.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@

major = 0
minor = 3
patch = 0
patch = 1
2 changes: 1 addition & 1 deletion core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dv"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
authors = [ "Alex Tacescu <alextac98@gmail.com>",]
description = "Core Rust library for DimensionalVariable, a multi-language library for handling physical quantities with units."
Expand Down
17 changes: 16 additions & 1 deletion core/src/units.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn unit_map() -> HashMap<&'static str, Unit> {
("MA", Unit { name: "megaampere", conversion_factor: 1e6, base_unit: [0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0] }),

// ===== Energy Units =====
("ev", Unit { name: "electronvolt", conversion_factor: 1.602176634e-19, base_unit: [2.0, 1.0, -2.0, 0.0, 0.0, 0.0, 0.0, 0.0] }),
("eV", Unit { name: "electronvolt", conversion_factor: 1.602176634e-19, base_unit: [2.0, 1.0, -2.0, 0.0, 0.0, 0.0, 0.0, 0.0] }),
("mJ", Unit { name: "millijoule", conversion_factor: 1e-3, base_unit: [2.0, 1.0, -2.0, 0.0, 0.0, 0.0, 0.0, 0.0] }),
("J", Unit { name: "joule", conversion_factor: 1.0, base_unit: [2.0, 1.0, -2.0, 0.0, 0.0, 0.0, 0.0, 0.0] }),
("kJ", Unit { name: "kilojoule", conversion_factor: 1e3, base_unit: [2.0, 1.0, -2.0, 0.0, 0.0, 0.0, 0.0, 0.0] }),
Expand All @@ -110,6 +110,21 @@ pub fn unit_map() -> HashMap<&'static str, Unit> {
("TW", Unit { name: "terawatt", conversion_factor: 1e12, base_unit: [2.0, 1.0, -3.0, 0.0, 0.0, 0.0, 0.0, 0.0] }),
("hp", Unit { name: "horsepower", conversion_factor: 745.6998715822702, base_unit: [2.0, 1.0, -3.0, 0.0, 0.0, 0.0, 0.0, 0.0] }),

// ===== Electrical Charge Units =====
("Coulomb", Unit { name: "coulomb", conversion_factor: 1.0, base_unit: [0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0] }),
("mC", Unit { name: "millicoulomb", conversion_factor: 1e-3, base_unit: [0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0] }),
("kC", Unit { name: "kilocoulomb", conversion_factor: 1e3, base_unit: [0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 0.0, 0.0] }),

// ===== Electric Potential Units =====
("V", Unit { name: "volt", conversion_factor: 1.0, base_unit: [2.0, 1.0, -3.0, 0.0, -1.0, 0.0, 0.0, 0.0] }),
("mV", Unit { name: "millivolt", conversion_factor: 1e-3, base_unit: [2.0, 1.0, -3.0, 0.0, -1.0, 0.0, 0.0, 0.0] }),
("kV", Unit { name: "kilovolt", conversion_factor: 1e3, base_unit: [2.0, 1.0, -3.0, 0.0, -1.0, 0.0, 0.0, 0.0] }),

// ===== Electric Resistance Units =====
("Ohm", Unit { name: "ohm", conversion_factor: 1.0, base_unit: [2.0, 1.0, -3.0, 0.0, -2.0, 0.0, 0.0, 0.0] }),
("mOhm", Unit { name: "milliohm", conversion_factor: 1e-3, base_unit: [2.0, 1.0, -3.0, 0.0, -2.0, 0.0, 0.0, 0.0] }),
("kOhm", Unit { name: "kiloohm", conversion_factor: 1e3, base_unit: [2.0, 1.0, -3.0, 0.0, -2.0, 0.0, 0.0, 0.0] }),

// ===== Amount of Substance Units =====
("mol", Unit { name: "mole", conversion_factor: 1.0, base_unit: [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0] }),
("kmol", Unit { name: "kilomole", conversion_factor: 1e3, base_unit: [0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0] }),
Expand Down
12 changes: 12 additions & 0 deletions core/tests/units_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,15 @@ fn errors_on_unknown_unit() {
let result = dv::new(1.0, "unknown_unit");
assert!(result.is_err(), "Expected error on unknown unit");
}

#[test]
fn electrical_units() {
let voltage = dv::new(10.0, "V").expect(FAIL_MSG);
let current = dv::new(2.0, "A").expect(FAIL_MSG);
let resistance = dv::new(5.0, "Ohm").expect(FAIL_MSG);

assert!(voltage == &current * &resistance, "Ohm's law failed");

let power = dv::new(20.0, "W").expect(FAIL_MSG);
assert!(power == &voltage * &current, "Power calculation failed");
}
2 changes: 1 addition & 1 deletion python/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "dv_py"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
authors = [ "Alex Tacescu <alextac98@gmail.com>",]
homepage = "https://dv.alextac.com"
Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "maturin"

[project]
name = "dv_py"
version = "0.3.0"
version = "0.3.1"
description = "Python bindings for dv (DimensionalVariable) - keeping track of units and dimensions for physical quantities"
readme = "pip-readme.md"
requires-python = ">=3.8"
Expand Down