-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f0c948
commit 50e586a
Showing
21 changed files
with
208 additions
and
360 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ plugins { | |
} | ||
|
||
group 'moe.rainbowyang' | ||
version '0.1.3' | ||
version '0.2.0' | ||
|
||
repositories { | ||
mavenCentral() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package moe.rainbowyang.math.graphics | ||
|
||
/** | ||
* 抽象图形 | ||
* @author: Rainbow Yang | ||
* @create: 2018-11-14 18:52 | ||
**/ | ||
interface Graphics |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/main/kotlin/moe/rainbowyang/math/graphics/point/Point.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package moe.rainbowyang.math.graphics.point | ||
|
||
import moe.rainbowyang.math.graphics.Graphics | ||
import moe.rainbowyang.math.number.Real | ||
import moe.rainbowyang.math.operation.Addition | ||
|
||
/** | ||
* 抽象点 | ||
* 所有子类的所有操作均不应修改其本身,而是返回一个新的类 | ||
* 所有点之间都应能够进行互相转换,可以用[PointAxes]作为中介 | ||
* @author Rainbow Yang | ||
*/ | ||
abstract class Point : Graphics, Addition<Point> { | ||
|
||
/** | ||
* 转换为[PointAxes] | ||
*/ | ||
abstract val asAxes: PointAxes | ||
|
||
/** | ||
* 检测该点中是否没有[Double.NaN]之类无效的值 | ||
*/ | ||
open val available: Boolean get() = asAxes.available | ||
|
||
/** | ||
* 默认通过[PointAxes]进行计算,值为其模 | ||
*/ | ||
open val length: Real get() = asAxes.length | ||
|
||
override operator fun plus(other: Point): Point = asAxes.plus(other.asAxes) | ||
override operator fun unaryMinus(): Point = this * -Real.ONE | ||
|
||
open operator fun times(times: Real): Point = asAxes * times | ||
open operator fun div(div: Real): Point = this * div.reciprocal() | ||
|
||
override fun equals(other: Any?): Boolean = asAxes == other | ||
override fun hashCode(): Int = asAxes.hashCode() | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/kotlin/moe/rainbowyang/math/graphics/point/Point2D.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package moe.rainbowyang.math.graphics.point | ||
|
||
import moe.rainbowyang.math.number.Real | ||
import moe.rainbowyang.math.number.atan2 | ||
|
||
/** | ||
* 二维笛卡尔坐标系点 | ||
* @author Rainbow Yang | ||
*/ | ||
data class Point2D(val x: Real, val y: Real) : Point() { | ||
|
||
constructor(point: PointAxes) : this(point[0], point[1]) | ||
|
||
override val asAxes = PointAxes(x, y) | ||
|
||
val angle = atan2(y, x) | ||
|
||
/** | ||
* 逆时针旋转[angle]【弧度】 | ||
*/ | ||
fun spin(angle: Real) = asPoint2DPolar.spin(angle).asPoint2D | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/kotlin/moe/rainbowyang/math/graphics/point/Point2DPolar.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package moe.rainbowyang.math.graphics.point | ||
|
||
import moe.rainbowyang.math.number.Real | ||
import moe.rainbowyang.math.number.toReal | ||
import moe.rainbowyang.math.operation.cos | ||
import moe.rainbowyang.math.operation.sin | ||
|
||
/** | ||
* 二维极坐标点 | ||
* @author Rainbow Yang | ||
*/ | ||
data class Point2DPolar(val radius: Real, val angle: Real) : Point() { | ||
|
||
constructor(radius: Number, angle: Number) : this(radius.toReal(), angle.toReal()) | ||
|
||
companion object { | ||
operator fun invoke(form: Point): Point2DPolar { | ||
val pd = form.asPoint2D | ||
return Point2DPolar(pd.length, pd.angle) | ||
} | ||
} | ||
|
||
override val asAxes by lazy { PointAxes(radius * cos(angle), radius * sin(angle)) } | ||
|
||
/** | ||
* 逆时针旋转[angle]【弧度】 | ||
*/ | ||
fun spin(angle: Real) = Point2DPolar(radius, this.angle + angle) | ||
|
||
} | ||
|
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/moe/rainbowyang/math/graphics/point/Point3D.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package moe.rainbowyang.math.graphics.point | ||
|
||
import moe.rainbowyang.math.number.Real | ||
import moe.rainbowyang.math.number.toReal | ||
|
||
/** | ||
* 三维轴坐标点 | ||
* @author Rainbow Yang | ||
*/ | ||
data class Point3D(val x: Real, val y: Real, val z: Real) : Point() { | ||
|
||
constructor(x: Number = 0, y: Number = 0, z: Number = 0) : this(x.toReal(), y.toReal(), z.toReal()) | ||
|
||
companion object { | ||
operator fun invoke(form: Point): Point3D { | ||
val (x, y, z) = form.asAxes | ||
return Point3D(x, y, z) | ||
} | ||
} | ||
|
||
override val asAxes = PointAxes(x, y, z) | ||
|
||
fun spinAtXY(angle: Real) = asAxes.spinAtAndNew(0, 1, angle) | ||
fun spinAtXZ(angle: Real) = asAxes.spinAtAndNew(0, 2, angle) | ||
fun spinAtYX(angle: Real) = asAxes.spinAtAndNew(1, 0, angle) | ||
fun spinAtYZ(angle: Real) = asAxes.spinAtAndNew(1, 2, angle) | ||
fun spinAtZX(angle: Real) = asAxes.spinAtAndNew(2, 0, angle) | ||
fun spinAtZY(angle: Real) = asAxes.spinAtAndNew(2, 1, angle) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.