| // Copyright 2016 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| @available(added=7) |
| library fuchsia.math; |
| |
| /// An integer position in a 2D cartesian space. |
| /// |
| /// This type does not specify units. Protocols that use this type should |
| /// specify the characteristics of the vector space, including orientation and |
| /// units. |
| type Point = struct { |
| /// The number of units along the x-axis. |
| x int32; |
| |
| /// The number of units along the y-axis. |
| y int32; |
| }; |
| |
| /// A floating point position in a 2D cartesian space. |
| /// |
| /// This type does not specify units. Protocols that use this type should |
| /// specify the characteristics of the vector space, including orientation and |
| /// units. |
| type PointF = struct { |
| /// The number of units along the x-axis. |
| x float32; |
| |
| /// The number of units along the y-axis. |
| y float32; |
| }; |
| |
| /// A floating point position in a 3D cartesian space. |
| /// |
| /// This type does not specify units. Protocols that use this type should |
| /// specify the characteristics of the vector space, including orientation and |
| /// units. |
| type Point3F = struct { |
| /// The number of units along the x-axis. |
| x float32; |
| |
| /// The number of units along the y-axis. |
| y float32; |
| |
| /// The number of units along the z-axis. |
| z float32; |
| }; |
| |
| /// The integer dimensions of a rectangular region in a 2D cartesian space. |
| /// |
| /// This type does not specify units. Protocols that use this type should |
| /// specify the characteristics of the vector space, including orientation and |
| /// units. |
| /// |
| /// This type allows for negative dimensions, to which protocols can give |
| /// semantics. Protocols that use this type should specify whether negative |
| /// dimensions are meaningful, and, if they are meaningful, what they mean. |
| type Size = struct { |
| /// The distance along the x-axis. |
| width int32; |
| |
| /// The distance along the y-axis. |
| height int32; |
| }; |
| |
| /// The floating point dimensions of a rectangular region in a 2D cartesian |
| /// space. |
| /// |
| /// This type does not specify units. Protocols that use this type should |
| /// specify the characteristics of the vector space, including orientation and |
| /// units. |
| /// |
| /// This type allows for negative dimensions, to which protocols can give |
| /// semantics. Protocols that use this type should specify whether negative |
| /// dimensions are meaningful, and, if they are meaningful, what they mean. |
| type SizeF = struct { |
| /// The distance along the x-axis. |
| width float32; |
| |
| /// The distance along the y-axis. |
| height float32; |
| }; |
| |
| /// The unsigned integer dimensions of a rectangular region in a 2D cartesian |
| /// space. |
| /// |
| /// This type does not specify units. Protocols that use this type should |
| /// specify the characteristics of the vector space, including orientation and |
| /// units. |
| type SizeU = struct { |
| /// The distance along the x-axis. |
| width uint32; |
| |
| /// The distance along the y-axis. |
| height uint32; |
| }; |
| |
| /// Represents a 2D vector with integer coordinates. |
| /// |
| /// This type does not specify units. Protocols that use this type should |
| /// specify the characteristics of the vector space, including orientation and |
| /// units. |
| type Vec = struct { |
| // The direction along the x-axis. |
| x int32; |
| |
| // The direction along the y-axis. |
| y int32; |
| }; |
| |
| /// Represents a 2D vector with floating point coordinates. |
| /// |
| /// This type does not specify units. Protocols that use this type should |
| /// specify the characteristics of the vector space, including orientation and |
| /// units. |
| type VecF = struct { |
| // The direction along the x-axis. |
| x float32; |
| |
| // The direction along the y-axis. |
| y float32; |
| }; |
| |
| /// An integral, rectangular, axis-aligned region in a 2D cartesian |
| /// space. |
| /// |
| /// This type does not specify units. Protocols that use this type should |
| /// specify the characteristics of the vector space, including orientation and |
| /// units. |
| type Rect = struct { |
| /// The location of the origin of the rectangle in the x-axis. |
| x int32; |
| |
| /// The location of the origin of the rectangle in the y-axis. |
| y int32; |
| |
| /// The distance along the x-axis. |
| /// |
| /// If `width` is positive, the region includes x values starting at `x` and |
| /// increasing along the x-axis. If `width` is negative, the region includes |
| /// x values starting at `x` and decreasing along the x-axis. |
| width int32; |
| |
| /// The distance along the y-axis. |
| /// |
| /// If `height` is positive, the region includes y values starting at `y` |
| /// and increasing along the y-axis. If `height` is negative, the region |
| /// includes y values starting at `y` and decreasing along the y-axis. |
| height int32; |
| }; |
| |
| /// A floating point, rectangular, axis-aligned region in a 2D cartesian |
| /// space. |
| /// |
| /// This type does not specify units. Protocols that use this type should |
| /// specify the characteristics of the vector space, including orientation and |
| /// units. |
| type RectF = struct { |
| /// The location of the origin of the rectangle in the x-axis. |
| x float32; |
| |
| /// The location of the origin of the rectangle in the y-axis. |
| y float32; |
| |
| /// The distance along the x-axis. |
| /// |
| /// If `width` is positive, the region includes x values starting at `x` and |
| /// increasing along the x-axis. If `width` is negative, the region includes |
| /// x values starting at `x` and decreasing along the x-axis. |
| width float32; |
| |
| /// The distance along the y-axis. |
| /// |
| /// If `height` is positive, the region includes y values starting at `y` |
| /// and increasing along the y-axis. If `height` is negative, the region |
| /// includes y values starting at `y` and decreasing along the y-axis. |
| height float32; |
| }; |
| |
| /// A floating point rounded rectangle with the custom radii for all four |
| /// corners. |
| /// |
| /// A region in a 2D cartesian space consisting of linear, axis-aligned sides |
| /// with corners rounded into a quarter ellipse. |
| /// |
| /// If the quarter ellipses in two corners would overlap, their radii are |
| /// clamped such that the ellipses meet with an axis-aligned tangent. |
| /// |
| /// This type does not specify units. Protocols that use this type should |
| /// specify the characteristics of the vector space, including orientation and |
| /// units. |
| type RRectF = struct { |
| /// The location of the origin of the region in the x-axis. |
| x float32; |
| |
| /// The location of the origin of the region in the y-axis. |
| y float32; |
| |
| /// The distance along the x-axis. |
| /// |
| /// If `width` is positive, the region includes x values starting at `x` and |
| /// increasing along the x-axis. If `width` is negative, the region includes |
| /// x values starting at `x` and decreasing along the x-axis. |
| width float32; |
| |
| /// The distance along the y-axis. |
| /// |
| /// If `height` is positive, the region includes y values starting at `y` |
| /// and increasing along the y-axis. If `height` is negative, the region |
| /// includes y values starting at `y` and decreasing along the y-axis. |
| height float32; |
| |
| /// The radius of the quarter ellipse in the top-left corner along the |
| /// x-axis. |
| /// |
| /// Must not be negative. |
| top_left_radius_x float32; |
| |
| /// The radius of the quarter ellipse in the top-left corner along the |
| /// y-axis. |
| /// |
| /// Must not be negative. |
| top_left_radius_y float32; |
| |
| /// The radius of the quarter ellipse in the top-right corner along the |
| /// x-axis. |
| /// |
| /// Must not be negative. |
| top_right_radius_x float32; |
| |
| /// The radius of the quarter ellipse in the top-right corner along the |
| /// y-axis. |
| /// |
| /// Must not be negative. |
| top_right_radius_y float32; |
| |
| /// The radius of the quarter ellipse in the bottom-left corner along the |
| /// x-axis. |
| /// |
| /// Must not be negative. |
| bottom_left_radius_x float32; |
| |
| /// The radius of the quarter ellipse in the bottom-left corner along the |
| /// y-axis. |
| /// |
| /// Must not be negative. |
| bottom_left_radius_y float32; |
| |
| /// The radius of the quarter ellipse in the bottom-right corner along the |
| /// x-axis. |
| /// |
| /// Must not be negative. |
| bottom_right_radius_x float32; |
| |
| /// The radius of the quarter ellipse in the bottom-right corner along the |
| /// y-axis. |
| /// |
| /// Must not be negative. |
| bottom_right_radius_y float32; |
| }; |
| |
| /// A projective transformation of a 3D cartesian space. |
| /// |
| /// A transform consists of a 4x4 matrix that operates in homogeneous |
| /// coordinates. For example, a point located at (x, y, z) in the cartesian |
| /// space is transformed by `M` to a point located at (x'/w', y'/w', z'/w'), |
| /// where `(x', y', z', w') = M (x, y, z, 1)`. |
| type Transform = struct { |
| /// The entries in the transformation matrix in row major order. |
| /// |
| /// Specifically, if the matrix is as follows: |
| /// |
| /// ``` |
| /// a b c d |
| /// e f g h |
| /// i j k l |
| /// m n o p |
| /// ``` |
| /// |
| /// then the entries in this array are |
| /// `(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)`. |
| matrix array<float32, 16>; |
| }; |
| |
| /// An integer offset to apply to each edge of a rectangle. |
| /// |
| /// This type does not specify units. Protocols that use this type should |
| /// specify the characteristics of the vector space, including orientation and |
| /// units. |
| type Inset = struct { |
| /// The amount to move the top edge of the rectangle towards the center of |
| /// the rectangle. |
| top int32; |
| |
| /// The amount to move the right edge of the rectangle towards the center of |
| /// the rectangle. |
| right int32; |
| |
| /// The amount to move the bottom edge of the rectangle towards the center |
| /// of the rectangle. |
| bottom int32; |
| |
| /// The amount to move the left edge of the rectangle towards the center of |
| /// the rectangle. |
| left int32; |
| }; |
| |
| /// A floating point offset to apply to each edge of a rectangle. |
| /// |
| /// This type does not specify units. Protocols that use this type should |
| /// specify the characteristics of the vector space, including orientation and |
| /// units. |
| type InsetF = struct { |
| /// The amount to move the top edge of the rectangle towards the center of |
| /// the rectangle. |
| top float32; |
| |
| /// The amount to move the right edge of the rectangle towards the center of |
| /// the rectangle. |
| right float32; |
| |
| /// The amount to move the bottom edge of the rectangle towards the center |
| /// of the rectangle. |
| bottom float32; |
| |
| /// The amount to move the left edge of the rectangle towards the center of |
| /// the rectangle. |
| left float32; |
| }; |