Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update geometry related functions #442

Merged
merged 2 commits into from
Jul 19, 2016
Merged

Update geometry related functions #442

merged 2 commits into from
Jul 19, 2016

Conversation

kymckay
Copy link
Contributor

@kymckay kymckay commented Jul 16, 2016

When merged this pull request will:

  • Add a new getArea function to return the array form of any area construct
  • Function randPosArea now accepts areas in the form of an array or location (same as the inArea command)
  • Function taskSearchArea now accepts areas in the form of an array or location
  • Function inArea deprecated in favour of inArea command

I'm not sure if CBA has a deprecation system we might want to use for the inArea function now that there's an equivalent engine command

@jonpas
Copy link
Member

jonpas commented Jul 16, 2016

Yes there is a "system", reference this. Basically move it into a backwards compat file so it doesn't get included in documentation and prints warnings. CBA does not remove deprecated functions like we do in ACE3.

@commy2
Copy link
Contributor

commy2 commented Jul 16, 2016

Suggestion for fnc_randPosArea.
Can't we simply make it create a random position with fnc_randPos and if the result is not inArea, then we discard it and try again?

@commy2 commy2 added this to the 3.0.1 milestone Jul 16, 2016
@commy2
Copy link
Contributor

commy2 commented Jul 16, 2016

[[10,10], 0] call cba_fnc_randPos

Before:
[10,10]

After:
[10,10,0]

While getPos supports 2d positions, the return value is always a 3d position. That is not true for our function.

I have no idea why they chose to make this the alternative syntax of getPos. It is completely different from the original purpose.


Description:
Returns the array form of any area construct:
[center, a, b, angle, isRectangle]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has to be a single line. The format should probably be in L:09 f anyway though

@kymckay
Copy link
Contributor Author

kymckay commented Jul 17, 2016

Can't we simply make it create a random position with fnc_randPos and if the result is not inArea, then we discard it and try again?

While rejection sampling would work, the reason I originally wrote this function was to avoid that since it requires looping an indeterminate amount of times. This way you're guaranteed to get a position in a single shot.

@commy2
Copy link
Contributor

commy2 commented Jul 17, 2016

But that "single shot" could take way longer on average. I guess it also depends on the marker shape. For circles and hexagons it will on average be faster, but it could take a long time on narrow rectangles and ellipses.

- added a new getArea function to return the array form of any area construct
- randPosArea now accepts areas in the form of an array or location (same as the `inArea` command)
- taskSearchArea now accepts area in the form of an array or location
- inArea now directly calls the `inArea` command
New `inArea` command replaces this functionality
@kymckay
Copy link
Contributor Author

kymckay commented Jul 17, 2016

My thinking is that you'd use the function for a guaranteed result, whereas if you wanted to use rejection sampling for possibly quicker execution you'd just write it manually with while and getPos

@kymckay
Copy link
Contributor Author

kymckay commented Jul 17, 2016

Trying to figure out if there's a way to optimise this part of randPosArea:

        private _rho = random (4*(_a + _b));

        private _x1 = (_rho min _2a);
        private _y1 = ((_rho - _x1) min _2b) max 0;
        private _x2 = ((_rho - _x1 - _y1) min _2a) max 0;
        private _y2 = ((_rho - _x1 - _y1 - _x2) min _2b) max 0;
        _posVector = [(_x1 - _x2) - _a, (_y1 - _y2) - _b, 0];

It's used to uniformly find a position along the perimeter of a rectangle, but I feel like there must some way to condense it down.

@@ -71,3 +71,11 @@ CBA_fnc_intToString = {
if (isNil "_int") exitWith {""};
str _int
};

CBA_fnc_inArea = {
Copy link
Contributor

@Killswitch00 Killswitch00 Jul 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't be compileFinal:ed, which, if I'm not mistaken, CfgFunctions functions are.

Also, there's a deprecation macro.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a general problem with this file and should probably be fixed in another PR

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, so we should not add to the problem.

Instead, change the old function file and keep its CfgFunctions entry.

Copy link
Contributor

@commy2 commy2 Jul 18, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with that is, that the function will appear in the config functions viewer. Deprecated functions shouldn't appear there in my opinion.

@Killswitch00 Killswitch00 merged commit 13227f9 into CBATeam:master Jul 19, 2016
@kymckay kymckay deleted the geometry branch July 19, 2016 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants