# Draw lines limits?

I have a minimap that has lines drawn from point to point. I need to some how masks these lines to stay in the minimap box.

[lua]
for k, pos in pairs(CheckPoints)do
sx = GetMiniMapPos(CheckPoints[k]).x
sy = GetMiniMapPos(CheckPoints[k]).y
if(CheckPoints[k+1] != nil)then
ex = GetMiniMapPos(CheckPoints[k+1]).x
ey = GetMiniMapPos(CheckPoints[k+1]).y
else
ex = GetMiniMapPos(CheckPoints[1]).x
ey = GetMiniMapPos(CheckPoints[1]).y
end
if(((sx < 0) && (ex < 0)) || (sx > CameraSize) && (ex > CameraSize) || ((sy < 0) && (ey < 0)) || (sy > CameraSize) && (ey > CameraSize))then
else
surface.SetDrawColor( 0, 255, 0, 255 )
surface.DrawLine( sx, sy, ex, ey )
end
end
[/lua]

How would I make the lines only be visible in a square 250x250?

math.max / math.min ?

Well I stopped lines that I do not need from drawing using this if statment

[lua]
if(((sx < 0) && (ex < 0)) || (sx > CameraSize) && (ex > CameraSize) || ((sy < 0) && (ey < 0)) || (sy > CameraSize) && (ey > CameraSize))then
else
surface.DrawLine( sx, sy, ex, ey )
end
[/lua]

[editline]1st November 2011[/editline]

[lua] if(((sx < 0) && (ex < 0)) || (sx > CameraSize) && (ex > CameraSize) || ((sy < 0) && (ey < 0)) || (sy > CameraSize) && (ey > CameraSize))then // – Can we even see the line?
else // – Yes we can!
surface.SetDrawColor( 0, 255, 0, 255 )
if(ex == sx)then // – Handle horizontal lines cheaply
if(sy > 250)then
sy = 250
elseif (sy < 0)then
sy = 0
end
if(ey > 250)then
ey = 250
elseif (ey < 0)then
ey = 0
end
elseif(ey == sy)then // – Handle vertical lines cheaply
if(sx > 250)then
sx = 250
elseif (sx < 0)then
sx = 0
end
if(ex > 250)then
ex = 250
elseif (ex < 0)then
ex = 0
end
else // – Shit it’s a sloped line.
local b = 0
local slope = (ey-sy)/(ex-sx)
if(ex < 0)then // Snap to the left x-intercept
b = ey-(slopeex)
ex = 0
ey = (slope
ex)+b
elseif(ex > CameraSize)then // Snap to the right x-intercept
b = ey-(slopeex)
ex = CameraSize
ey = (slope
ex)+b
end
if(ey < 0)then // Snap to the left y-intercept
b = ey-(slopeex)
ey = 0
ex = (ey-b)/slope
elseif(ey > CameraSize)then // Snap to the right y-intercept
b = ey-(slope
ex)
ey = CameraSize
ex = (ey-b)/slope
end
if(sx < 0)then // Snap to the left x-intercept
b = sy-(slopesx)
sx = 0
sy = (slope
sx)+b
elseif(sx > CameraSize)then // Snap to the right x-intercept
b = sy-(slopesx)
sx = CameraSize
sy = (slope
sx)+b
end
if(sy < 0)then // Snap to the left y-intercept
b = sy-(slopesx)
sy = 0
sx = (sy-b)/slope
elseif(sy > CameraSize)then // Snap to the right y-intercep
b = sy-(slope
sx)
sy = CameraSize
sx = (sy-b)/slope
end
end
surface.DrawLine( sx, sy, ex, ey )
end
[/lua]

Solved