Struct glifparser::point::Point
source · pub struct Point<PD: PointData> {
pub x: f32,
pub y: f32,
pub a: Handle,
pub b: Handle,
pub name: Option<String>,
pub ptype: PointType,
pub smooth: bool,
pub data: Option<PD>,
}Expand description
A Skia-friendly point
Fields§
§x: f32§y: f32§a: Handle§b: Handle§name: Option<String>§ptype: PointType§smooth: bool§data: Option<PD>Implementations§
source§impl<PD: PointData> Point<PD>
impl<PD: PointData> Point<PD>
sourcepub fn apply_matrix(&mut self, matrix: Affine)
pub fn apply_matrix(&mut self, matrix: Affine)
Examples found in repository?
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
fn apply_component_rect<PD: PointData>(last: &Node<Component<PD>>, minx: &mut f32, miny: &mut f32, maxx: &mut f32, maxy: &mut f32, final_outline: &mut Outline<PD>) {
let mut matrices = vec![];
matrices.push((*last).data().matrix);
// Climb the tree, building a Vec of matrices for this component
let mut pt = last.parent();
while let Some(parent) = pt {
matrices.push(parent.data().matrix);
pt = parent.parent();
}
match (*last).data().glif.outline {
Some(ref o) => {
let mut to_transform = o.clone();
for i in 0..to_transform.len() {
for j in 0..to_transform[i].len() {
let is_first = i == 0 && j == 0;
let mut p = to_transform[i][j].clone();
if p.x < *minx || is_first { *minx = p.x; }
if p.y < *miny || is_first { *miny = p.y; }
if p.x > *maxx || is_first { *maxx = p.x; }
if p.y > *maxy || is_first { *maxy = p.y; }
for m in &matrices {
p.apply_matrix(*m);
}
to_transform[i][j] = p;
}
}
final_outline.extend(to_transform);
},
None => {}
}
}source§impl<PD: PointData> Point<PD>
impl<PD: PointData> Point<PD>
pub fn new() -> Point<PD>
sourcepub fn from_x_y_type((x, y): (f32, f32), ptype: PointType) -> Point<PD>
pub fn from_x_y_type((x, y): (f32, f32), ptype: PointType) -> Point<PD>
Make a point from its x and y position and type
sourcepub fn from_x_y_a_b_type(
(x, y): (f32, f32),
(a, b): (Handle, Handle),
ptype: PointType
) -> Point<PD>
pub fn from_x_y_a_b_type(
(x, y): (f32, f32),
(a, b): (Handle, Handle),
ptype: PointType
) -> Point<PD>
Make a point from its x and y position, handles and type
sourcepub fn from_fields(
(x, y): (f32, f32),
(a, b): (Handle, Handle),
smooth: bool,
ptype: PointType,
name: Option<String>,
data: Option<PD>
) -> Point<PD>
pub fn from_fields(
(x, y): (f32, f32),
(a, b): (Handle, Handle),
smooth: bool,
ptype: PointType,
name: Option<String>,
data: Option<PD>
) -> Point<PD>
Make a point from its x and y position, handles and type
sourcepub fn handle(&self, which: WhichHandle) -> Handle
pub fn handle(&self, which: WhichHandle) -> Handle
Examples found in repository?
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230
pub fn handle_or_colocated(
&self,
which: WhichHandle,
transform_x: &dyn Fn(f32) -> f32,
transform_y: &dyn Fn(f32) -> f32,
) -> (f32, f32) {
let handle = self.handle(which);
match handle {
Handle::At(x, y) => (transform_x(x), transform_y(y)),
Handle::Colocated => (transform_x(self.x), transform_y(self.y)),
}
}
pub fn handle_as_gpoint(
&self,
which: WhichHandle,
) -> GlifPoint {
let handle = self.handle(which);
let (x, y) = match handle {
Handle::At(x, y) => (x, y),
Handle::Colocated => (self.x, self.y),
};
GlifPoint::from_x_y_type((x, y), PointType::OffCurve)
}More examples
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
fn is_valid(&self) -> bool {
if let Some(pd) = self.data.as_ref() {
if !pd.is_valid() {
return false;
}
}
if self.ptype == PointType::Undefined {
return false;
}
if self.x.is_nan() || self.y.is_subnormal() {
return false;
}
for handle in [self.handle(WhichHandle::A), self.handle(WhichHandle::B)] {
if let Handle::At(hx, hy) = handle {
if hx.is_nan() || hy.is_subnormal() {
return false;
}
}
}
true
}sourcepub fn handle_or_colocated(
&self,
which: WhichHandle,
transform_x: &dyn Fn(f32) -> f32,
transform_y: &dyn Fn(f32) -> f32
) -> (f32, f32)
pub fn handle_or_colocated(
&self,
which: WhichHandle,
transform_x: &dyn Fn(f32) -> f32,
transform_y: &dyn Fn(f32) -> f32
) -> (f32, f32)
Return an x, y position for a point, or one of its handles. If called with WhichHandle::Neither, return position for point.
sourcepub fn handle_as_gpoint(&self, which: WhichHandle) -> GlifPoint
pub fn handle_as_gpoint(&self, which: WhichHandle) -> GlifPoint
pub fn handle_as_point(&self, which: WhichHandle) -> Self
pub fn handle_as_kpoint(&self, which: WhichHandle) -> KurboPoint
sourcepub fn set_handle(&mut self, which: WhichHandle, handle: Handle)
pub fn set_handle(&mut self, which: WhichHandle, handle: Handle)
This function is intended for use by generic functions that can work on either handle, to
decrease the use of macros like move_mirror!(a, b).
Trait Implementations§
source§impl<'de, PD> Deserialize<'de> for Point<PD>where
PD: Deserialize<'de> + Default + PointData,
impl<'de, PD> Deserialize<'de> for Point<PD>where
PD: Deserialize<'de> + Default + PointData,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl<PD: PointData> IsValid for Point<PD>
impl<PD: PointData> IsValid for Point<PD>
source§fn is_valid(&self) -> bool
fn is_valid(&self) -> bool
validate_data parameter allows you to define an is_valid (or whatever) impl on your
PointData struct’s. You can then pass the function while validating the point as e.g.
Some(MyPointData::is_valid). It takes an Option<&PD> so that you have the choice as to
whether it’s valid or not for your type not to be defined; Point.data should probably not
be defined as an Option