Verticaly center windows with gtk API - gtk

It is possible with the help of gtk API to position one window under another centered in the middle
------------------
| WINDOW TOP |
------------------
----------------------
| WINDOW BOTTOM |
----------------------
I try:
GtkAllocation alloc;
gint x, y;
gtk_window_get_position (WINDOW_TOP, &x, &y);
gtk_widget_get_allocated_size (WINDOW_TOP, &alloc, NULL);
gtk_window_move (WINDOW BOTTOM, alloc.x + x, alloc.y + alloc.height + y);
but windows are left aligned.

Related

Get point between two points crossing the 180 degree meridian at 180 degrees

I am plotting a line on a MapboxGL (js) world map that follows the path of orbital objects. I do this by adding a new set of decimal longitude/latitude coordinates to a line geometry array as the orbit of the object updates.
There is a known issue with Mapbox (and others) that when drawing a line that crosses the 180° meridian (longitude), we do not get a nice straight line from a to b, we get a very long line that wraps around the whole globe from a to b:
instead of: we get:
/ /
/ /___
.../..... ......... 180° meridian
/ ___
/ /
/ /
"Accepted" answers here and at Mapbox suggest shifting to a 0°/360° longitude range, but this just moves the problem from the equator to the pole. This is fine for most general proposes, but is still an issue for orbital tracking where we may be crossing the 0°/360° meridian.
My solution is to use MultiLine geometry and break up my coords into new arrays when I cross this meridian, however, this will always leave a wee gap, or, if I "180, lat" either side, we get a "kink" at the meridian:
gap: or kink:
/ /
/ /
........ .....|... 180° meridian
/
/ /
/ /
So I need to figure out what the exact latitude would be if the longitude is on the meridian, knowing the start and end points either side:
+170 | p2 /:
| / :
| / :
180 -|-----/ pX? -- 180° meridian
| /: :
(lng) | / : :
| / : :
-170 |_/___:___:___
p1 x?
(lat)
I need to solve for latitude x so I can generate pX (knowing p1 and p2 if longitude where 180). Once I have pX, I can add this to the end of the last line and to the beginning of the next, thus closing the gap (or smoothing the "kink").
I know this is basic Trig, but my old-man-brain has failed me .. again ....
The simple way to split a line in this way would be to use Turf's lineSplit function. Something like:
const meridian = turf.lineString([[180, -90], [180, 90]]);
const linePieces = turf.lineSplit(myline, meridian);
I haven't tried this, so not sure if Turf itself has any weirdness at the meridian. If it does, you might have to temporarily translate the coordinates elsewhere or something.
Better than doing your own trigonometry in any case, especially since it may introduce errors with the world not being flat.
SOLVED! With basic Trig (while writing the question - so I am posting it anyway, just incase it helps someone else):
We are basically playing with two right triangles: p1 to p2, and the smaller right triangle where the opposite side stops at the meridian, both with the same hypotenuse angle. So, we have:
+170 | p2 /|
| / |
| / |
180 -|-----/ pX? -- 180° meridian
| /: |
(lng) | / : A |
| / B: |
-170 |_/___:___|___
p1 x?
(lat)
Where A is our p1 to p2 right angle triangle and B is the triangle from p1 longitude to the meridian, whose adjacent side we need to work out.
Pythagoras basically teaches us that all we need is two points of data (other then the right angle) of a right triangle to solve any other.
We already have the opposite and adjacent lengths of A:
+170 | p2 /|
| /α|
| / |
180 -|-- / | -- 180° meridian
| / |
(lng) | / A | oppositeA
| / |
-170 |_/β______|___
p1 adjacentA
(lat)
So from here we need to calculate the hypotenuse of A to get the angle of the hypotenuse of A (α) so we can use it later:
// add 360 to a negative longitude to shift lng from -180/+180, to 0/360
p1 = { lng: p1.lng < 0 ? p1.lng + 360 : p1.lng, lat: p1.lat }
p2 = { lng: p2.lng < 0 ? p2.lng + 360 : p2.lng, lat: p2.lat }
let oppositeA = Math.abs(p2.lng - p1.lng) // get A opposite length
let adjacentA = Math.abs(p2.lat - p1.lat) // get A adjacent length
let hypotenuseA = Math.sqrt(Math.pow(oppositeA,2) + Math.pow(adjacentA,2)) // calc A hypotenuse
let angleA = Math.asin(oppositeA / hypotenuseA) // calc A hypotenuse angle
Now we need the new opposite of B (p1.lng to 180) and our calculated angle of A to work out the new hypotenuse of B so we can get the new adjacent of B:
+170 | p2 /
| /
| /
180 -|-- / -- 180° meridian
| /: B
(lng) | /α:
| / : oppositeB
-170 |_/___:___ ___
p1 adjacentB
(lat)
let oppositeB = Math.abs(180 - p1.lng) // get B opposite
let hypotenuseB = oppositeB / Math.cos(angleA) // calc B hypotenuse using A angle
let adjacentB = Math.sqrt(Math.pow(oppositeB,2) + Math.pow(hypotenuseB,2)); calc B adjacent
Now we add the new adjacent to p1 latitude, and we have x! So:
let pX = { lng: 180, lat: p1.lat + adjacentB }
End the last line array and start the next with pX, and the gap is perfectly closed!
Highschool math (well, the genius of Pythagoras) to the rescue! I knew it was rattling around in that old-man-brain somewhere .....

Raycast get local coordinates of hit of Plane

I have a plane with scale (64,1,36) and rotation is (90,-180,0) and need the local coordinate of a raycast hit in the 2d coordinates format:
(0,0)-------(64,0)
| |
| |
| |
(0,36)------(64,36)
with my current code:
RaycastHit hit;
Vector3 coords = new Vector3();
if (Physics.Raycast(GazeOriginCombinedLocal, GazeDirectionCombined, out hit, Mathf.Infinity))
{
if (!hit.transform.Equals("Cube"))
{
Pointer.transform.position = hit.point; //Green cube for visualization of hit in worldspace
// coords = RectTransformUtility.ScreenPointToLocalPointInRectangle(Plane, hit.point, Camera.main, out coords);// no result at all
}
}
Trying this:
hit.transform.InverseTransformPoint(hit.point)
gives me this
(5,-5)---(-5,-5)
| |
| (0,0) |
| |
(5,5)----(-5,5)
Does some have an idea to get the needed format?
Thats how my plane which is a child of the main camera and my hierarchy looks like:
Thanks in advance
I think you could use the Transform.InverseTransformPoint which
Transforms position from world space to local space.
And then since this also is affected by the scale multiple it again by the scale of the plane using Vector3.Scale.
So your coords should probably be something like
coords = hit.transform.localScale / 2f + Vector3.Scale(hit.transform.InverseTransformPoint(hit.point), hit.transform.localScale);
can't test it right now though since typing on smartphone. You might e.g. need to invert the y/z component according to your needs and depending how the plane is rotated etc. But I hope this gives you an idea
In order to debug what's wrong you should probably print out the values step by step
var scale = hit.transform.localScale; // 64, 1, 36
var halfScale = scale / 2f; // 32, 0.5, 18
var localHitPoint = hit.transform.InverseTransformPoint(hit.point);
Debug.Log($"{nameof(localHitPoint)}:{localHitPoint:0.000}");
So what I had expected originally here would be values like
(-0.5, 0.5, 0)----(0.5, 0.5, 0)
| |
| (0, 0, 0) |
| |
(-0.5, -0.5, 0)---(0.5, -0.5, 0)
BUT as you now added: Your plane is rotated!
The 90° on X actually makes that Y and Z switch places. So in order to get the desired Y coordinate you would rather read the localHitPoint.z.
Then the 180° on Y basically inverts both X and Z.
So I would now expect the values to look like
(0.5, 0, -0.5)----(-0.5, 0, -0.5)
| |
| (0, 0, 0) |
| |
(0.5, 0, 0.5)---(-0.5, 0, 0.5)
Which looks pretty much like the values you describe you are getting. Not sure though why you have a factor of 10 and why you didn't need to switch Y and Z.
However since you actually want the 0,0 to be in the top-left corner you only need to flip the X axis and use Z instead of Y so
fixedLocalHitPoint = new Vector2(-localHitPoint.x, localHitPoint.z);
Debug.Log($"{nameof(fixedLocalHitPoint)}:{fixedLocalHitPoint:0.000}");
Which should now give you values like
(-0.5, -0.5)----(0.5, -0.5)
| |
| (0, 0) |
| |
(-0.5, 0.5)----(0.5, 0.5)
And still you need to scale it up again
var scaledHitPoint = Vector2.Scale(fixedLocalHitPoint, new Vector2 (scale.x, scale.z));
Debug.Log($"{nameof(scaledHitPoint)}:{scaledHitPoint:0.000}");
Which should now give values like
(-32, -18)----(32, -18)
| |
| (0, 0) |
| |
(-32, 18)-----(32, 18)
That's why you need to add the center point as a reference
coords = new Vector2(halfScale.x, halfScale.z) + scaledHitPoint;
Debug.Log($"{nameof(coords)}:{coords:0.000}");
Which now should be
(0, 0)------(64, 0)
| |
| (32, 18) |
| |
(0, 36)-----(64, 36)
I hope this brings a bit more light into where these "strange" values come from.
Since your camera is scaled 1,1,1 and there is nothing else involved I have a hard time finding where the factor of 10 would have sneaked its way into the calculation to be honest.
If you want to convert this:
hit.transform.InverseTransformPoint(hit.point)
which gives this:
(5,-5)---(-5,-5)
| |
| (0,0) |
| |
(5,5)----(-5,5)
to this:
(0,0)-------(64,0)
| |
| |
| |
(0,36)------(64,36)
Why not do this:
Vector2.Scale(
hit.transform.InverseTransformPoint(hit.point) - new Vector2(5,-5),
new Vector2(-6.4, 3.6)
);
This answer hardcodes the (5,-5) and (-6.4, 3.6) terms because the question doesn't include enough information to use variables instead.
Assuming the scale of the parent of the plane (Main Camera) is (10,10), then this should suffice:
Vector3 planeScale = hit.transform.localScale;
Vector3 cameraScale = hit.transform.parent.localScale;
result = Vector2.Scale(
hit.transform.InverseTransformPoint(hit.point)
- new Vector2(cameraScale * 0.5f ,-cameraScale * 0.5f),
new Vector2(-planeScale.x * 0.5f/cameraScale.x, planeScale.y * 0.5f / cameraScale.y)
);

How i can't do swipe on tablet phone by katalon studio?

I can't find the correct "X" and "Y" coordinate. when I enter the "X" and "Y" coordinate it will scroll the top menu bar.now I am using tablet phone.
This might help for iOS swipe function
https://medium.com/#manishboricha308/ios-mobile-swipe-action-in-katalon-studio-4911199679e
For Android you can create another #Keyword custom
#Keyword
def swipeLeft(){
TouchAction touch = new TouchAction(getCurrentSessionMobileDriver())
int device_Height, device_Width
device_Height = Mobile.getDeviceHeight()
println device_Height
device_Width = Mobile.getDeviceWidth()
println device_Width
int midheight = device_Height/2
println midheight
int midwidth = device_Width/2
println midwidth
int startX,startY,endX,endY
startX = device_Width-100
startY = midheight
endX = -startX
endY = 0
Mobile.swipe(startX,startY,endX,endY)
touch.tap(startX, startY).perform()
}
When You SpyMobile Your device, and mark object You want to swipe or scroll on You will notice properties window filed.
There are X and Y also Height (H) and Width (W).
X and Y are absolute co-ordinates to the top left corner of the object.
H and W are the size of an object. So You do a simple calculation to see
co-ordinates for rest of corners of the object.
With this You know space You want to swipe or scroll on.
Hope it works for You.

Autohotkey get width of current active child window

I am trying to write a script that moves mouse cursor to the center of active child window.
WinGetActiveStats, Title, Width, Height, X, Y
MouseMove, Width / 2, Height / 2, 0
Above does the trick for the Main window. However, I can't seem to find a way to grab the width and height of active child window so that I can move the mouse cursor to the center of child window.
This is very useful feature when using with softwares such as AutoCAD where you could have more than one child window open at any given moment.
Thanks,
The following should work:
ControlGetFocus, cr, A ; get the focused(active) control(child window) of the active window
ControlGetPos, x, y, width, Height, %cr%, A ; get the position and dimensions of this control
MouseMove, % x + Width / 2, % y + Height / 2, 0

How can i create random rectangles (automatically)?

I want to create many rectangles. This should be done automatically. How can I do this without typing thousands of values in my code? Is there an solution?
In my code I wrote every single coordinate point (4 points of each rectangle) manually in my vector "V".
Also how to connect them. "F"
And the value of each rectangle. "C"
My code is
clc
clear all
figure;
V = [0,0;1,0;1,1;0,1;5,5;10,5;10,10;5,10;2,2;4,2;4,4;2,4];
F = [1,2,3,4;5,6,7,8;9,10,11,12];%Dieser Vektor sagt mir in welcher Reihenfolge die Punkte
C = [50;24;99];
patch('Faces',F,'Vertices',V,'FaceVertexCData',C,'FaceColor','flat','EdgeColor','none') %Befehl fürs "zeichnen"
colormap(parula)
colorbar
You can use the following function to create a random rectangle, by randomly generating an (x, y) position for the bottom left corner, and randomly generating a width and height -
function rect = createRandomRectangle(maxX, maxY, minHeight, maxHeight, minWidth, maxWidth)
bottom = maxY * rand;
left = maxX * rand;
height = minHeight + rand * (maxHeight - minHeight);
width = minWidth + rand * (maxWidth - minWidth);
rect = [
left, bottom
left, bottom + height
left + width, bottom + height
left + width, bottom
];
end
Then you just need to take care of creating your V, F, C matrices (by calling createRandomRectangle in a loop) and plotting them.