📄 geometry.zc
字号:
//[c]geometry
//[c]
//[of]:license
//[c] Code Browser - a folding text editor for programmers
//[c] Copyright (C) 2003-07 Marc Kerbiquet
//[c]
//[c] This program is free software; you can redistribute it and/or modify
//[c] it under the terms of the GNU General Public License as published by
//[c] the Free Software Foundation; either version 2 of the License, or
//[c] (at your option) any later version.
//[c]
//[c] This program is distributed in the hope that it will be useful,
//[c] but WITHOUT ANY WARRANTY; without even the implied warranty of
//[c] MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//[c] GNU General Public License for more details.
//[c]
//[c] You should have received a copy of the GNU General Public License
//[c] along with this program; if not, write to the Free Software
//[c] Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//[cf]
//[of]:imports
//[c]
public import "base/numbers"
public import "private/sys-graphics"
//[cf]
//[c]
//[of]:point
//[of]:structure
//[c]The structure is defined in sys-graphics for better integration
//[c]with platform
//[c]
/*public struct point
x: int
y: int
end*/
//[cf]
//[c]
//[of]:accessing
//[c]
public equ set x (p:point, x:int) = p.x = x
public equ set y (p:point, y:int) = p.y = y
//[cf]
//[cf]
//[of]:area
//[of]:structure
//[c]
public struct area
w: int
h: int
end
//[cf]
//[c]
//[of]:initialize
//[of]:set (a, src)
//[c]Initialize an Area by Copying Data from Another Area
//[c]
public func set (self: area, source: area)
w (self) = w (source)
h (self) = h (source)
end
//[cf]
//[of]:empty (a)
//[c]
public func empty (self: area)
w (self) = 0
h (self) = 0
end
//[cf]
//[cf]
//[of]:accessing
//[of]:width
//[c]
public equ width (a:area) = w (a)
//[cf]
//[of]:height
//[c]
public equ height (a:area) = h (a)
//[cf]
//[c]
//[of]:set (w, h)
//[c]
public func set(self: area, w: int, h: int)
w (self) = w
h (self) = h
end
//[cf]
//[of]:set w (w)
//[c]
public equ set w (a:area, w:int) = w (a) = w
//[cf]
//[of]:set h (h)
//[c]
public equ set h (a:area, h:int) = h (a) = h
//[cf]
//[of]:set width (w)
//[c]
public equ set width (a:area, w:int) = w (a) = w
//[cf]
//[of]:set height (h)
//[c]
public equ set height (a:area, h:int) = h (a) = h
//[cf]
//[cf]
//[cf]
//[of]:rectangle
//[of]:structure
//[c]The structure is defined in sys-graphics for better integration
//[c]with platform
//[c]
/*public struct rectangle
x: int
y: int
w: int
h: int
end*/
//[cf]
//[c]
//[of]:initialize
//[of]:rectangle (rectangle)
//[c]
public equ rectangle (source: rectangle, return r: rectangle) = set (r, source)
//[cf]
//[of]:rectangle (area)
//[c]
public equ rectangle (a: area, return r: rectangle) = set (r, a)
//[cf]
//[of]:rectangle (left, top, width, height)
//[c]
public equ rectangle (
left: int,
top: int,
width: int,
height: int,
return r: rectangle) =
set (r, left, top, width, height)
//[cf]
//[of]:rectangle from boundaries (left, top, right, bottom)
//[c]
public equ rectangle from boundaries (
left: int,
top: int,
right: int,
bottom: int,
return r: rectangle) =
set boundaries (r, left, top, right, bottom)
//[cf]
//[c]
//[of]:set (rectangle)
//[c]
public func set (r: rectangle, source: rectangle)
x (r) = x (source)
y (r) = y (source)
w (r) = w (source)
h (r) = h (source)
end
//[cf]
//[of]:set (area)
//[c]
public func set (r: rectangle, source: area)
x (r) = 0
y (r) = 0
w (r) = w (source)
h (r) = h (source)
end
//[cf]
//[of]:set (left, top, width, height)
//[c]
public func set (self: rectangle, left: int, top: int, width: int, height: int)
x (self) = left
y (self) = top
w (self) = width
h (self) = height
end
//[cf]
//[of]:set boundaries (left, top, right, bottom)
//[c]
public func set boundaries (self: rectangle, left: int, top: int, right: int, bottom: int)
x (self) = left
y (self) = top
w (self) = right - left
h (self) = bottom - top
end
//[cf]
//[c]
//[of]:empty
//[c]
public func empty (self: rectangle)
x (self) = 0
y (self) = 0
w (self) = 0
h (self) = 0
end
//[cf]
//[cf]
//[of]:binary operations
//[of]:intersection (r1, r2)
//[c]
public func intersection (r1: rectangle, r2: rectangle, return r: rectangle)
// use local variables because r can point at r1 or r2
def x = max (x (r1), x (r2))
def y = max (y (r1), y (r2))
def w = max (min (x (r1) + w (r1), x (r2) + w (r2)) - x, 0)
def h = max (min (y (r1) + h (r1), y (r2) + h (r2)) - y, 0)
x (r) = x
y (r) = y
w (r) = w
h (r) = h
end
//[cf]
//[of]:bounding box (r1, r2)
//[c]
public func bounding box (r1: rectangle, r2: rectangle, return r: rectangle)
// use local variables because r can point at r1 or r2
def x = min (x (r1), x (r2))
def y = min (y (r1), y (r2))
def w = max (x (r1) + w (r1), x (r2) + w (r2)) - x
def h = max (y (r1) + h (r1), y (r2) + h (r2)) - y
x (r) = x
y (r) = y
w (r) = w
h (r) = h
end
//[cf]
//[cf]
//[of]:translating
//[of]:move (left, top)
//[c]
public func move (r: rectangle, left: int, top: int)
x (r) = left
y (r) = top
end
//[cf]
//[cf]
//[of]:accessing
//[of]:left
//[c]
public equ left (r: rectangle) = x (r)
//[cf]
//[of]:right
//[c]
public equ right (r: rectangle) = x (r) + w (r)
//[cf]
//[of]:top
//[c]
public equ top (r: rectangle) = y (r)
//[cf]
//[of]:bottom
//[c]
public equ bottom (r: rectangle) = y (r) + h (r)
//[cf]
//[of]:width
//[c]
public equ width (r: rectangle) = w (r)
//[cf]
//[of]:height
//[c]
public equ height (r: rectangle) = h (r)
//[cf]
//[c]
//[of]:set x (x)
//[c]
public equ set x (r:rectangle, x:int) = x (r) = x
//[cf]
//[of]:set y (y)
//[c]
public equ set y (r:rectangle, y:int) = y (r) = y
//[cf]
//[of]:set w (w)
//[c]
public equ set w (r:rectangle, w:int) = w (r) = w
//[cf]
//[of]:set h (h)
//[c]
public equ set h (r:rectangle, h:int) = h (r) = h
//[cf]
//[c]
//[cf]
//[of]:testing
//[of]:contains (pt)
//[c]Tests if a rectangle contains a point
//[c]
//[c] The method is a bit long, it is optimized for code and speed.
//[c]
public func contains (r: rectangle, pt: point)
def a = x (pt)
def b = x (r)
if a < b
return false
end
b += w (r)
if a >= b
return false
end
a = y (pt)
b = y (r)
if a < b
return false
end
b += h (r)
if a >= b
return false
end
return true
end
//[cf]
//[of]:overlaps (r2)
//[c]
public func overlaps (r1: rectangle, r2: rectangle)
if x (r1) >= right (r2); return false ; end
if x (r2) >= right (r1); return false ; end
if y (r1) >= bottom (r2); return false ; end
if y (r2) >= bottom (r1); return false ; end
return true
end
//[cf]
//[of]:is equal (r2)
//[c]
public func is equal (self: rectangle, other: rectangle)
if x (self) <> x (other); return false; end
if y (self) <> y (other); return false; end
if w (self) <> w (other); return false; end
if h (self) <> h (other); return false; end
return true
end
//[cf]
//[of]:not equal (r2)
//[c]
public func not equal (self: rectangle, other: rectangle)
if x (self) <> x (other); return true; end
if y (self) <> y (other); return true; end
if w (self) <> w (other); return true; end
if h (self) <> h (other); return true; end
return false
end
//[cf]
//[of]:is empty
//[c]
public func is empty (self: rectangle)
if x (self) <> 0; return false; end
if y (self) <> 0; return false; end
if w (self) <> 0; return false; end
if h (self) <> 0; return false; end
return true
end
//[cf]
//[cf]
//[cf]
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -