Skip to content

Commit 5e6b456

Browse files
committed
Vector2D 和 Vector3D 可以是数据类
1 parent 4d11125 commit 5e6b456

3 files changed

Lines changed: 105 additions & 112 deletions

File tree

build.gradle.kts

Lines changed: 89 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
22

33
plugins {
44
kotlin("jvm") version "1.3.50" apply (true)
5-
id("org.jetbrains.dokka") version "0.9.18"
6-
id("com.jfrog.bintray") version "1.8.4"
7-
`maven-publish`
5+
// id("org.jetbrains.dokka") version "0.9.18"
6+
// id("com.jfrog.bintray") version "1.8.4"
7+
// `maven-publish`
88
`build-scan`
99
}
1010

@@ -15,8 +15,7 @@ buildScan {
1515
}
1616

1717
group = "org.mechdancer"
18-
version = "0.2.5-dev-3"
19-
18+
version = "0.2.6-dev-1"
2019

2120
repositories {
2221
mavenCentral()
@@ -34,98 +33,96 @@ tasks.withType<KotlinCompile> {
3433
}
3534
}
3635

36+
//tasks.dokka {
37+
// outputFormat = "javadoc"
38+
// outputDirectory = "$buildDir/javadoc"
39+
//}
3740

38-
tasks.dokka {
39-
outputFormat = "javadoc"
40-
outputDirectory = "$buildDir/javadoc"
41-
}
42-
43-
val doc = tasks.register<Jar>("javadocJar") {
44-
group = JavaBasePlugin.DOCUMENTATION_GROUP
45-
description = "Assembles Kotlin docs with Dokka"
46-
archiveClassifier.set("javadoc")
47-
from(tasks.dokka)
48-
}
41+
//val doc = tasks.register<Jar>("javadocJar") {
42+
// group = JavaBasePlugin.DOCUMENTATION_GROUP
43+
// description = "Assembles Kotlin docs with Dokka"
44+
// archiveClassifier.set("javadoc")
45+
// from(tasks.dokka)
46+
//}
4947

5048
val sources = tasks.register<Jar>("sourcesJar") {
5149
group = JavaBasePlugin.BUILD_TASK_NAME
5250
description = "Creates sources jar"
5351
archiveClassifier.set("sources")
5452
from(sourceSets.main.get().allSource)
5553
}
56-
57-
val fat = tasks.register<Jar>("fatJar") {
58-
group = JavaBasePlugin.BUILD_TASK_NAME
59-
description = "Packs binary output with dependencies"
60-
archiveClassifier.set("all")
61-
from(sourceSets.main.get().output)
62-
from({
63-
configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
64-
})
65-
}
66-
67-
tasks.register("allJars") {
68-
group = JavaBasePlugin.BUILD_TASK_NAME
69-
description = "Assembles all jars in one task"
70-
dependsOn(doc, sources, fat, tasks.jar)
71-
}
72-
73-
val rename = tasks.register("renamePomFile") {
74-
dependsOn(tasks.publishToMavenLocal)
75-
doLast {
76-
val path = "${buildDir.absolutePath}/publications/maven/"
77-
val old = File(path + "pom-default.xml")
78-
val f = File("$path${project.name}-$version.pom")
79-
old.renameTo(f)
80-
}
81-
}
82-
83-
tasks.bintrayUpload.configure {
84-
dependsOn(rename)
85-
}
86-
87-
bintray {
88-
user = "berberman"
89-
key = System.getenv("BintrayToken")
90-
setConfigurations("archives")
91-
val v = version.toString()
92-
val url = "https://github.com/MechDancer/linearalgebra"
93-
publish = true
94-
pkg.apply {
95-
name = project.name
96-
desc = "linearalgebra kotlin utilities"
97-
repo = "maven"
98-
userOrg = "mechdancer"
99-
githubRepo = "MechDancer/linearalgebra"
100-
vcsUrl = "$url.git"
101-
issueTrackerUrl = "$url/issues"
102-
publicDownloadNumbers = true
103-
setLicenses("WTFPL")
104-
version.apply {
105-
name = v
106-
vcsTag = v
107-
websiteUrl = "$url/releases/tag/$v"
108-
}
109-
}
110-
}
111-
112-
publishing {
113-
repositories {
114-
maven("$buildDir/repo")
115-
}
116-
117-
publications {
118-
create<MavenPublication>("maven") {
119-
from(components["java"])
120-
}
121-
}
122-
}
123-
124-
artifacts {
125-
add("archives", tasks.jar)
126-
add("archives", fat)
127-
add("archives", sources)
128-
add("archives", doc)
129-
add("archives", File("${buildDir.absolutePath}/publications/maven/${project.name}-$version.pom"))
130-
131-
}
54+
//
55+
//val fat = tasks.register<Jar>("fatJar") {
56+
// group = JavaBasePlugin.BUILD_TASK_NAME
57+
// description = "Packs binary output with dependencies"
58+
// archiveClassifier.set("all")
59+
// from(sourceSets.main.get().output)
60+
// from({
61+
// configurations.runtimeClasspath.get().filter { it.name.endsWith("jar") }.map { zipTree(it) }
62+
// })
63+
//}
64+
//
65+
//tasks.register("allJars") {
66+
// group = JavaBasePlugin.BUILD_TASK_NAME
67+
// description = "Assembles all jars in one task"
68+
// dependsOn(doc, sources, fat, tasks.jar)
69+
//}
70+
//
71+
//val rename = tasks.register("renamePomFile") {
72+
// dependsOn(tasks.publishToMavenLocal)
73+
// doLast {
74+
// val path = "${buildDir.absolutePath}/publications/maven/"
75+
// val old = File(path + "pom-default.xml")
76+
// val f = File("$path${project.name}-$version.pom")
77+
// old.renameTo(f)
78+
// }
79+
//}
80+
//
81+
//tasks.bintrayUpload.configure {
82+
// dependsOn(rename)
83+
//}
84+
//
85+
//bintray {
86+
// user = "berberman"
87+
// key = System.getenv("BintrayToken")
88+
// setConfigurations("archives")
89+
// val v = version.toString()
90+
// val url = "https://github.com/MechDancer/linearalgebra"
91+
// publish = true
92+
// pkg.apply {
93+
// name = project.name
94+
// desc = "linearalgebra kotlin utilities"
95+
// repo = "maven"
96+
// userOrg = "mechdancer"
97+
// githubRepo = "MechDancer/linearalgebra"
98+
// vcsUrl = "$url.git"
99+
// issueTrackerUrl = "$url/issues"
100+
// publicDownloadNumbers = true
101+
// setLicenses("WTFPL")
102+
// version.apply {
103+
// name = v
104+
// vcsTag = v
105+
// websiteUrl = "$url/releases/tag/$v"
106+
// }
107+
// }
108+
//}
109+
//
110+
//publishing {
111+
// repositories {
112+
// maven("$buildDir/repo")
113+
// }
114+
//
115+
// publications {
116+
// create<MavenPublication>("maven") {
117+
// from(components["java"])
118+
// }
119+
// }
120+
//}
121+
//
122+
//artifacts {
123+
// add("archives", tasks.jar)
124+
// add("archives", fat)
125+
// add("archives", sources)
126+
// add("archives", doc)
127+
// add("archives", File("${buildDir.absolutePath}/publications/maven/${project.name}-$version.pom"))
128+
//}

