[vJASS] Enumerating units in a rotated rectangle with a library occasionally fails to detect units

I'm making a laser spell and as the title says sometimes it fails to hit units that the laser clearly passes through. I'm reasonably sure the issue is with this library Line Segment Enumeration v2.2b (vJass, Lua, GUI) because I just updated LightningUtils to use it instead of what was provided with LightningUtils and now I'm having this issue. Attached is a video of the spell both working and failing and a demo map.
 

Attachments

  • line segment enum bugs.w3m
    116.5 KB · Views: 4
  • warcraft-iii-reforged-20240627-21034609_kRSXbCml.mp4
    9 MB
I'm sorry, I tried to decipher your code to understand what was going wrong, but I couldn't do it. I can't tell what's going on in your angle increment method. I don't know what the dummy is for and I don't know why your struct is a missile. You have these variables in your code, like source and model, which I assume are struct members, but I don't know which struct they actually belong to.

You're using these complex libraries to achieve what appears to me to be, apart from the Line Segment Enumeration, relatively simple things. That's fine as long as it works well, but if there's a bug, then finding it will of course become much more difficult.

All I can tell from testing the map is that the bug, like in your mouse turning system, appears to happen only at the 360° - 0° transition point, so that's where I would be looking for it.
 
Last edited:
I'm sorry, I tried to decipher your code to understand what was going wrong, but I couldn't do it. I don't see anywhere in your code that you're actually incrementing the angle. I don't know what the dummy is for and I don't know why your struct is a missile. You have these variables in your code, like source and model, which I assume are struct members, but I don't know which struct they actually belong to.

You're using these complex libraries to achieve what appears to me to be, apart from the Line Segment Enumeration, relatively simple things. That's fine as long as it works well, but if there's a bug, then finding it will of course become much more difficult.

All I can tell from testing the map is that the bug, like in your mouse turning system, appears to happen only at the 360° - 0° transition point, so that's where I would be looking for it.
Sorry, I threw together the demo map really quickly last night. These parts are where I need help with the math:

In LaserSweep:

JASS:
        method onPeriod takes nothing returns boolean
        local group g = CreateGroup()
        local unit u
        call LightningUtils.enumUnits(g, beam, 100.) //Right here is where I get the group of units in the line segment and what I want you to look at
        loop
        set u=FirstOfGroup(g)
        exitwhen u==null
        if not IsUnitInGroup(u,alreadyhit) and IsUnitEnemy(u, owner) and not IsUnitType(u, UNIT_TYPE_MAGIC_IMMUNE) and not BlzIsUnitInvulnerable(u) and UnitAlive(u) and not IsUnitType(u,UNIT_TYPE_STRUCTURE) then
            call GroupAddUnit(alreadyhit,u)
            call UnitDamageTarget(source, u, damage, false, true, ATTACK_TYPE_NORMAL, DAMAGE_TYPE_MAGIC, null)
        endif
        call GroupRemoveUnit(g,u)
        endloop
        set beam.targetX = .x
        set beam.targetY = .y
        call DestroyGroup(g)
        set g = null
            return false
        endmethod

In LightningUtils:

JASS:
        static method enumUnits takes group g, Lightning light, real radius returns nothing
            local real angle = AngleBetweenPointsReal(light.sourceX, light.sourceY, light.targetX, light.targetY)
        call LineSegment.EnumUnits(g,light.sourceX, light.sourceY, light.targetX, light.targetY, angle, null)
        endmethod
 
Printed out the difference in maxY and minY of the rect created by Line Segment Enumeration as it passes through the 360° transition point. It becomes 0, so the line segment has zero width.

1719581992225.png
 
JASS:
        static method enumUnits takes group g, Lightning light, real radius returns nothing
            local real angle = AngleBetweenPointsReal(light.sourceX, light.sourceY, light.targetX, light.targetY)
            call LineSegment.EnumUnits(g,light.sourceX, light.sourceY, light.targetX, light.targetY, angle, null)
        endmethod

This function makes no sense. It discards the radius argument and passes the angle as the offset into the LineSegment.EnumUnits function.

Replace it with this function:

JASS:
        static method enumUnits takes group g, Lightning light, real radius returns nothing
            call LineSegment.EnumUnits(g,light.sourceX, light.sourceY, light.targetX, light.targetY, radius, null)
        endmethod

and it works.

P.S.: Why the hell is the width of the line segment called radius and then offset? I swear, some people and their variable names...
 
JASS:
        static method enumUnits takes group g, Lightning light, real radius returns nothing
            local real angle = AngleBetweenPointsReal(light.sourceX, light.sourceY, light.targetX, light.targetY)
            call LineSegment.EnumUnits(g,light.sourceX, light.sourceY, light.targetX, light.targetY, angle, null)
        endmethod

This function makes no sense. It discards the radius argument and passes the angle as the offset into the LineSegment.EnumUnits function.

Replace it with this function:

JASS:
        static method enumUnits takes group g, Lightning light, real radius returns nothing
            call LineSegment.EnumUnits(g,light.sourceX, light.sourceY, light.targetX, light.targetY, radius, null)
        endmethod

and it works.

P.S.: Why the hell is the width of the line segment called radius and then offset? I swear, some people and their variable names...
I'll try this out and let you know if I have any further issues but I don't think I will ( :
 
Top