Do you find this helpful?

Dirac

22710180
Reaction score
147
Because i do, and i find it to be a very good replacement to the ugly Location native
The join method would be used to constantly have useful data of both locations at any time without repeating the same calculations
If you don't know what the "slope" variable is for, it's the relation between the difference of the height of two locs and the distance between them.
JASS:
library Loc /* v1.0.0

Replacement of the Location native.

***********************************************************************
*
*   struct Loc
*
*       readonly real x
*       readonly real y
*       readonly real z
*           -   These 3 read-only variables are the Loc's coordinates
*
*       static method create takes real x, real y, real z returns Loc
*           -   Creates a new Loc with the given coordinates.
*       method destroy takes nothing returns nothing
*           -   Deallocates the Loc.
*
*       method move takes real x, real y, real z returns nothing
*           -   Assigns the Loc new coordinates.
*
*       static method join takes Loc v1, Loc v2 returns nothing
*           -   Joins two Locs together.
*       method disjoint takes nothing returns nothing
*           -   Breaks the joint of the given Loc.
*
*       readonly real angle
*       readonly real distance
*       readonly real slope
*           -   These 3 read-only members store the relation between
*           -   two joined Locs. Updates everytime a Loc is moved.
*
**********************************************************************/
    
    struct Loc extends array
        
        private static integer ic = 0
        private static integer array next
        
        readonly static location point = Location(0,0)
        
        readonly real x 
        readonly real y
        readonly real z
        
        readonly real angle
        readonly real distance
        readonly real slope
        
        private static method refresh takes Loc v1, Loc v2 returns nothing
            local real a = Atan2(v2.y-v1.y,v2.x-v1.x)
            local real d = SquareRoot((v1.x-v2.x)*(v1.x-v2.x)+(v1.y-v2.y)*(v1.y-v2.y))
            local real s = (v2.z-v1.z)/d
            set v1.angle = a
            set v2.angle = a+bj_PI
            set v1.distance = d
            set v2.distance = d
            set v1.slope = s
            set v2.slope = -s
        endmethod
        
        static method join takes Loc v1, Loc v2 returns nothing
            call refresh(v1,v2)
            set next[v1]=v2
            set next[v2]=v1
        endmethod
        
        method disjoint takes nothing returns nothing
            set next[next[this]]=next[this]
            set next[this]=this
        endmethod
        
        method move takes real sx, real sy, real sz returns nothing
            call MoveLocation(point,sx,sy)
            set x=sx
            set y=sy
            set z=sz+GetLocationZ(point)
            if this!=next[this] then
                call refresh(this,next[this])
            endif
        endmethod
        
        static method create takes real sx, real sy, real sz returns thistype
            local thistype this
            if next[0]==0 then
                set ic = ic+1
                set this = ic
            else
                set this = next[0]
                set next[0] = next[next[0]]
            endif
            set next[this]=this
            call this.move(sx,sy,sz)
            return this
        endmethod
        
        method destroy takes nothing returns nothing
            call this.disjoint()
            set next[this]=next[0]
            set next[0]=this
        endmethod
        
    endstruct
    
endlibrary
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
i would add something like this:
JASS:
static method compare takes thistype this, thistype this2 returns real
    return SquareRoot((this.x - this2.x, 2) * (this.x - this2.x, 2) + (this.y - this2.y) * (this.y - this2.y) + (this.z - this2.z, 2) * (this.z - this2.z, 2))
endmethod //to return the real distance between points taking height into consideration


and if you werent limited to 2 points linked together

Also if you increased the link ammounts, something like this:

JASS:
static method compareChain takes thistype this returns real
    local real dist = 0
    local thistype i = this
    loop
        set dist = dist + .compare(i, i.next)
        exitwhen i.next = this
        set i = i.next
    endloop
    return dist
endmethod


thats actually something i would use (as long as its truly more efficient than just using x/y arguments and locals)

also... why do you use an integer array instead of a dynamic struct variable, ie:

JASS:
struct Example extends array
    static integer array next
    static integer array previous

    ---->

    thistype next
    thistype previous

    or just

    thistype.next
endstruct


this makes it much simpler for deallocation and referencing next/previous

ie this.next.previous.next.previous = this

no need for
.next[.previous[.next[.previous]]]
or
thistype(thistype(thistype(this.next).previous).next).previous

which are way more complicated
it compiles the same but its more readable



Also also:

why do you link them with 0 when you destroy them? what happens when someone destroys a bunch 1 after another, do they just all point to 0 and not get pointed to at all?
 

Dirac

22710180
Reaction score
147
Thanks for the feedback.
[ljass]loc.distance/Atan(loc.slope)[/ljass]
Would be equal to the distance of the locs considering the height of both

I limit myself to two points because of two reasons:
  • It's the most common situation
  • I would have to use Table instead, would be much slower

I guess i could implement some kind of "sync" between two locs, but would be monodirectional data.

Example, I have 5 locs and 4 of them are linked to the 5th one.
If i move the 5th one, all other 4 locs would get their data updated, but the 5th one would only get the data from 1 of them (as it can only be synced with 1 node)
In that case I would have to use LinkedList and it would be less user friendly
 

GFreak45

I didnt slap you, i high 5'd your face.
Reaction score
130
if you need to link 2 locations together to compare the distance i wouldnt find that useful, i would rather just compare them via regular math for slope/distance etc
i mean i guess it would be usefull to someone whos not to great at math and would spend a ton of time researching how to do it and still not get it, but other than that it would basically be a new version of the [ljass]PolarProjectionBJ[/ljass] with a slight twist, more efficient to use whats inside rather than the function
 

Dirac

22710180
Reaction score
147
why do you link them with 0 when you destroy them? what happens when someone destroys a bunch 1 after another, do they just all point to 0 and not get pointed to at all?
It's a stack.

0 -> 0 -> 0

instance (4) gets deallocated
{
next[4] = next[0] -> 0
next[0] = 4
}

0 -> 4 -> 0

instance (7) gets deallocated
{
next[7] = next[0] -> 4
next[0] = 7
}

0 -> 7 -> 4 -> 0



Using your way of doing things
JASS:
local real dist = 0
local thistype i = this
loop
    set dist = dist + .compare(i, i.next)
    exitwhen i.next = this
    set i = i.next
endloop

Would update every other Loc "i" with "this" , but won't update the data on "this"
That would cause issues if the user has joined only 2 Locs together, because now only one of those locations knows the actual distance, the one you didn't move.
In case the user has more than 2 joined... as an example Locs A, B and C are together, if I move A then B and C would know their distance to A, but they won't know their distance to each other and A would know the distance between itself and one of the other Locs (chosen randomly)
A.distance = distance between A and ??
B.distance = distance between B and A
C.distance = distance between C and A

Current method i wrote using my linked list module
JASS:
private method refresh takes nothing returns nothing
    local thistype exit = this
    local real a
    local real d
    local real s
    loop
        set this = next
        exitwhen this == exit
        set a = Atan2(this.y-exit.y,this.x-exit.x)
        set d = SquareRoot((exit.x-this.x)*(exit.x-this.x)+(exit.y-this.y)*(exit.y-this.y))
        set s = (this.z-exit.z)/d
        set exit.angle = a
        set this.angle = a+bj_PI
        set exit.distance = d
        set this.distance = d
        set exit.slope = s
        set this.slope = -s
    endloop
endmethod
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/
  • The Helper The Helper:
    Decided to put up a healthier type recipe to mix it up - Honey Garlic Shrimp Stir-Fry https://www.thehelper.net/threads/recipe-honey-garlic-shrimp-stir-fry.193595/

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top