What is the easiest way to check if the two CRgn intersects? - winapi

I use VS2010 and have:
CRgn rRgn1, rRgn2;
I'd expected a function like:
BOOL CRgn::Intersect(CRgn rRgn);
or
BOOL Intersect(CRgn rRgn1, CRgn rRgn2);
Already had search the official documentation and the SO with no results.

You can use CRgn::CombineRgn with a parameter of RGN_AND. It will return NULLREGION if the intersection is empty.

Related

How do I get a random variant of an enum in GDScript, Godot 3.3?

I have declared an enum like so in GDScript:
enum State = { STANDING, WALKING, RUNNING }
I want to get a random variant of this enum without mentioning all variants of it so that I can add more variants to the enum later without changing the code responsible for getting a random variant.
So far, I've tried this:
State.get(randi() % State.size())
And this:
State[randi() % State.size()]
Neither work. The former gives me Null, and the latter gives me the error "Invalid get index '2' (on base: 'Dictionary')."
How might I go about doing this in a way that actually works?
This can be achieved the following way:
State.keys()[randi() % State.size()]
This works because keys() converts the State dictionary to an array, which can be indexed using [].

Is it possible to use only one of the return values when initializing members in Go?

I understand how to use multiple return values in go. I further understand that in most cases one of the returns is an error, so ignoring returned values can be dangerous.
Is there a way to ignore a value in struct initializer like this? The below example does not work as Split returns two values, but I am interested only in the first one. I can of course create a variable but...
someFile := "test/filename.ext"
contrivedStruct := []struct{
parentDir string
}{
{ parentDir: filepath.Split(someFile) },
}
It's not possible to use only one of the return values when initializing members in Go.
Using variables clearly expresses your intent.
Go sometimes feels like it could be more succinct, but the Go authors favoured readability over brevity.
Alternatively, use a wrapper function. There are several 'Must' wrapper functions in the standard library, like: template.Must.
func first(args ...string) string {
return args[0]
}
For your particular example, splitting paths, see filepath.Base or filepath.Dir.
No, there is no way to skip one of the returned values in structure initializer.

Ti Nspire: Convert solve(...) output to a callable Function

in order to calculate the inverse function of f(x) I defined following function:
inv(fx):=exp▶list(solve(fx=y,x),x)
which output is:
inv(x^(2)) {piecewise(−√(y),y≥0),piecewise(√(y),y≥0)}
So that part works already, but how can I use this result as a callable function i(y)?
Thanks for your help
Outside of your program, you can turn the result into function i(y) with:
i(y):=piecewise(-√(y),y≥0,√(y),y≥0)
I do not have a CAS, so your results may differ, but, because the function can only return one value, it would only return (and display in the graph) the first value, in this case, -√(y). If you want to display on the graph or get the values of both, you would be better off creating two separate functions (-√(y), and √(y)). Hope this helps you "use the result as a callable function."

How to use Enumerations in DXL Scripts?

I'd like to test the value of an enumeration attribute of a DOORs object. How can this be done? And where can I find a DXL documentation describing basic features like this?
if (o."Progress" == 0) // This does NOT work
{
// do something
}
So after two weeks and an expired bounty I finally made it.
Enum-Attributes can be assigned to int or string variables as desired. But you have to assign to a variable to perform such a conversion. It is not casted when a mere comparison is done like in my example. So here comes the solution:
int tmp = o."Progress"
if (tmp == 0)
{
// do something
}
When tmp is a string, a comparison to the enum literals is possible.
That was easy. Wasn't it? And here I finally found the everything-you-need-to-know-about-DXL manual.
For multi-valued enumerations, the best way is if (isMember(o."Progress", "0")) {. The possible enumerations for single and multi-enumeration variables are considered strings, so Steve's solution is the best dxl way for the single enumeration.
You can also do
if(o."Progress" "" == "0")
{
//do something
}
This will cast the attribute value to a string and compare it to the string "0"
If you're talking about the "related number" that is assignable from the Edit Types box, then you'll need to start by getting the position of the enumeration string within the enum and then retrieve EnumName[k].value .
I'm no expert at DXL, so the only way to find the index that I know of off the top of my head is to loop over 1 : EnumName.size and when you get a match to the enumeration string, use that loop index value to retrieve the enumeration "related number."

Has google closure a contains-function where I can specify the comparing function?

I have an array of DateObjects and DateRange-Objects and a single DateObject.
I would like to know if this single Date is in the array of DateObjects or in the range of one DateRange-Object.
goog.array.contains(arr, obj) is almost what I want, but I would like the goog.date.isSameDay(date, opt_now) function to compare.
Has google closure a contains-function where I can specify the comparing function?
find/findIndex might be what you're looking for. Something like:
goog.array.find(dates, goog.partial(goog.date.isSameDay, singleDateObject));
goog.array.findIndex(ranges, function(range) { /* your comparison */ });

Resources