| 1 |
/** |
|---|
| 2 |
XXX |
|---|
| 3 |
|
|---|
| 4 |
Authors: Daniel Keep |
|---|
| 5 |
Copyright: 2006, Daniel Keep |
|---|
| 6 |
License: BSD v2 (http://opensource.org/licenses/bsd-license.php). |
|---|
| 7 |
**/ |
|---|
| 8 |
/** |
|---|
| 9 |
Copyright © 2006 Daniel Keep |
|---|
| 10 |
All rights reserved. |
|---|
| 11 |
|
|---|
| 12 |
Redistribution and use in source and binary forms, with or without |
|---|
| 13 |
modification, are permitted provided that the following conditions are |
|---|
| 14 |
met: |
|---|
| 15 |
|
|---|
| 16 |
* Redistributions of source code must retain the above copyright |
|---|
| 17 |
notice, this list of conditions and the following disclaimer. |
|---|
| 18 |
|
|---|
| 19 |
* Redistributions in binary form must reproduce the above copyright |
|---|
| 20 |
notice, this list of conditions and the following disclaimer in the |
|---|
| 21 |
documentation and/or other materials provided with the distribution. |
|---|
| 22 |
|
|---|
| 23 |
* Neither the name of this software, nor the names of its contributors |
|---|
| 24 |
may be used to endorse or promote products derived from this software |
|---|
| 25 |
without specific prior written permission. |
|---|
| 26 |
|
|---|
| 27 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|---|
| 28 |
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
|---|
| 29 |
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|---|
| 30 |
PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|---|
| 31 |
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|---|
| 32 |
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|---|
| 33 |
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|---|
| 34 |
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|---|
| 35 |
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|---|
| 36 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|---|
| 37 |
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|---|
| 38 |
**/ |
|---|
| 39 |
module cairooo.matrix; |
|---|
| 40 |
|
|---|
| 41 |
private |
|---|
| 42 |
{ |
|---|
| 43 |
import cairo.cairo; |
|---|
| 44 |
import cairooo.enums; |
|---|
| 45 |
import cairooo.exceptions; |
|---|
| 46 |
} |
|---|
| 47 |
|
|---|
| 48 |
struct Matrix |
|---|
| 49 |
{ |
|---|
| 50 |
double xx, yx, xy, yy, x0, y0; |
|---|
| 51 |
|
|---|
| 52 |
static Matrix |
|---|
| 53 |
init(double xx, double yx, double xy, double yy, double x0, double y0) |
|---|
| 54 |
{ |
|---|
| 55 |
Matrix result; |
|---|
| 56 |
cairo_matrix_init(result.toPtr, xx, yx, xy, yy, x0, y0); |
|---|
| 57 |
return result; |
|---|
| 58 |
} |
|---|
| 59 |
|
|---|
| 60 |
static Matrix |
|---|
| 61 |
initIdentity() |
|---|
| 62 |
{ |
|---|
| 63 |
Matrix result; |
|---|
| 64 |
cairo_matrix_init_identity(result.toPtr); |
|---|
| 65 |
return result; |
|---|
| 66 |
} |
|---|
| 67 |
|
|---|
| 68 |
static Matrix |
|---|
| 69 |
initTranslate(double tx, double ty) |
|---|
| 70 |
{ |
|---|
| 71 |
Matrix result; |
|---|
| 72 |
cairo_matrix_init_translate(result.toPtr, tx, ty); |
|---|
| 73 |
return result; |
|---|
| 74 |
} |
|---|
| 75 |
|
|---|
| 76 |
static Matrix |
|---|
| 77 |
initScale(double sx, double sy) |
|---|
| 78 |
{ |
|---|
| 79 |
Matrix result; |
|---|
| 80 |
cairo_matrix_init_scale(result.toPtr, sx, sy); |
|---|
| 81 |
return result; |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
static Matrix |
|---|
| 85 |
initRotate(double radians) |
|---|
| 86 |
{ |
|---|
| 87 |
Matrix result; |
|---|
| 88 |
cairo_matrix_init_rotate(result.toPtr, radians); |
|---|
| 89 |
return result; |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|
| 92 |
void |
|---|
| 93 |
invert() |
|---|
| 94 |
{ |
|---|
| 95 |
checkStatus(cairo_matrix_invert(this.toPtr)); |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
static Matrix |
|---|
| 99 |
multiply(Matrix a, Matrix b) |
|---|
| 100 |
{ |
|---|
| 101 |
Matrix result; |
|---|
| 102 |
cairo_matrix_multiply(result.toPtr, a.toPtr, b.toPtr); |
|---|
| 103 |
return result; |
|---|
| 104 |
} |
|---|
| 105 |
|
|---|
| 106 |
void |
|---|
| 107 |
transformDistance(inout double dx, inout double dy) |
|---|
| 108 |
{ |
|---|
| 109 |
cairo_matrix_transform_distance(this.toPtr, &dx, &dy); |
|---|
| 110 |
} |
|---|
| 111 |
|
|---|
| 112 |
void |
|---|
| 113 |
transformPoint(inout double x, inout double y) |
|---|
| 114 |
{ |
|---|
| 115 |
cairo_matrix_transform_point(this.toPtr, &x, &y); |
|---|
| 116 |
} |
|---|
| 117 |
|
|---|
| 118 |
Matrix |
|---|
| 119 |
opMul(Matrix other) |
|---|
| 120 |
{ |
|---|
| 121 |
return Matrix.multiply(*this, other); |
|---|
| 122 |
} |
|---|
| 123 |
|
|---|
| 124 |
cairo_matrix_t* |
|---|
| 125 |
toPtr() |
|---|
| 126 |
{ |
|---|
| 127 |
return cast(cairo_matrix_t*) this; |
|---|
| 128 |
} |
|---|
| 129 |
|
|---|
| 130 |
static Matrix |
|---|
| 131 |
fromPtr(cairo_matrix_t* ptr) |
|---|
| 132 |
{ |
|---|
| 133 |
//return cast(Matrix) (*ptr); |
|---|
| 134 |
return *(cast(Matrix*)ptr); |
|---|
| 135 |
} |
|---|
| 136 |
} |
|---|