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§

Examples found in repository?
src/component.rs (line 163)
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 => {}
    }
}

Make a point from its x and y position and type

Make a point from its x and y position, handles and type

Make a point from its x and y position, handles and type

Examples found in repository?
src/point.rs (line 213)
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
Hide additional examples
src/point/valid.rs (line 48)
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
    }

Return an x, y position for a point, or one of its handles. If called with WhichHandle::Neither, return position for point.

Examples found in repository?
src/point/conv.rs (line 15)
14
15
16
17
    pub fn from_handle<PD: PointData>(point: &Point<PD>, wh: WhichHandle) -> Self {
        let (x, y) = point.handle_or_colocated(wh, &|f| f, &|f| f);
        GlifPoint::from_x_y_type((x, y), PointType::OffCurve)
    }
Examples found in repository?
src/point.rs (line 233)
232
233
234
235
236
237
238
239
240
241
242
    pub fn handle_as_point(&self, which: WhichHandle) -> Self {
        (&self.handle_as_gpoint(which)).into()
    }

    pub fn handle_as_kpoint(
        &self,
        which: WhichHandle,
    ) -> KurboPoint {
        let p = self.handle_as_gpoint(which);
        KurboPoint::new(f64::from(p.x), f64::from(p.y))
    }

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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Converts to this type from the input type.

Warning: you lose handles with this.

Converts to this type from the input type.
Converts to this type from the input type.

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, but removing that’s TODO. This API will change when that does and should be considered unstable/testing.

This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.