Skip to content

Instantly share code, notes, and snippets.

@auroranockert
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save auroranockert/9096768 to your computer and use it in GitHub Desktop.

Select an option

Save auroranockert/9096768 to your computer and use it in GitHub Desktop.
{
"type": "crate",
"name": "cairo",
"children": [
{
"type": "library",
"name": "cairo"
},
{
"type": "module",
"name": "matrix",
"children": [
{
"type": "enum/c",
"name": "InvertStatus",
"values": {
"Success": 0,
"InvalidMatrix": 5
}
},
{
"type": "struct",
"name": "Matrix",
"members": {
"value": "[f64, ..6]"
},
"methods": [
{
"type": "constructor",
"name": "new",
"foreign": "cairo_matrix_init",
"self": 0,
"arguments": {
"xx": "double",
"yx": "double",
"xy": "double",
"yy": "double",
"x0": "double",
"y0": "double"
}
},
{
"type": "constructor",
"name": "identity",
"foreign": "cairo_matrix_init_identity",
"self": 0,
"arguments": {}
},
{
"type": "constructor",
"name": "for_translation",
"foreign": "cairo_matrix_init_translate",
"self": 0,
"arguments": {
"tx": "double",
"ty": "double"
}
},
{
"type": "constructor",
"name": "for_scale",
"foreign": "cairo_matrix_init_scale",
"self": 0,
"arguments": {
"sx": "double",
"sy": "double"
}
},
{
"type": "constructor",
"name": "for_rotation",
"foreign": "cairo_matrix_init_rotate",
"self": 0,
"arguments": {
"radians": "double"
}
},
{
"type": "method",
"name": "translate",
"foreign": "cairo_matrix_translate",
"self": 0,
"arguments": {
"tx": "double",
"ty": "double"
}
},
{
"type": "method",
"name": "scale",
"foreign": "cairo_matrix_scale",
"self": 0,
"arguments": {
"sx": "double",
"sy": "double"
}
},
{
"type": "method",
"name": "rotate",
"foreign": "cairo_matrix_rotate",
"self": 0,
"arguments": {
"radians": "double"
}
},
{
"type": "method",
"name": "transform_distance",
"foreign": "cairo_matrix_transform_distance",
"self": 0,
"inout": {
"1": { "type": "double", "name": "dx", "pass_by": "value" },
"2": { "type": "double", "name": "dy", "pass_by": "value" }
}
},
{
"type": "method",
"name": "transform_point",
"foreign": "cairo_matrix_transform_point",
"self": 0,
"inout": {
"1": { "type": "double", "name": "x", "pass_by": "value" },
"2": { "type": "double", "name": "y", "pass_by": "value" }
}
}
]
}
]
}
]
}
#[link(name = "cairo")]
extern {}
pub mod matrix {
use std;
pub enum InvertStatus {
Success = 0,
InvalidMatrix = 5
}
pub struct Matrix {
value: [f64, ..6]
}
impl Matrix {
pub fn new(xx: f64, yx: f64, xy: f64, yy: f64, x0: f64, y0: f64) -> Matrix {
unsafe {
let mut self_parameter:Matrix = std::unstable::intrinsics::init();
cairo_matrix_init(std::ptr::to_mut_unsafe_ptr(&mut self_parameter), xx, yx, xy, yy, x0, y0);
return self_parameter;
}
}
pub fn identity() -> Matrix {
unsafe {
let mut self_parameter:Matrix = std::unstable::intrinsics::init();
cairo_matrix_init_identity(std::ptr::to_mut_unsafe_ptr(&mut self_parameter));
return self_parameter;
}
}
pub fn for_translation(tx: f64, ty: f64) -> Matrix {
unsafe {
let mut self_parameter:Matrix = std::unstable::intrinsics::init();
cairo_matrix_init_translate(std::ptr::to_mut_unsafe_ptr(&mut self_parameter), tx, ty);
return self_parameter;
}
}
pub fn for_scale(sx: f64, sy: f64) -> Matrix {
unsafe {
let mut self_parameter:Matrix = std::unstable::intrinsics::init();
cairo_matrix_init_scale(std::ptr::to_mut_unsafe_ptr(&mut self_parameter), sx, sy);
return self_parameter;
}
}
pub fn for_rotation(radians: f64) -> Matrix {
unsafe {
let mut self_parameter:Matrix = std::unstable::intrinsics::init();
cairo_matrix_init_rotate(std::ptr::to_mut_unsafe_ptr(&mut self_parameter), radians);
return self_parameter;
}
}
pub fn translate(&mut self, tx: f64, ty: f64) {
unsafe {
cairo_matrix_translate(std::ptr::to_mut_unsafe_ptr(self), tx, ty);
}
}
pub fn scale(&mut self, sx: f64, sy: f64) {
unsafe {
cairo_matrix_scale(std::ptr::to_mut_unsafe_ptr(self), sx, sy);
}
}
pub fn rotate(&mut self, radians: f64) {
unsafe {
cairo_matrix_rotate(std::ptr::to_mut_unsafe_ptr(self), radians);
}
}
pub fn transform_distance(&mut self, dx: f64, dy: f64) -> (f64, f64) {
unsafe {
let mut dx_local = dx;
let mut dy_local = dy;
cairo_matrix_transform_distance(std::ptr::to_mut_unsafe_ptr(self), std::ptr::to_mut_unsafe_ptr(&mut dx_local), std::ptr::to_mut_unsafe_ptr(&mut dy_local));
return (dx_local, dy_local);
}
}
pub fn transform_point(&mut self, x: f64, y: f64) -> (f64, f64) {
unsafe {
let mut x_local = x;
let mut y_local = y;
cairo_matrix_transform_point(std::ptr::to_mut_unsafe_ptr(self), std::ptr::to_mut_unsafe_ptr(&mut x_local), std::ptr::to_mut_unsafe_ptr(&mut y_local));
return (x_local, y_local);
}
}
}
extern {
fn cairo_matrix_init(this: *mut Matrix, xx: f64, yx: f64, xy: f64, yy: f64, x0: f64, y0: f64) -> Matrix;
fn cairo_matrix_init_identity(this: *mut Matrix) -> Matrix;
fn cairo_matrix_init_translate(this: *mut Matrix, tx: f64, ty: f64) -> Matrix;
fn cairo_matrix_init_scale(this: *mut Matrix, sx: f64, sy: f64) -> Matrix;
fn cairo_matrix_init_rotate(this: *mut Matrix, radians: f64) -> Matrix;
fn cairo_matrix_translate(this: *mut Matrix, tx: f64, ty: f64);
fn cairo_matrix_scale(this: *mut Matrix, sx: f64, sy: f64);
fn cairo_matrix_rotate(this: *mut Matrix, radians: f64);
fn cairo_matrix_transform_distance(this: *mut Matrix, dx: *mut f64, dy: *mut f64);
fn cairo_matrix_transform_point(this: *mut Matrix, x: *mut f64, y: *mut f64); }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment