pub struct Point2D {
    /// The x point on the field.
    x: Bytes,
    /// The y point on the field.
    y: Bytes,
}
Expand description

A 2D point on a field.

Additional Information

The Point2D type only supports positive integer points.

Fields

x: Bytes

The x point on the field.

y: Bytes

The y point on the field.

Implementations

pub fn new() -> Self

Returns a new, uninitialized Point2D.

Returns

  • [Point2D] - The new Point2D.

Examples

use std::point2d::Point2D;

fn foo() {
    let new_point = Point2D::new();
}

pub fn zero() -> Self

Returns a zeroed Point2D.

Returns

  • [Point2D] - The new zeroed Point2D.

Examples

use std::point2d::Point2D;

fn foo() {
    let zero_point = Point2D::zero();
    assert(b256::try_from(new_point.x()).unwrap() == b256::zero());
    assert(b256::try_from(new_point.y()).unwrap() == b256::zero());
}

pub fn is_zero(self) -> bool

Returns true if the point is (0, 0), otherwise false.

Returns

Examples

use std::point2d::Point2D;

fn foo() {
    let zero_point = Point2D::zero();
    assert(zero_point.is_zero());
}

pub fn min() -> Self

Returns the minimum point.

Returns

  • [Point2D] - The new minimum Point2D.

Examples

use std::point2d::Point2D;

fn foo() {
    let zero_point = Point2D::zero();
    assert(b256::try_from(new_point.x()).unwrap() == b256::zero());
    assert(b256::try_from(new_point.y()).unwrap() == b256::zero());
}

pub fn x(self) -> Bytes

Returns the underlying x point as bytes.

Returns

  • [Bytes] - The x point represented as bytes.

Examples

use std::point2d::Point2D;

fn foo(point: Point2D) {
    let x = point.x();
    assert(x.len() != 0);
}

pub fn y(self) -> Bytes

Returns the underlying y point as bytes.

Returns

  • [Bytes] - The y point represented as bytes.

Examples

use std::point2d::Point2D;

fn foo(point: Point2D) {
    let y = point.y();
    assert(y.len() != 0);
}

Trait Implementations

pub fn abi_encode(self, buffer: Buffer) -> Buffer

pub fn abi_decode(refmut buffer: BufferReader) -> Self

pub fn eq(self, other: Self) -> bool

pub fn neq(self, other: Self) -> bool

Evaluates if two values of the same type are not equal.

Additional Information

This function is inherited when eq() is implemented.

Arguments

  • other: [Self] - The value of the same type.

Returns

  • [bool] - true if the two values are not equal, otherwise false.

Examples

struct MyStruct {
    val: u64,
}

impl Eq for MyStruct {
    fn eq(self, other: Self) -> bool {
         self.val == other.val
    }
}

fn foo() {
    let struct1 = MyStruct { val: 10 };
    let struct2 = MyStruct { val: 2 };
    let result = struct1 != struct2;
    assert(result);
}

pub fn from(bytes: [u256; 2]) -> Self

pub fn from(bytes: [b256; 2]) -> Self

pub fn from(bytes: (b256, b256)) -> Self

pub fn from(bytes: (u256, u256)) -> Self

pub fn from(bytes: [u8; 64]) -> Self