java - Drawing a 8x8 rectangle becomes a 9x9 rectangle on screen? -


g2.fill(new rectangle2d.double(0, 0, 8, 8)); 

this nicely fills 8x8 rectangle.

but strange things happen when try draw 8x8 rectangle border:

g2.draw(new rectangle2d.double(0, 0, 8,8)); 

this draws rectangle 9x9 rectangle.

enter image description here

but specified should 8 width , 8 height.

i have default stroke width 1.

am overlooking something? maybe better question is: can turn off 8x8 rectangle when calling draw?

the documentation of graphics2d class, in section titled "rendering compatibility issues", says:

the jdk(tm) 1.1 rendering model based on pixelization model specifies coordinates infinitely thin, lying between pixels. drawing operations performed using one-pixel wide pen fills pixel below , right of anchor point on path. jdk 1.1 rendering model consistent capabilities of of existing class of platform renderers need resolve integer coordinates discrete pen must fall on specified number of pixels.

it goes on say:

java 2d api maintains compatibility jdk 1.1 rendering behavior, such legacy operations , existing renderer behavior unchanged under java 2d api. legacy methods map onto general draw , fill methods defined,

so basically, means if java renders line (0,0) (0,8), draw in pixels under 0 coordinate. line (0,8) (8,8) go in pixl right of 8 x coordinate.

 0┌───┬───┬───┬───┬───┬───┬───┬───┬───┐  │ █ │ █ │ █ │ █ │ █ │ █ │ █ │ █ │ █ │ 1├───┼───┼───┼───┼───┼───┼───┼───┼───┤  │ █ │   │   │   │   │   │   │   │ █ │ 2├───┼───┼───┼───┼───┼───┼───┼───┼───┤  │ █ │   │   │   │   │   │   │   │ █ │ 3├───┼───┼───┼───┼───┼───┼───┼───┼───┤  │ █ │   │   │   │   │   │   │   │ █ │ 4├───┼───┼───┼───┼───┼───┼───┼───┼───┤  │ █ │   │   │   │   │   │   │   │ █ │ 5├───┼───┼───┼───┼───┼───┼───┼───┼───┤  │ █ │   │   │   │   │   │   │   │ █ │ 6├───┼───┼───┼───┼───┼───┼───┼───┼───┤  │ █ │   │   │   │   │   │   │   │ █ │ 7├───┼───┼───┼───┼───┼───┼───┼───┼───┤  │ █ │   │   │   │   │   │   │   │ █ │ 8├───┼───┼───┼───┼───┼───┼───┼───┼───┤  │ █ │ █ │ █ │ █ │ █ │ █ │ █ │ █ │ █ │  └───┴───┴───┴───┴───┴───┴───┴───┴───┘  0   1   2   3   4   5   6   7   8       

thus, using draw around 8x8 rectangle draws 2 lines inside rectangle, , 2 outside it.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -