Centered Widget in FLTK - resize

Can you center a non-resizable widget in FLTK? The references from this stackoverflow question seem to imply the answer is no. A centered widget would require resizable widgets on either side, but you can only have one resizable child in a group.
(Sorry for the ask and answer, but I searched all over for this and almost gave up, so I think this will be useful to others.)

Here's how you do it. The trick is that a widget in FLTK can be outside its parent group's borders.
You have 4 groups A, B, C, and D. B and C are children of A. D is a child of C. Not shown is the widget you actually want to have centered, called E. E is a child of C. A and E are the ones you want to actually see. B, C, and D are empty with no border, so they are invisible. A and D are resizable. Nothing else is. Center E in A, not overlapping with D. E will be partially outside of C. That's the trick.
|--------------------------------------------|
| A |
||--------------------||--------------------||
|| || |-----| ||
|| B || C | D | ||
|| || |-----| ||
||--------------------||--------------------||
|--------------------------------------------|
When A is resized, B and C will be resized proportionally and equally, because there are no resizable children of A, and they are the same size. The origin of C will remain in the center of A. When C is resized, E will not be resized, only D. So E will remain in the same position with respect to the origin of C, i.e. with respect to the center of A.
Caveat 1: I have implemented this in FLUID/FLTK 1.3.0, which is admittedly old. Things may have changed since then. I did not attempt to verify this on anything more recent.
Caveat 2: FLUID will automatically resize a group to enclose the widgets within it whenever you move any widget. This breaks the centering behavior. I have found I need to resize C via the FLUID dialog box to the original size, after any other layout changes, every time.

FLTK layout made easier with the header files here: https://fltk-layout-manager.blogspot.com
CoordinateManager()
.set(addrSubject)
.centerTo (void* addrBenefactor)
.render();
You can give a point x, y or the top left and bottom right coordinates:
CoordinateManager()
.set(addrSubject)
.centerTo (int x, int y, int x2 = 0, int y2 = 0)
.render();

Related

Unwind to another brach of segues in swift or Objective-C

I have a scenario like this:
/-> C -> D \
A -> B - -> G (Contain values of D and F,
\-> E -> F /
Basically at G I have a list of value produce by D and F, let us call D1 and F1.
To create a new value from G, I have to just unwind to B and user can either choose branch C or E and continue to the end G with value of D2 or F2, or he can pop back to A. Let us say the new value is F2, though ABEFG
Now I'm facing a problem, that is I want to edit the values at G, let us say D1.
I want to be able to pop back to D but also allow users pop back to C etc, but D is not in the workflow ABEFG.
My guess is that I have to back up to B and somehow prepare multiple segues up to D but I have no idea if this kind of workflow exists.
Apparently, there is no such way. The solution I found is
Find the instance of B in navigationController!.viewControllers
popToViewController B
Initiate C & D from Main storyboard with identifier (they are already deallocated anyway)
Setup some properties of C & D from D1
pushViewController C & D

How can I find (generate) data points form a shape in 2D in MATLAB ? For example, the letter A , B ,and C. Thanks

How can I find or generate data points form a shape in 2D in MATLAB ? For example, the letters A, B, and C.
You can use fill()
An example for an octogon, provided by
See https://www.mathworks.com/help/matlab/ref/fill.html
% Generate the points required for the fill.
t = (1/16:1/8:1)'*2*pi; % using 1/8 steps we get an 8 sided object.
x = cos(t);
y = sin(t);
% fill the data
fill(x,y,'r')
axis square % prevent skewing the result.
An example of generating the x y coordinates of a rectangle with an offset of (5,5):
x=[5 5 25 25 5]
y=[5 15 15 5 5]
You have 5 points because you need to include the final point to complete the path ( I believe ) Follow the blue path when collecting the x coordinates and the y coordinates. You can see we start at 5,5 then move to 5,15 --- so the first part of the path is
x=[5 5 ...
y=[5 15 ...
If you want to generate the coordinates automatically, you could use a program like InkScape (vector program) to help you convert a character to paths, but here is a simple example drawn with the pen tool:
The points are given by
m 0,1052.3622 5,-10 5,0 5,10 z
which 1052.3622 is VERY large, but is ultimately because I placed my shape at the bottom of the page. if we set this to be 0,0 it would go to the top of the page.

How determine if point is within rectangle given all latitude/longitude coordinates?

If given x/y coordinates for all 4 corners of rectangle, and then another x/y, it's easy to determine if the point is within the rectangle if top left is 0,0.
But what if the coordinates are latitude/longitude where they can be negative (please see attached). Is there a formula that can work in this case?
Mathematicaly, you could use inequations to determine that.
edit: When doing the example, i've noticed you put the coordinates in the inverse format (y,x) instead of (x,y). In my example I use (x,y) format, so I just inverted the order to easy my explanation.
Let's say
A = (-130,10)
B = (-100,20)
C = (-125,-5)
D = (-100,5)
You build an inequation from your rectangle edges :
if( (x,y) < AB && (x,y) > AC && (x,y) > CD && (x,y) < BD) then
(x,y) belongs to rectangle ABCD
end if
If all inequations are true, then your point belongs to the rectangle
Concrete example :
AB represent the segment but can be represented by a formula : y = ax + b
to determine a (the slope of the formula, not the point A) you get the difference of
(Ay - By) / (Ax - Bx)
Ay means Y component of point A wich is 10 in that case
That formula gives us
(10 - 20) / (-130 - -100) = -10 / -30 = 1/3
Now we have
y = x/3 + b
We now determine b. We now that both point A and B belongs to that formula. So we take any of them to replace the x,y values in the formula. Let's take point B :
20 = -100/3 + b
We isolate b giving us :
b = -100 / 60 = -10/6
We have now
y = x/3 - (6/10)
So if we want to determine if Point Z (10, 15) belongs to your retangle, you check firstly if
y > x/3 - (10/6)
Then in the case of Z(10, 15) :
15 > 10/3 - (10/6)
15 > 10/6
15 > 1.66 is true
So condition is met for this edge. You need to this same logic for each edges.
Note that to determine if you use > or <, you need to tell if at a certain x value, our point has a bigger y or smaller y value than our rectangle edge.
You can use < and > if you want a point to be strictly inside the rectangle; <= and >= if a point on the rectangle's edge belongs to the rectangle too. You decide.
I hope that my explanation is clear. Feel free to ask more if some points are unclear.

Plot a third point past the two previously plotted points. Cocos2d

Ok so let me try to explain this the best way that i can.
I have two points plotted 'A' and 'B' and I am trying to plot a third point 'C' so that it is past point 'B' but along the same slope. I have the angle of the line and I would post some code but I really have no idea where to begin.
any help would be awesome!
Just a little code that i do have
CGPoint vector = ccpSub(touchedPoint, fixedPoint);
CGFloat rotateAngle = -ccpToAngle(vector);
Assuming that by this you mean you need a 3rd point C added such that all the points are colinear, all you need to do is calculate the vector that takes you from A to B, and then generate a new point by adding multiples of this vector to the point B. Choose the multiple based on the distance you want C to be from B.
As an example, say A = (2,2), B = (4,3). Then the vector from A to B is given by (2,1).
All you need to do then is work out how far your new point is from B and add a multiple K*(2,1) to your point B where K is chosen to meet the requirements of your distance
I am assuming you are in 2D, but the same method would apply in higher dimensions
My math is rusty, but the linear equation is generally represented as y=m*x+b, where m is the slope, and b is the y-intercept. You can get m, the slope, by taking the difference of the y values and dividing that by the difference in the x values, e.g., if A = (2,2) and B = (4,3), then m is (3-2)/(4-2) or 0.5. Then, you can solve the linear equation for b, the y-intercept, i.e. b=y-m*x and then plug in either of the data points, e.g. if we plug in the x and y values for point A, you get b = 2 - 0.5 * 2 = 1. Now knowing the slope, m (0.5 in this example), and the y-intercept, b (1 in this example), you can calculate the y for any x value using y=m*x+b, in this case y=0.5*x+1.
So, if touchedPoint and fixedPoint are CGPoint, you can calculate the slope and y-intercept from fixedPoint and touchedPoint like so:
double m = (fixedPoint.y - touchedPoint.y) / (fixedPoint.x - touchedPoint.x);
double b = fixedPoint.y - m * fixedPoint.x;
Now, you don't say how you want to determine where this third point, C, is. But if you, for example, knew the x coordinate for this new point C, you can calculate the y coordinate that falls on the same line as follows:
CGPoint pointC;
pointC.x = 400; // or set this to whatever you want
pointC.y = m * pointC.x + b;

How would I split a large set of tabular data into smaller relevant tables? (Not a DB Question)

I'm really hoping I can describe this question in an understandable way. This is a puzzle that I have not been able to begin to solve even though I (mostly) understand it. I'm just not sure where to start, and I'm really hoping someone out there can get me headed in the right direction.
I have a LARGE table of data. It describes relationships between objects. Let's say the Y-axis has items numbered 1-1000, and the X-axis has items 1-1000 also. If item #234 on the Y-axis is related to item #791 on X, there will be a mark in the table where the row and column cross. In some industries this is referred to an a Truth Table. One can, at a glance, see how many items in a system relate to each other. The marks in the table can help to identify trends and patterns.
Here's some other helpful stuff about the nature of the table:
The full range of the number of relationships (r) for each item on either axis can be 1 <= r <= axisTotal.
The X and Y axis will share common items, but each axis will also have items that the other axis does not.
Each item will only exist once per axis. It can be on X and Y, but it would only be on each one 1 time.
The total number of items on each axis will most likely NOT be equal. Each axis could have from 50 to 1000's of items.
The end result is that this is going to be a report that needs to be printed. We have successfully printed a table that had about 100-150 items on each axis on an 11in X 17in piece of paper. Any more than that and it begins to be so small it's unreadable.
What I am trying to do is split the super large tables into smaller tables, but related points need to stay together. If I grab item 1-100 on X then I would need each item they relate to from Y.
I've generated a number of these tables and, while the number of relationships CAN be arbitrary, I have never seen an item relate to all other items. So in real practice the range is more like 1 <= r <= (10% * axisTotal). If an item's relationships exceed this range, it can be split up into multiple tables, but that is not optimal at all.
At the end of the day I think we, and our clients, would be happy if a 1000x1000 item table was split into 8 to 10 printed pages of smaller, related tables.
Any guidance would be a great help! Thanks.
---EDIT---
One other thing worth noting, there will be no empty rows or columns in the table. Every item on both the x and y axis will relate to at least 1 item on the opposite axis.
---EDIT---
Here is an example of a small truth table that I'm describing: . Every row and column has at least one relationship.
---EDIT---
May 18th, 2011
For what it's worth, I was moving pretty good on this project and I got pulled off for a couple of weeks. So it's going to a little while before I get back to this problem. But it is one that I will have to solve soon.
---EDIT---
July 11th, 2011
Bummer. Well, looks like I'm not going to be able to solve this problem right now. I was really hoping to be able to figure this out. Through discussion we decided to present the truth table in an Excel spreadsheet as an add-on resource to the main report. Excel 2007 and later will handle 1000's of columns which will more than suffice. Plus, we added some VBA which allows the viewer to double click on the column titles. This action will reduce the rows to only ones where there are interactions. Then it removes empty columns. In this way they can see a small sub-table based on the item they want to view, and can print it if they want.
This isn't an answer, I just want to try to visualize your data a little better. Does it kind of look like this?
Alice Bob Charlie ... Zelda
Shoes X X
Hats X X
Gloves X
...
Pants X
EDIT
Is it a requirement to show the data in tabular format? Or could you just list each out? Something like:
Alice
Shoes
Bob
Hats
Pants
Charlie
Shoes
Gloves
Zelda
Hats
Or the other way:
Shoes
Alice
Charlie
Hats
Bob
Zelda
Gloves
Charlie
Pants
Bob
EDIT 2
Okay, I've made another larger truth table to hopefully get a better understanding of how you want to split things up:
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
1 x x x x
2 x x x x x x
3 x x x x
4 x x x
5 x x x
6 x x x
7 x x x
8 x x x
For argument's sake lets just say that you can only fit 4 rows on a page (because I don't feel like typing out a giant table this early in the morning) so we're going to split this into two pages. First, it is important to show every row, right? Second, do you need to show columns that never have a value. For instance Y and Z never have a value for rows 1 through 8 in this table, can they be excluded from the report or do they still need to be there? Third, is order of the rows important?
If its not important to show completely empty columns then we could remove 10 columns from the table above and compress it down to:
A B C E F H I L M O P Q R U V W
1 x x x x
2 x x x x x x
3 x x x x
4 x x x
5 x x x
6 x x x
7 x x x
8 x x x
Then if row order isn't important you can compress it further by taking an optimum row arrangement (not necessarily shown here). The two tables below have further been compress to 11 and 10 columns:
A B C F H I M P Q R U
1 x x x x
2 x x x x x x
5 x x x
7 x x x
A E H I L M O P U W
3 x x x x
4 x x x
6 x x x
8 x x x
Am I going down a completely wrong path here? These are all just questions to help me better understand your data and output requirements.
Also, in all seriousness, is it an option to get larger printers/plotters? Also, is it an option to just generate a PDF and use Acrobat's print tile's option?
Last year I read an article at the Computational Biology PLoS journal (www.ploscompbiol.org), that seems related to your problem.
In short, it describes a new approach when we already have a set of proteins and tabular data about their one-to-one interaction and we want to to group them so that interaction inside a group and interaction between two groups is either maximized or (this is the innovative idea) minimized .
If we plot the start data table with black for high and white for low interaction it looks randomly gray. The result table, after the calculations and rearranging is done (so grouped items are placed near one another), looks more like orthogonal areas of black and white.
The article: Protein Interaction Networks—More Than Mere Modules,
where there are also references to other older techniques for grouping this kind of data.