src/main/kotlin/org/mechdancer/algebra/implement/vector/Vector2D.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ import org.mechdancer.algebra.function.vector.y
88
import org.mechdancer.algebra.hash
99
import kotlin.math.hypot
1010

11-
class Vector2D(val x: Double, val y: Double) : Vector {
11+
data class Vector2D(val x: Double, val y: Double) : Vector {
1212
override val dim = 2
1313

14+
override val length by lazy { hypot(x, y) }
15+
1416
override fun get(i: Int) =
1517
when (i) {
1618
0 -> x
1719
1 -> y
1820
else -> throw IllegalArgumentException()
1921
}
2022

21-
override val length by lazy { hypot(x, y) }
22-
2323
override fun toList() = listOf(x, y)
2424

2525
override fun equals(other: Any?) =
2626
this === other
27-
|| (other is Vector
27+
|| (other is Vector
2828
&& other.dim == 2
2929
&& doubleEquals(other.x, x)
3030
&& doubleEquals(other.y, y))

src/main/kotlin/org/mechdancer/algebra/implement/vector/Vector3D.kt

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,29 @@ import org.mechdancer.algebra.function.vector.z
99
import org.mechdancer.algebra.hash
1010
import kotlin.math.sqrt
1111

12-
class Vector3D(val x: Double, val y: Double, val z: Double) : Vector {
13-
12+
data class Vector3D(val x: Double, val y: Double, val z: Double) : Vector {
1413
override val dim: Int = 3
1514

1615
override val length: Double by lazy { sqrt(x * x + y * y + z * z) }
1716

18-
override fun equals(other: Any?): Boolean =
19-
this === other
20-
|| (other is Vector
21-
&& other.dim == 3
22-
&& doubleEquals(other.x, x)
23-
&& doubleEquals(other.y, y)
24-
&& doubleEquals(other.z, z)
25-
)
26-
27-
2817
override fun get(i: Int): Double = when (i) {
2918
0 -> x
3019
1 -> y
3120
2 -> z
3221
else -> throw IllegalArgumentException()
3322
}
3423

35-
override fun hashCode(): Int = hash(x, y, z)
36-
3724
override fun toList(): List<Double> = listOf(x, y, z)
3825

39-
override fun toString(): String = columnView()
26+
override fun equals(other: Any?): Boolean =
27+
this === other
28+
|| (other is Vector
29+
&& other.dim == 3
30+
&& doubleEquals(other.x, x)
31+
&& doubleEquals(other.y, y)
32+
&& doubleEquals(other.z, z))
33+
34+
override fun hashCode(): Int = hash(x, y, z)
4035

41-
}
36+
override fun toString(): String = columnView()
37+
}

0 commit comments

Comments
 (0)