Distance(2/3)DSquared functions

Moderator: GZDoom Developers

User avatar
Major Cooke
Posts: 8175
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Distance(2/3)DSquared functions

Post by Major Cooke »

Pull Request

A simple submission, adds a boolean parameter to Distance2D and Distance3D in zscript. If true, the result returns squared, otherwise returns square rooted.

Test code:

Code: Select all

 // Pick a random monster in the map and print how far away it is, both squared and rooted.
Class a : Actor
{
	Default
	{
		+NOINTERACTION
	}
	States
	{
	Spawn:
		TNT1 A 1 NoDelay
		{
			double len, sq;
			let it = ThinkerIterator.Create("Actor", Thinker.STAT_DEFAULT);
			Actor mo = null;
			while (mo = Actor(it.Next()))
			{
				if (mo.bISMONSTER)
				{
					len = Distance3D(mo);
					sq = Distance3DSquared(mo);
					Console.Printf("Regular: %.3f\nSquared: %.3f", len, sq);
					break;
				}
			}
		}
		Stop;
	}
}
Last edited by Major Cooke on Sat Feb 24, 2018 2:37 pm, edited 3 times in total.
dpJudas
 
 
Posts: 3040
Joined: Sat May 28, 2016 1:01 pm

Re: Distance(2/3)D Squared boolean

Post by dpJudas »

In my opinion Distance2D(true) is pretty bad as its nowhere obvious what such a boolean would do. Two functions like Distance2D() and Distance2DSquared() is so much clearer.
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: Distance(2/3)D Squared boolean

Post by _mental_ »

Agreed, distinct function names make intention obvious to a reader.
This is not as bad as some ACS functions with like ten integer arguments but it's a different story.
There are some bad examples on C++ side too. Let's not move such obscurity to ZScript.

Alternatively, use enum values instead of boolean. It's more useful with several arguments though.
User avatar
Major Cooke
Posts: 8175
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Distance(2/3)DSquared functions

Post by Major Cooke »

Changed. OP updated too.
User avatar
Major Cooke
Posts: 8175
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Distance(2/3)DSquared functions

Post by Major Cooke »

Also I am unaware of how or why Travis failed to build. I don't know how that system works.
Edward-san
Posts: 1774
Joined: Sat Oct 17, 2009 9:40 am

Re: Distance(2/3)DSquared functions

Post by Edward-san »

That failure seems to be independent on the code, most likely an internal error in travis. Restarting the job might do the trick there.

About the submission, 'Squared' in the name is much better, indeed.
User avatar
Rachael
Posts: 13562
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: Distance(2/3)DSquared functions

Post by Rachael »

Travis and AppVeyor are not inherently reliable. As Edward-San said you can sometimes just restart the job.
User avatar
Major Cooke
Posts: 8175
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Distance(2/3)DSquared functions

Post by Major Cooke »

I don't even know how to restart it.
User avatar
Rachael
Posts: 13562
Joined: Tue Jan 13, 2004 1:31 pm
Preferred Pronouns: She/Her
Contact:

Re: Distance(2/3)DSquared functions

Post by Rachael »

When you open the failing build it will give you the option. There's several "jobs" for each commit and chances are only one of them is failing - you can manually trigger a rebuild when you click on it.
User avatar
Major Cooke
Posts: 8175
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Distance(2/3)DSquared functions

Post by Major Cooke »

Don't think I can actually, probably because I don't have push access to the repo.

At any rate, also probably not worth bothering over. This is essentially a copy/paste of functions.
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: Distance(2/3)DSquared functions

Post by _mental_ »

After retrying a job PR was built fine. Changes are OK to me.
User avatar
Major Cooke
Posts: 8175
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Distance(2/3)DSquared functions

Post by Major Cooke »

Great! Any other devs?

Also, curious, the thought of potential overflows came to mind but seeing as the maximum map size is 65536 (I think). 4,294,967,295 (long unsigned int max) is a safe distance check for these functions right?
_mental_
 
 
Posts: 3812
Joined: Sun Aug 07, 2011 4:32 am

Re: Distance(2/3)DSquared functions

Post by _mental_ »

They operate with doubles, no?
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49067
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Distance(2/3)DSquared functions

Post by Graf Zahl »

THey do.
User avatar
Major Cooke
Posts: 8175
Joined: Sun Jan 28, 2007 3:55 pm
Preferred Pronouns: He/Him
Location: QZDoom Maintenance Team

Re: Distance(2/3)DSquared functions

Post by Major Cooke »

Yeah but I'm just asking for the sake of capping it off in my mods, zscript-wise. I.e. I wouldn't expect anything beyond 32767^2 to be of much importance so I'd clamp it down to a long uint to save on memory, for things that are recorded.
Post Reply

Return to “Closed Feature Suggestions [GZDoom]”