Skip to main content

motion_core/
drawing.rs

1//! Logical drawing contracts and bounded rectangle/path fill commands.
2
3mod atmosphere;
4mod blend;
5mod canvas;
6mod clip;
7mod command;
8mod context;
9mod evaluation;
10pub mod mesh;
11pub mod paint;
12mod stroke;
13
14pub use crate::shape::{Shape, Styled};
15pub use atmosphere::{AtmosphereKind, AtmospherePaint, AtmosphereParameters};
16pub use blend::{BlendMode, BlendSpace, FillRule, MaskMode};
17pub use canvas::Canvas;
18pub use clip::{ClipGeometry, ClipMode, IntoShapeClip, PathClip, RectClip, ShapeClip};
19pub use command::DrawCommand;
20pub use context::{DeferredContent, DrawContext, Drawable, RenderQuality};
21pub use evaluation::Evaluation;
22
23pub use mesh::{
24    MAX_MESH_POINTS_PER_AXIS, MAX_MESH_SUBDIVISIONS, MeshGradient, MeshImage, MeshPaint, MeshPatch,
25    MeshVertex,
26};
27pub use paint::{
28    GradientExtend, GradientSpace, GradientUnits, ImagePattern, LinearGradient, Paint,
29    PatternImage, RadialGradient, SweepGradient, WeakPatternImage,
30};
31pub use stroke::{LineCap, LineJoin, MAX_STROKE_VERBS, StrokeStyle};
32
33use std::sync::Arc;
34
35use crate::validation::ValidationState;
36use crate::{Path2D, Rect, Transform, ValidationError, ValidationLimits};
37
38/// Rejects nonfinite/inverted corners or nonfinite spans; zero-area rectangles are valid.
39pub fn validate_rect(bounds: Rect, path: &str, field: &str) -> Result<(), ValidationError> {
40    if !bounds.is_finite()
41        || bounds.right < bounds.left
42        || bounds.bottom < bounds.top
43        || !bounds.width().is_finite()
44        || !bounds.height().is_finite()
45    {
46        return Err(ValidationError::invalid(
47            path,
48            field,
49            "Require finite, noninverted rectangle bounds and finite spans",
50        ));
51    }
52    Ok(())
53}
54
55#[cfg(test)]
56mod tests;