Update of /cvsroot/freenet/freenet/src/freenet/support/graph
In directory sc8-pr-cvs1:/tmp/cvs-serv19626/src/freenet/support/graph
Modified Files:
Bitmap.java
Log Message:
Stopped clipping in Bitmap.setPixel(), throw exception instead. With a little luck
this will encourage people in need of cumbersome coordinate-to-pixel mapping to make
it easy for themself by using the Bitmap class viewport facilities to manage their
coordinate conversion.
Made Bitmap.drawPlus() use bitmap ViewPort setting.
Modify viewport coordinate conversion so that valid coordinates is:
viewport_left<=x<viewport_right viewport_bottom<=y<viewport_top. Previously the valid
coordinates was more like
(min+pix_to_viewport_scale*0.5)<=coord<(max-pix_to_viewport_scale*0.5) which is quite
a bit harder to use.
Simplify drawing of estimate()-graphs by using a Bitmap viewport for the coordinate
conversion.
Index: Bitmap.java
===================================================================
RCS file: /cvsroot/freenet/freenet/src/freenet/support/graph/Bitmap.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -w -r1.7 -r1.8
--- Bitmap.java 4 Nov 2003 12:32:11 -0000 1.7
+++ Bitmap.java 14 Nov 2003 10:40:40 -0000 1.8
@@ -86,19 +86,29 @@
}
/**
- * Draws in pixel-array coordinates px,py with the current pen, does clipping.
+ * Draws in pixel-array coordinates px,py with the current pen, does not clip.
*/
public void setPixel(int px, int py) {
if (px >= 0 && px < width && py >= 0 && py < height)
pixels[px][py] = (byte) pen;
+ else
+ throw new IndexOutOfBoundsException("("+px+","+py+") not
inside image of width="+width+" and height="+height);
}
- public void drawPlus(int px, int py) {
- setPixel(px, py);
- setPixel(px - 1, py);
- setPixel(px + 1, py);
- setPixel(px, py - 1);
- setPixel(px, py + 1);
+ //Draws a five-pixel plus centered on the supplied coordinate
+ //Clips the pixel properly and respects scaleView coordinates
+ public void drawPlus(float px, float py) {
+ int x = Math.round(xPix(px));
+ int y = Math.round(yPix(py));
+ setPixel(x, y);
+ if(x-1 >= 0) //dont even try to draw outside the image bounds
+ setPixel(x - 1, y);
+ if(x+1<width)
+ setPixel(x + 1, y);
+ if(y-1>=0)
+ setPixel(x, y - 1);
+ if(y+1<height)
+ setPixel(x, y + 1);
}
public int getPixel(int px, int py) {
@@ -182,11 +192,11 @@
* Be sure to clip based on the rounded result; -0.4 is inside the view box,
-0.6 is not.
*/
private float xPix(float xu) {
- return ((xu - coord.left) / (coord.left - coord.right)) * (0.5f -
(float) width) + 0.49f;
+ return ((xu - coord.left) / (coord.left - coord.right)) * (0.5f -
(float) width);
}
private float yPix(float yu) {
- return ((yu - coord.top) / (coord.top - coord.bottom)) * (0.5f -
(float) height) + 0.49f;
+ return ((yu - coord.top) / (coord.top - coord.bottom)) * (0.5f -
(float) height);
}
byte[][] getPixels() {
_______________________________________________
cvs mailing list
[EMAIL PROTECTED]
http://dodo.freenetproject.org/cgi-bin/mailman/listinfo/cvs