Databases are used by many of today’s applications,
Transactions are used to
A couple of interview topics are less common than those we’ve
A computer screen consists of pixels arranged in a Cartesian coordinate system. This is commonly called a
raster pixel display
. Computer graphics algorithms change the colors of sets of pixels. Often, the algorithm for generating a raster pixel image is based on a geometric equation. Because a computer screen has a finite number of pixels, translating from a geometric equation to a pixel display can be quite complex. Geometric equations usually have real-number (floating-point) solutions, but pixels are found only at fixed, regularly
Consider something as simple as drawing a line segment, for example. Suppose you were trying to implement a function that takes two endpoints and draws a line between them. After doing a little algebra, you could easily get an equation in the form of y = mx + b . Then, you could calculate y for a range of x values and draw the points making up the line. This function seems trivial.
Even this won’t solve all your problems. Suppose you need to draw a line with a slope of 1 - for example, y = x . In this case, using either procedure, you would draw the pixels (0, 0), (1, 1), (2, 2) … . This is mathematically correct, but the line looks too thin on the screen because the pixels are much more spread out than in other lines. A diagonal line of length 100 has fewer pixels in it than a horizontal line of length 80. An ideal line-drawing algorithm would have some mechanism to guarantee that all lines have nearly equal pixel density.
Another problem involves rounding. If you calculate a point at (.99, .99) and use a type cast to convert this to integers, then the floating-point values will be truncated and the pixel will be drawn at (0, 0). You need to explicitly round the values so that the point is drawn at (1, 1).
If graphics problems seem like
Computer graphics involves drawing with pixels. Always check for rounding errors, gaps, and special cases.