rectangles

Java Partition Surface into Little Squares

旧街凉风 提交于 2019-12-06 11:50:02
问题 I would like to know if there is any algorithm that does something like this: Given a specific surface it divides it into smaller rectangles of the same size. Something like this example figure: The grey area is the surface, and the red squares is the partition itself. I am thinking if there is a optimized way to do this. A very bad approach would be a for loop in all the pixels and check if there is a rectangle for that specific spot, if not, would create a rectangle, and so on.. Maybe

Paint method java - Rectangle with outline

风格不统一 提交于 2019-12-06 09:12:40
I want to create a wall with a blue line outline and black filling. I have only a blue wall now and I tried a couple of the Graphics methods but wasn't working. public void paint(Graphics g) { g.setColor(Color.blue); g.fillRect(x, y, size, size); } First, override paintComponent , not paint . Second, there's no need to re-invent the wheel like that. Instead, use an existing Swing component (e.g. JPanel ), import java.awt.Color; import java.awt.Dimension; import java.awt.FlowLayout; import javax.swing.BorderFactory; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing

Add rectangle into pdfpcell itextsharp

半腔热情 提交于 2019-12-06 07:09:15
How can I add a rectangle with certain width, height and background color into a PdfPCell using itextsharp? Something like this: PdfPCell cell = new PdfPCell(); Rectangle rectangle = new Rectangle(); rectangle.Width = 50f; rectangle.BackgroundColor = BaseColor.RED; cell.AddElement(cell); Bruno Lowagie The simple answer is: draw the Rectangle as a Form XObject ( PdfTemplate ), wrap it inside an Image object, and add that image to the table. However: there are several ways to do this, and there may be only one way that results in the desired output. That's why I've made you an example: rectangle

Difference (XOR) between two rectangles, as rectangles?

笑着哭i 提交于 2019-12-06 00:34:23
问题 I'm looking for a simple way to calculate the difference between two rectangles. I mean all points which belong to one of the rectangles, but not to both (so it's like XOR). The rectangles are axis-aligned in this case, so there will be only right angles. I believe the difference region can be expressed in 0-4 rectangles (0 if both rectangles are the same, 1 if just one edge is different, 4 in the general case), and I'd like to get the difference region as a list of rectangles. You can also

Determining if a point in a view is within a subviews bounds

萝らか妹 提交于 2019-12-05 22:26:54
问题 Suppose I have a UIView parentView and a subview childView that is rotated at some unknown angle relative to parentView. What is the most efficient way to determine if a point within parentView (I know the coordinates in parentView's coordinate system) is within a rectangle in childView's coordinate system (the rectangle is orthogonal to, but not equal to its bounds and probably not orthogonal to parentView's bounds)? 回答1: Convert the point to the subview's coordinate system and then use

Determining which screen a window is on (by checking where the most surfacearea is located)

拟墨画扇 提交于 2019-12-05 19:55:30
I'm currently determining which screen a window is on, by checking on which screen it's very left-top position is. Now I'd like to change that so that I can find out on which scren the most surface area of the window is to be found. Any ideas how that can be accomplished? Here is my old code: (it simply moves the active window between all available screens when pressing F1) F1:: WinGetPos, X, Y,,, A window := {x:X,y:Y} monitors := GetMonitors() Loop % monitors.MaxIndex() { curMonitor := monitors[A_Index] If IsPointInRectange(window,curMonitor) { nextMonitorIndex := (A_Index = monitors.MaxIndex

How do I draw the outline of a collection of rectangles?

痞子三分冷 提交于 2019-12-05 17:18:39
As part of a project I'm working on I have to store and restore magic wand regions from an image. To obtain the data for storage, I'm utilizing the GetRegionData method. As the specification specifies, this method: Returns a RegionData that represents the information that describes this Region. I store the byte[] kept in the RegionData.Data property in a base64 string, so I can retrieve the RegionData later through a somewhat unconventional method: // This "instantiates" a RegionData object by simply initiating an object and setting the object type pointer to the specified type. //

find all rectangular areas with certain properties in a matrix

眉间皱痕 提交于 2019-12-05 05:34:04
given an n*m matrix with the possible values of 1, 2 and null: . . . . . 1 . . . 1 . . . . . 1 . . . 2 . . . . . . . . 2 . . . 1 . . . . . 1 . . . . . . . . . . . 1 . . 2 . . 2 . . . . . . 1 I am looking for all blocks B (containing all values between (x0,y0) and (x1,y1)) that: contain at least one '1' contain no '2' are not a subset of a another block with the above properties Example: The red, green and blue area all contain an '1', no '2', and are not part of a larger area. There are of course more than 3 such blocks in this picture. I want to find all these blocks. what would be a fast way

How do I see if two rectangles intersect in JavaScript or pseudocode?

风格不统一 提交于 2019-12-05 04:48:22
I have two rectangles which I must return in a function whether they intersect or not. They are represented by [ x0, y0, x1, y1 ] pairs that represent the top-left and bottom-right corner of the rectangles. Alternatively, your solution could be [ x0, y0, width, height ] if its somehow simpler, I can adapt my function's parameter input by it. I tried to see if any of the two corners from rectangle A are included in rectangle B but if A is larger than B and B is partially included in A, it will say it doesn't overlap. Now I could try A and B but this seems to be a bad way to do things. I can't

How to draw a rectangle with a colored border in gnuplot

[亡魂溺海] 提交于 2019-12-05 02:24:42
I would like to draw an empty rectangle in my plot. So far I have: set style rect back fs empty border lt 3 set object 1 rect from 1,1 to 2,2 And I have my rectangle with a dashed line. How do I change the color of the line? lc does not seem to work after border. I also tried with setting a new line style, and border but I was not successful. Thank you! Using lc instead of lt in the code you posted works fine with version 4.6.5: reset set style rect back fs empty border lc rgb '#008800' set object 1 rect from 1,1 to 2,2 lw 5 set object 2 rect from 1,3 to 2,4 lw 5 fs empty border lc rgb '