public class PixelDrawing extends Object implements PixerFactory
Graphics
, but renders only to
a one-bit-per-pixel bitmap. After drawings have been done, the
object can be used as a PixerFactory
to get a list of the pixels
which have been hit at least once by one of the drawing methods called
during the life of the object. Pixels will not be repeated in this list.
The drawing methods are intended to be as efficient as possible. Bounds checking is done, so it is generally not problematic (or inefficient) to attempt drawing operations with coordinates far outside the drawing's range.
Constructor and Description |
---|
PixelDrawing(int x0,
int y0,
int width,
int height)
Constructs a drawing with bounds given explicitly.
|
PixelDrawing(Rectangle bounds)
Constructs a drawing with bounds given by a rectangle.
|
Modifier and Type | Method and Description |
---|---|
void |
addPixel(int x,
int y)
Adds a single pixel to the list of pixels which have been plotted
if it is within this drawing's bounds.
|
void |
addPixelUnchecked(int x,
int y)
Adds a single pixel to the list of pixels which have been plotted
without bounds checking.
|
boolean |
contains(int x,
int y)
Indicates whether a given position is within the bounds of this
drawing.
|
Pixer |
createPixer()
Returns a Pixer that interrogates this drawing's bitmap.
|
void |
drawEllipse(int x0,
int y0,
int ax,
int ay,
int bx,
int by)
Draws the outline of an ellipse with no restrictions on the alignment
of its axes.
|
void |
drawLine(int x0,
int y0,
int x1,
int y1)
Draws a straight line between two points.
|
void |
drawOval(int x,
int y,
int width,
int height)
Draws the outline of an ellipse with horizontal/vertical axes.
|
void |
fill(Shape shape)
Deprecated.
may be slow for large shapes; use fillPolygon if possible
|
void |
fillEllipse(int x0,
int y0,
int ax,
int ay,
int bx,
int by)
Fills an ellipse with no restrictions on the alignment of its axes.
|
void |
fillOval(int x,
int y,
int width,
int height)
Fills an ellipse with horizontal/vertical axes.
|
void |
fillPolygon(int[] xs,
int[] ys,
int np)
Draws a filled polygon on this drawing.
|
void |
fillRect(int x,
int y,
int width,
int height)
Fills a rectangle.
|
int |
getMaxX()
Returns the highest X value from each created pixer.
|
int |
getMaxY()
Returns the highest Y value from each created pixer.
|
int |
getMinX()
Returns the lowest X value from each created pixer.
|
int |
getMinY()
Returns the lowest Y value from each created pixer.
|
int |
getPixelCount()
Returns the number of pixels over which each created pixer iterates.
|
BitSet |
getPixels()
Returns the pixel mask containing the data for this drawing.
|
public PixelDrawing(Rectangle bounds)
bounds
- rectangle giving the region in which pixels may be
plottedpublic PixelDrawing(int x0, int y0, int width, int height)
x0
- lower bound of X coordinatey0
- upper bound of Y coordinatewidth
- extent in X directionheight
- extent in Y directionpublic void addPixel(int x, int y)
x
- X coordinatey
- Y coordinatepublic void addPixelUnchecked(int x, int y)
x
- X coordinate, must be within this drawing's X boundsy
- Y coordinate, must be within this drawing's Y boundspublic void drawLine(int x0, int y0, int x1, int y1)
x0
- X coordinate of first pointy0
- Y coordinate of first pointx1
- X coordinate of second pointy1
- Y coordinate of second pointGraphics.drawLine(int, int, int, int)
public void fillRect(int x, int y, int width, int height)
x
- X coordinate of top left cornery
- Y coordinate of top left cornerwidth
- widthheight
- heightGraphics.fillRect(int, int, int, int)
public void drawOval(int x, int y, int width, int height)
x
- X coordinate of top left corner of enclosing rectangley
- Y coordinate of top left corner of enclosing rectanglewidth
- width of enclosing rectangleheight
- height of enclosing rectangleGraphics.drawOval(int, int, int, int)
public void fillOval(int x, int y, int width, int height)
x
- X coordinate of top left corner of enclosing rectangley
- Y coordinate of top left corner of enclosing rectanglewidth
- width of enclosing rectangleheight
- height of enclosing rectangleGraphics.drawOval(int, int, int, int)
public void drawEllipse(int x0, int y0, int ax, int ay, int bx, int by)
x0
- X coordinate of ellipse centrey0
- Y coordinate of ellipse centreax
- X component of semi-major (or -minor) axisay
- Y component of semi-major (or -minor) axisbx
- X component of semi-minor (or -major) axisby
- Y component of semi-minor (Or -major) axispublic void fillEllipse(int x0, int y0, int ax, int ay, int bx, int by)
x0
- X coordinate of ellipse centrey0
- Y coordinate of ellipse centreax
- X component of semi-major (or -minor) axisay
- Y component of semi-major (or -minor) axisbx
- X component of semi-minor (or -major) axisby
- Y component of semi-minor (Or -major) axispublic void fillPolygon(int[] xs, int[] ys, int np)
xs
- X coordinates of verticesys
- Y coordinates of verticesnp
- number of vertices@Deprecated public void fill(Shape shape)
shape
- shape to fillGraphics2D.fill(java.awt.Shape)
public boolean contains(int x, int y)
x
- X coordinatey
- Y coordinatepublic BitSet getPixels()
public int getMinX()
PixerFactory
getMinX
in interface PixerFactory
public int getMaxX()
PixerFactory
getMaxX
in interface PixerFactory
public int getMinY()
PixerFactory
getMinY
in interface PixerFactory
public int getMaxY()
PixerFactory
getMaxY
in interface PixerFactory
public int getPixelCount()
PixerFactory
getPixelCount
in interface PixerFactory
public Pixer createPixer()
createPixer
in interface PixerFactory
Copyright © 2024 Central Laboratory of the Research Councils. All Rights Reserved.