matrix.odin (3841B)
1 // This file is part of Blend2D project <https://blend2d.com> 2 // 3 // See blend2d.h or LICENSE.md for license and copyright information 4 // SPDX-License-Identifier: Zlib 5 package blend2d 6 7 import "core:c" 8 9 when ODIN_OS == .Windows { 10 foreign import lib "blend2d.lib" 11 } else when ODIN_OS == .Darwin { 12 foreign import lib "libblend2d.a" 13 } else when ODIN_OS == .Linux { 14 foreign import lib "libblend2d.a" 15 } 16 17 18 //! Transformation matrix type that can be obtained by calling `BLMatrix2D::type()`. 19 //! 20 //! ``` 21 //! Identity Transl. Scale Swap Affine 22 //! [1 0] [1 0] [. 0] [0 .] [. .] 23 //! [0 1] [0 1] [0 .] [. 0] [. .] 24 //! [0 0] [. .] [. .] [. .] [. .] 25 //! ``` 26 TransformType :: enum u32 { 27 //! Identity matrix. 28 TRANSFORM_TYPE_IDENTITY = 0, 29 30 //! Has translation part (the rest is like identity). 31 TRANSFORM_TYPE_TRANSLATE = 1, 32 33 //! Has translation and scaling parts. 34 TRANSFORM_TYPE_SCALE = 2, 35 36 //! Has translation and scaling parts, however scaling swaps X/Y. 37 TRANSFORM_TYPE_SWAP = 3, 38 39 //! Generic affine matrix. 40 TRANSFORM_TYPE_AFFINE = 4, 41 42 //! Invalid/degenerate matrix not useful for transformations. 43 TRANSFORM_TYPE_INVALID = 5, 44 45 //! Maximum value of `BLTransformType`. 46 TRANSFORM_TYPE_MAX_VALUE = 5, 47 MATRIX2D_TYPE_FORCE_UINT = 4294967295, 48 } 49 50 //! Transformation matrix operation type. 51 TransformOp :: enum u32 { 52 //! Reset matrix to identity (argument ignored, should be nullptr). 53 RESET = 0, 54 55 //! Assign (copy) the other matrix. 56 ASSIGN = 1, 57 58 //! Translate the matrix by [x, y]. 59 TRANSLATE = 2, 60 61 //! Scale the matrix by [x, y]. 62 SCALE = 3, 63 64 //! Skew the matrix by [x, y]. 65 SKEW = 4, 66 67 //! Rotate the matrix by the given angle about [0, 0]. 68 ROTATE = 5, 69 70 //! Rotate the matrix by the given angle about [x, y]. 71 ROTATE_PT = 6, 72 73 //! Transform this matrix by other \ref BLMatrix2D. 74 TRANSFORM = 7, 75 76 //! Post-translate the matrix by [x, y]. 77 POST_TRANSLATE = 8, 78 79 //! Post-scale the matrix by [x, y]. 80 POST_SCALE = 9, 81 82 //! Post-skew the matrix by [x, y]. 83 POST_SKEW = 10, 84 85 //! Post-rotate the matrix about [0, 0]. 86 POST_ROTATE = 11, 87 88 //! Post-rotate the matrix about a reference BLPoint. 89 POST_ROTATE_PT = 12, 90 91 //! Post-transform this matrix by other \ref BLMatrix2D. 92 POST_TRANSFORM = 13, 93 94 //! Maximum value of `BLTransformOp`. 95 MAX_VALUE = 13, 96 FORCE_UINT = 4294967295, 97 } 98 99 @(default_calling_convention="c", link_prefix="bl_") 100 foreign lib { 101 //! \name BLMatrix2D - C API 102 //! 103 //! Functions that initialize and manipulate \ref BLMatrix2D content. 104 //! 105 //! \{ 106 matrix2d_set_identity :: proc(self: ^Matrix2D) -> Result --- 107 matrix2d_set_translation :: proc(self: ^Matrix2D, x: f64, y: f64) -> Result --- 108 matrix2d_set_scaling :: proc(self: ^Matrix2D, x: f64, y: f64) -> Result --- 109 matrix2d_set_skewing :: proc(self: ^Matrix2D, x: f64, y: f64) -> Result --- 110 matrix2d_set_rotation :: proc(self: ^Matrix2D, angle: f64, cx: f64, cy: f64) -> Result --- 111 matrix2d_apply_op :: proc(self: ^Matrix2D, op_type: TransformOp, op_data: rawptr) -> Result --- 112 matrix2d_invert :: proc(dst: ^Matrix2D, src: ^Matrix2D) -> Result --- 113 matrix2d_get_type :: proc(self: ^Matrix2D) -> TransformType --- 114 matrix2d_map_pointd_array :: proc(self: ^Matrix2D, dst: ^Point, src: ^Point, count: c.size_t) -> Result --- 115 } 116 117 //! 2D matrix represents an affine transformation matrix that can be used to transform geometry and images. 118 Matrix2D :: struct { 119 // TODO: Remove the union, keep only m[] array. 120 using _: struct #raw_union { 121 //! Matrix values stored in array. 122 m: [6]f64, 123 124 //! Matrix values that map `m` to named values that can be used directly. 125 using _: struct { 126 m00: f64, 127 m01: f64, 128 m10: f64, 129 m11: f64, 130 m20: f64, 131 m21: f64, 132 }, 133 }, 134 } 135