#[repr(C)]pub struct Point {
pub x: f32,
pub y: f32,
}
Expand description
A point.
Doesn’t guarantee to be finite.
Fields§
§x: f32
§y: f32
Implementations§
source§impl Point
impl Point
sourcepub fn from_xy(x: f32, y: f32) -> Point
pub fn from_xy(x: f32, y: f32) -> Point
Creates a new Point
.
Examples found in repository?
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
fn main() {
let mut paint = Paint::default();
paint.anti_alias = false;
paint.shader = LinearGradient::new(
Point::from_xy(100.0, 100.0),
Point::from_xy(900.0, 900.0),
vec![
GradientStop::new(0.0, Color::from_rgba8(50, 127, 150, 200)),
GradientStop::new(1.0, Color::from_rgba8(220, 140, 75, 180)),
],
SpreadMode::Pad,
Transform::identity(),
)
.unwrap();
let mut pb = PathBuilder::new();
pb.move_to(60.0, 60.0);
pb.line_to(160.0, 940.0);
pb.cubic_to(380.0, 840.0, 660.0, 800.0, 940.0, 800.0);
pb.cubic_to(740.0, 460.0, 440.0, 160.0, 60.0, 60.0);
pb.close();
let path = pb.finish().unwrap();
let mut pixmap = Pixmap::new(1000, 1000).unwrap();
pixmap.fill_path(
&path,
&paint,
FillRule::Winding,
Transform::identity(),
None,
);
pixmap.save_png("image.png").unwrap();
}
sourcepub fn from_f32x2(r: f32x2) -> Point
pub fn from_f32x2(r: f32x2) -> Point
Creates a new Point
from f32x2
.
sourcepub fn is_finite(&self) -> bool
pub fn is_finite(&self) -> bool
Returns true if both x and y are measurable values.
Both values are other than infinities and NaN.
sourcepub fn normalize(&mut self) -> bool
pub fn normalize(&mut self) -> bool
Scales (fX, fY) so that length() returns one, while preserving ratio of fX to fY, if possible.
If prior length is nearly zero, sets vector to (0, 0) and returns false; otherwise returns true.
sourcepub fn set_normalize(&mut self, x: f32, y: f32) -> bool
pub fn set_normalize(&mut self, x: f32, y: f32) -> bool
Sets vector to (x, y) scaled so length() returns one, and so that (x, y) is proportional to (x, y).
If (x, y) length is nearly zero, sets vector to (0, 0) and returns false; otherwise returns true.
sourcepub fn set_length(&mut self, length: f32) -> bool
pub fn set_length(&mut self, length: f32) -> bool
Scales vector so that distanceToOrigin() returns length, if possible.
If former length is nearly zero, sets vector to (0, 0) and return false; otherwise returns true.
sourcepub fn set_length_from(&mut self, x: f32, y: f32, length: f32) -> bool
pub fn set_length_from(&mut self, x: f32, y: f32, length: f32) -> bool
Sets vector to (x, y) scaled to length, if possible.
If former length is nearly zero, sets vector to (0, 0) and return false; otherwise returns true.
sourcepub fn cross(&self, other: Point) -> f32
pub fn cross(&self, other: Point) -> f32
Returns the cross product of vector and vec.
Vector and vec form three-dimensional vectors with z-axis value equal to zero. The cross product is a three-dimensional vector with x-axis and y-axis values equal to zero. The cross product z-axis component is returned.
Trait Implementations§
source§impl AddAssign for Point
impl AddAssign for Point
source§fn add_assign(&mut self, other: Point)
fn add_assign(&mut self, other: Point)
+=
operation. Read moresource§impl MulAssign for Point
impl MulAssign for Point
source§fn mul_assign(&mut self, other: Point)
fn mul_assign(&mut self, other: Point)
*=
operation. Read moresource§impl PartialEq for Point
impl PartialEq for Point
source§impl SubAssign for Point
impl SubAssign for Point
source§fn sub_assign(&mut self, other: Point)
fn sub_assign(&mut self, other: Point)
-=
operation. Read more