sqrid provides square grid coordinates and related operations, in a single-file create, with no dependencies.
The [Qa
] type represents an absolute position in a square
grid. The type itself receives the height and width of the grid as
const generic parameter.
We should usually create a type alias for the grid size we are using:
```rust use sqrid;
type Qa = sqrid::Qa<6, 7>; ```
Qa
instancesWe can get [Qa
] instances by:
- Using one of the const associated items:
rust
type Qa = sqrid::Qa<6, 7>;
const MyFirst : Qa = Qa::FIRST;
const MyLast : Qa = Qa::LAST;
- Using try_from
with a (i16, i16)
tuple or a tuple reference:
```rust
use std::convert::TryFrom;
use std::error::Error;
type Qa = sqrid::Qa<6, 7>; const MyFirst : Qa = Qa::FIRST;
fn main() -> Result<(), Box
println!("qa1: {}", qa1);
Ok(())
}
- Calling [`Qa::new`], which checks the bounds in const contexts:
rust
type Qa = sqrid::Qa<6, 7>;
const MYFIRST : Qa = Qa::new::<3, 4>();
The following, for instance, doesn't compile:
rust
type Qa = sqrid::Qa<6, 7>;
const MYFIRST : Qa = Qa::new::<12, 4>();
```