https://github.com/roeyfuchs/multi_dim_point
A simple multi-dimensional point
https://github.com/roeyfuchs/multi_dim_point
cli multidimensional point rust
Last synced: 5 months ago
JSON representation
A simple multi-dimensional point
- Host: GitHub
- URL: https://github.com/roeyfuchs/multi_dim_point
- Owner: roeyfuchs
- License: mit
- Created: 2021-05-11T15:43:27.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2024-03-22T13:10:09.000Z (over 2 years ago)
- Last Synced: 2025-05-14T08:49:41.859Z (about 1 year ago)
- Topics: cli, multidimensional, point, rust
- Language: Rust
- Homepage: https://crates.io/crates/multi_dim_point
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/RoeyFuchs/multi_dim_point/actions/workflows/rust.yml)
# Multi-Dimensional Point
A simple multi-dimensional point structer, base on a vector.
## Examples
```
use multi_dim_point::Point;
let p1: Point = Point::new(3); // create a 3-dim point, with default values (i32 default = 0).
```
```
use multi_dim_point::Point;
let p1: Point = Point::new_from_vec(&vec![1,2,3]); // create a 3-dim point with values from a vector.
p1.get_value(1) // return a reference to the value in the first dimension.
p1.get_size() // return how many dimensions the point has.
p1.get_vector() // return a reference to the vector that represents the point.
let p2: Point = Point::new_from_vec(&vec![4,5,6]);
let p3: Point = &p1+&p2; // create a new point, adding values in the same dimension (the new point will be 5,7,9).
let p4: Point = &p3-&p2;
let p5: Point = &p4 * &5 // multiply each value in the point.
let p6: Point = &p5 / &5;
p1 == p2; // return false
p1.close(&p2, 10) // return true
```
```
use multi_dim_point::Point;
fn add_f(num1: &i32, num2: &i32) -> i32 {
num1 + num2
}
let p1: Point = Point::new_from_vec(&vec![2, 8, 64, 256, 0]);
let p2: Point = Point::new_from_vec(&vec![2, 8, 14, 6, 0]);
p1.apply_func(&p2, &add_f); // return a vector ([4, 16, 78, 262, 0])
```
See more examples in the documentation.
## License
This code uses crate that under MIT license.