| maptopixel |
(Number x, Number y) |
typedict.Matrix |
| maptopixel |
(Point p) |
|
| |
Returns a user space point close to
(x, y)
that this matrix will map to a pixel in device space.
If one argument is supplied then it should be a
Point
and
maptopixel
returns a point close to
(p.x, p.y)
maptopixel
is not needed by most drawing applications, but occasionally you
may want to guarantee that a shape, like a letter in a font, looks
the same no matter where it is rendered, and in that case
maptopixel
can help.
In fact in many situations, particularly when built-ins like
rcurveto,
rlineto,
and
rmoveto
are used to construct the path, using
maptopixel
for the first point in the path is all that is needed.
Although the implementation details are subject to change without notice,
right now
maptopixel
and the Yoix function
MapToPixel(Point p, Graphics graphics) {
p = graphics.transform(p);
p.x = floor(p.x);
p.y = floor(p.y);
return(graphics.itransform(p));
}
are equivalent, but obviously
maptopixel
is significantly faster (1 built-in call versus 4 plus the function call).
| |
| Example: |
The program,
import yoix.*.*;
JFrame f = {
Color background = Color.white;
Array layout = {
new JCanvas {
int panandzoom = 0x000401;
paint(rect) {
Point p1;
Point p2;
graphics {
gsave();
p1.x = 72;
p1.y = 72;
p2 = maptopixel(p1);
erasedrawable();
setlinewidth(0);
moveto(p1);
rlineto(0, 72);
moveto(p1);
rlineto(72, 0);
setrgbcolor(1, 0, 0);
stroke();
moveto(p2);
rlineto(0, 72);
moveto(p2);
rlineto(72, 0);
setrgbcolor(0, 0, 1);
stroke();
grestore();
}
}
}, CENTER,
};
};
f.visible = TRUE;
creates a point from another one using
maptopixel
and draws the corner of a square in different colors using each of the points.
We set
panandzoom
so you can use the mouse wheel to scroll and button 1 to pan.
As you zoom in and out you sometimes see one pixel wide blue lines
and sometimes you see one pixel wide red and blue lines drawn right
next to each other.
| | |
| Return: |
Point
| | |
| See Also: |
concat,
concatmatrix,
currentmatrix,
dividematrix,
dtransform,
Graphics,
identmatrix,
idtransform,
initmatrix,
invertmatrix,
itransform,
rotate,
scale,
setmatrix,
shear,
transform,
translate
|
|
Yoix is a registered trademark of AT&T Inc.
|