point.st

来自「四皇后问题」· ST 代码 · 共 71 行

ST
71
字号
Class Point :Magnitude
| xvalue yvalue |
[
	< aPoint
		^ (xvalue < aPoint x) and: [yvalue < aPoint y]
|
	<= aPoint
		^ (xvalue <= aPoint x) and: [yvalue < aPoint y]
|
	>= aPoint
		^ (xvalue >= aPoint x) and: [yvalue >= aPoint y]
|
	= aPoint
		^ (xvalue = aPoint x) and: [yvalue = aPoint y]
|
	* scale
		^ (Point new x: (xvalue * scale)) y: (yvalue * scale)
|
	+ delta
		^ (Point new x: (xvalue + delta x)) y: (yvalue + delta y)
|
	- delta
		^ (Point new x: (xvalue - delta x)) y: (yvalue - delta y)
|
	/ scale
		^ (Point new x: (xvalue / scale)) y: (yvalue / scale)
|
	// scale
		^ (Point new x: (xvalue // scale)) y: (yvalue // scale)
|
	abs
		^ (Point new x: xvalue abs) y: (yvalue abs)
|
	asString
		^ xvalue asString , ' @ ' , (yvalue asString)
|
	dist: aPoint
		^ ((xvalue - aPoint x) squared + 
			(yvalue - aPoint y) squared) sqrt
|
	max: aPoint
		^ (Point new x: (xvalue max: aPoint x))
			y: (yvalue max: aPoint y)
|
	min: aPoint
		^ (Point new x: (xvalue min: aPoint x))
			y: (yvalue min: aPoint y)
|
	printString
		^ xvalue printString , ' @ ' , (yvalue printString)
|
	transpose
		^ (Point new x: yvalue) y: xvalue
|
	x
		^ xvalue
|
	x: aValue
		xvalue <- aValue
|
	x: xValue y: yValue
		xvalue <- xValue.
		yvalue <- yValue
|
	y
		^ yvalue
|
	y: aValue
		yvalue <- aValue
]

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?