Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (setq expFindClosestGridVerticle
- (lambda (origin gridID)
- (block Nil
- (and
- (or
- origin
- (not (if (expDebug) (dbgLog "expFindClosestGridVerticle error, origin is Nil")))
- )
- (or
- gridID
- (not (if (expDebug) (dbgLog "expFindClosestGridVerticle error, gridID is Nil")))
- )
- (block
- (
- (angel (expGridIDAngel gridID))
- (gridOrigin (objGetData angel "origin"))
- (gridSize (objGetData angel "size"))
- (gridSpacing (objGetData angel "spacing"))
- (gridEdge (objGetData angel "gridEdge"))
- (angle (sysVectorAngle origin gridOrigin))
- (originVerticle
- (objGetObjByID
- (random
- (objGetData angel "NWCorner")
- (objGetData angel "SECorner")
- )
- )
- )
- (originCoord (expGetGridCoordinate originVerticle))
- (currentPos (objGetPos originVerticle))
- (closestApproach (sysVectorDistance origin originVerticle))
- (offsetCoord (list 0 0))
- (deltaCoord (list))
- (triangulationStage 0)
- )
- (and
- (setq outOfBoundaryCondition
- (lambda (coord1 coord2 thisGridEdge)
- (block
- (newCoord (list))
- (lnkAppend newCoord (+ (@ coord1 0) (@ coord2 0)))
- (lnkAppend newCoord (+ (@ coord1 1) (@ coord2 1)))
- (or
- (ls (@ newCoord 0) 0)
- (geq (@ newCoord 0) thisGridEdge)
- (ls (@ newCoord 1) 0)
- (geq (@ newCoord 1) thisGridEdge)
- )
- )
- )
- )
- (if
- (or
- (and
- (geq angle 0)
- (ls angle 90)
- )
- (gr angle 270)
- )
- (lnkAppend deltaCoord True)
- (lnkAppend deltaCoord Nil)
- )
- (if
- (and
- (gr angle 0)
- (ls angle 180)
- )
- (lnkAppend deltaCoord True)
- (lnkAppend deltaCoord Nil)
- )
- (loop
- (neq triangulationStage 1)
- (block
- (stepAngle newPos)
- ; Step horizontally
- (and
- (setq stepAngle
- (if
- (@ deltaCoord 0)
- 0 ; To the right
- 180 ; To the left
- )
- )
- (setq offsetDelta
- (if
- (@ deltaCoord 0)
- 1 ; To the right
- -1 ; To the left
- )
- )
- (setq newPos
- (sysVectorPolarOffset
- currentPos
- stepAngle
- gridSpacing
- )
- )
- (if (outOfBoundaryCondition originCoord offsetCoord gridEdge) (not (setq triangulationStage 1))) ; We are out of grid, no point going further
- (if
- (ls
- (sysVectorDistance
- newPos
- origin
- )
- closestApproach
- )
- (block Nil
- (setq closestApproach (sysVectorDistance newPos origin)) ; We're closer horizontally
- (setq currentPos newPos)
- (set@ offsetCoord 0 (+ (@ offsetCoord 0) offsetDelta))
- )
- (setq triangulationStage 1); Otherwise we've already found the closest horizontal position
- )
- )
- )
- )
- (loop
- (neq triangulationStage 2)
- (block
- (stepAngle newPos)
- ; Step vertically
- (setq stepAngle
- (if
- (@ deltaCoord 1)
- 90 ; To the top
- 270 ; To the bottom
- )
- )
- (setq offsetDelta
- (if
- (@ deltaCoord 1)
- 1 ; To the top
- -1 ; To the bottom
- )
- )
- (setq newPos
- (sysVectorPolarOffset
- currentPos
- stepAngle
- gridSpacing
- )
- )
- (if (outOfBoundaryCondition originCoord offsetCoord gridEdge) (not (setq triangulationStage 2))) ; We are out of grid, no point going further
- (if
- (ls
- (sysVectorDistance
- newPos
- origin
- )
- closestApproach
- )
- (block Nil
- (setq closestApproach (sysVectorDistance newPos origin)) ; We're closer verically
- (setq currentPos newPos)
- (set@ offsetCoord 1 (+ (@ offsetCoord 1) offsetDelta))
- )
- (setq triangulationStage 2); Otherwise we've already found the closest position in the grid
- )
- )
- )
- ; We've got offsetCoord
- ; We've got originCoord
- ; Now we can add them together and we are good to go
- (setq xx
- (+
- (@ originCoord 0)
- (@ offsetCoord 0)
- )
- )
- (setq yy
- (+
- (@ originCoord 1)
- (@ offsetCoord 1)
- )
- )
- (setq closestID ; Serialize the ID
- (expGetIDByCoordinate (list xx yy) gridID)
- )
- (objGetObjByID closestID) ; Return the closest verticle
- )
- )
- )
- )
- )
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement