[orx-shapes] convert to MPP
This commit is contained in:
7
orx-shapes/src/jvmTest/kotlin/Assertions.kt
Normal file
7
orx-shapes/src/jvmTest/kotlin/Assertions.kt
Normal file
@@ -0,0 +1,7 @@
|
||||
import org.amshove.kluent.shouldBeInRange
|
||||
import org.openrndr.math.Vector2
|
||||
|
||||
infix fun Vector2.`should be near`(other: Vector2) {
|
||||
x shouldBeInRange (other.x - 0.00001..other.x + 0.00001)
|
||||
y shouldBeInRange (other.y - 0.00001..other.y + 0.00001)
|
||||
}
|
||||
156
orx-shapes/src/jvmTest/kotlin/TestChamferCorners.kt
Normal file
156
orx-shapes/src/jvmTest/kotlin/TestChamferCorners.kt
Normal file
@@ -0,0 +1,156 @@
|
||||
import org.amshove.kluent.`should be equal to`
|
||||
import org.openrndr.extra.shapes.operators.bevelCorners
|
||||
import org.openrndr.extra.shapes.operators.roundCorners
|
||||
import org.openrndr.extra.shapes.regularPolygon
|
||||
import org.openrndr.shape.Circle
|
||||
import org.openrndr.shape.contour
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
|
||||
object TestChamferCorners : Spek({
|
||||
|
||||
describe("a single segment linear contour") {
|
||||
val c = contour {
|
||||
moveTo(0.0, 0.0)
|
||||
lineTo(100.0, 100.0)
|
||||
}
|
||||
|
||||
it("should be similar to a chamfered version") {
|
||||
val cc = c.bevelCorners(10.0)
|
||||
cc.segments.size `should be equal to` 1
|
||||
cc.position(0.0) `should be near` c.position(0.0)
|
||||
cc.position(1.0) `should be near` c.position(1.0)
|
||||
cc.closed `should be equal to` c.closed
|
||||
}
|
||||
}
|
||||
|
||||
describe("a single segment quadratic contour") {
|
||||
val c = contour {
|
||||
moveTo(0.0, 0.0)
|
||||
curveTo(40.0, 40.0, 100.0, 100.0)
|
||||
}
|
||||
|
||||
it("should be similar to a chamfered version") {
|
||||
val cc = c.bevelCorners(10.0)
|
||||
cc.segments.size `should be equal to` 1
|
||||
cc.position(0.0) `should be near` c.position(0.0)
|
||||
cc.position(0.5) `should be near` c.position(0.5)
|
||||
cc.position(1.0) `should be near` c.position(1.0)
|
||||
}
|
||||
}
|
||||
|
||||
describe("a circle contour") {
|
||||
val c = Circle(0.0, 0.0, 200.0).contour
|
||||
|
||||
it("should be similar to a chamfered version") {
|
||||
val cc = c.bevelCorners(10.0)
|
||||
cc.segments.size `should be equal to` c.segments.size
|
||||
cc.position(0.0) `should be near` c.position(0.0)
|
||||
cc.position(0.5) `should be near` c.position(0.5)
|
||||
cc.position(1.0) `should be near` c.position(1.0)
|
||||
cc.closed `should be equal to` c.closed
|
||||
c.winding `should be equal to` cc.winding
|
||||
}
|
||||
}
|
||||
|
||||
describe("a two segment linear contour") {
|
||||
val c = contour {
|
||||
moveTo(0.0, 0.0)
|
||||
lineTo(50.0, 50.0)
|
||||
lineTo(100.0, 50.0)
|
||||
}
|
||||
it("should chamfer correctly") {
|
||||
val cc = c.bevelCorners(10.0)
|
||||
cc.segments.size `should be equal to` 3
|
||||
cc.position(0.0) `should be near` c.position(0.0)
|
||||
cc.position(1.0) `should be near` c.position(1.0)
|
||||
cc.closed `should be equal to` c.closed
|
||||
}
|
||||
}
|
||||
|
||||
describe("a two segment linear-curve contour") {
|
||||
val c = contour {
|
||||
moveTo(0.0, 0.0)
|
||||
lineTo(50.0, 50.0)
|
||||
curveTo(80.0, 120.0, 100.0, 50.0)
|
||||
}
|
||||
it("should be identical to the chamfered version") {
|
||||
val cc = c.bevelCorners(10.0)
|
||||
cc.segments.size `should be equal to` c.segments.size
|
||||
cc.position(0.0) `should be near` c.position(0.0)
|
||||
cc.position(1.0) `should be near` c.position(1.0)
|
||||
cc.closed `should be equal to` c.closed
|
||||
}
|
||||
}
|
||||
|
||||
describe("a two segment curve-linear contour") {
|
||||
val c = contour {
|
||||
moveTo(0.0, 0.0)
|
||||
curveTo(80.0, 120.0, 50.0, 50.0)
|
||||
lineTo(100.0, 50.0)
|
||||
|
||||
}
|
||||
it("should be identical to the chamfered version") {
|
||||
val cc = c.bevelCorners(10.0)
|
||||
cc.segments.size `should be equal to` c.segments.size
|
||||
cc.position(0.0) `should be near` c.position(0.0)
|
||||
cc.position(1.0) `should be near` c.position(1.0)
|
||||
cc.closed `should be equal to` c.closed
|
||||
}
|
||||
}
|
||||
|
||||
describe("a two segment curve-linear contour") {
|
||||
val c = contour {
|
||||
moveTo(0.0, 0.0)
|
||||
curveTo(80.0, 120.0, 50.0, 50.0)
|
||||
lineTo(100.0, 50.0)
|
||||
|
||||
}
|
||||
it("should be identical to the chamfered version") {
|
||||
val cc = c.bevelCorners(10.0)
|
||||
cc.segments.size `should be equal to` c.segments.size
|
||||
cc.position(0.0) `should be near` c.position(0.0)
|
||||
cc.position(1.0) `should be near` c.position(1.0)
|
||||
cc.closed `should be equal to` c.closed
|
||||
}
|
||||
}
|
||||
|
||||
describe("a triangle") {
|
||||
val c = regularPolygon(3, radius = 100.0)
|
||||
|
||||
c.closed `should be equal to` true
|
||||
|
||||
val cc = c.roundCorners(1.0)
|
||||
|
||||
c.winding `should be equal to` cc.winding
|
||||
|
||||
c.closed `should be equal to` cc.closed
|
||||
|
||||
val ccc = cc.roundCorners(1.0)
|
||||
|
||||
ccc.closed `should be equal to` cc.closed
|
||||
|
||||
cc.segments.size `should be equal to` 6
|
||||
|
||||
// cc.segments.forEach {
|
||||
// println(it)
|
||||
// }
|
||||
|
||||
// println("---")
|
||||
// ccc.segments.forEach {
|
||||
// println(it)
|
||||
// }
|
||||
it("should have 6 sides") {
|
||||
ccc.segments.size `should be equal to` cc.segments.size
|
||||
}
|
||||
it("should start at the right position") {
|
||||
ccc.position(0.0) `should be near` cc.position(0.0)
|
||||
}
|
||||
it("should end at the right position") {
|
||||
ccc.position(1.0) `should be near` cc.position(1.0)
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
})
|
||||
49
orx-shapes/src/jvmTest/kotlin/TestRegularPolygon.kt
Normal file
49
orx-shapes/src/jvmTest/kotlin/TestRegularPolygon.kt
Normal file
@@ -0,0 +1,49 @@
|
||||
import org.amshove.kluent.`should be equal to`
|
||||
import org.openrndr.extra.shapes.regularPolygon
|
||||
import org.openrndr.extra.shapes.regularPolygonBeveled
|
||||
import org.openrndr.extra.shapes.regularPolygonRounded
|
||||
import org.openrndr.shape.Winding
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
|
||||
object TestRegularPolygon : Spek({
|
||||
|
||||
|
||||
describe("a regular polygon with 3 sides") {
|
||||
val rp = regularPolygon(3)
|
||||
|
||||
it("is closed") {
|
||||
rp.closed `should be equal to` true
|
||||
}
|
||||
|
||||
it("has clockwise winding") {
|
||||
rp.winding `should be equal to` Winding.CLOCKWISE
|
||||
}
|
||||
}
|
||||
|
||||
describe("a regular polygon with rounded corners and 3 sides") {
|
||||
val rp = regularPolygonRounded(3)
|
||||
|
||||
it("is closed") {
|
||||
rp.closed `should be equal to` true
|
||||
}
|
||||
|
||||
it("has clockwise winding") {
|
||||
rp.winding `should be equal to` Winding.CLOCKWISE
|
||||
}
|
||||
}
|
||||
|
||||
describe("a regular polygon with beveled corners and 3 sides") {
|
||||
val rp = regularPolygonBeveled(3)
|
||||
|
||||
it("is closed") {
|
||||
rp.closed `should be equal to` true
|
||||
}
|
||||
|
||||
it("has clockwise winding") {
|
||||
rp.winding `should be equal to` Winding.CLOCKWISE
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
})
|
||||
47
orx-shapes/src/jvmTest/kotlin/TestRegularStar.kt
Normal file
47
orx-shapes/src/jvmTest/kotlin/TestRegularStar.kt
Normal file
@@ -0,0 +1,47 @@
|
||||
import org.amshove.kluent.`should be equal to`
|
||||
import org.openrndr.extra.shapes.regularPolygonBeveled
|
||||
import org.openrndr.extra.shapes.regularPolygonRounded
|
||||
import org.openrndr.extra.shapes.regularStar
|
||||
import org.openrndr.extra.shapes.regularStarRounded
|
||||
import org.openrndr.shape.Winding
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
|
||||
object TestRegularStar : Spek({
|
||||
describe("a regular star with 5 points") {
|
||||
val rs = regularStar(5, 10.0, 20.0)
|
||||
|
||||
it("is closed") {
|
||||
rs.closed `should be equal to` true
|
||||
}
|
||||
|
||||
it("has clockwise winding") {
|
||||
rs.winding `should be equal to` Winding.CLOCKWISE
|
||||
}
|
||||
}
|
||||
|
||||
describe("a regular star with rounded corners and 5 points") {
|
||||
val rs = regularStarRounded(5, 10.0, 20.0, 0.2, 0.2)
|
||||
|
||||
it("is closed") {
|
||||
rs.closed `should be equal to` true
|
||||
}
|
||||
|
||||
it("has clockwise winding") {
|
||||
rs.winding `should be equal to` Winding.CLOCKWISE
|
||||
}
|
||||
}
|
||||
|
||||
describe("a regular star with beveled corners and 5 points") {
|
||||
val rs = regularPolygonBeveled(5, 0.5)
|
||||
|
||||
it("is closed") {
|
||||
rs.closed `should be equal to` true
|
||||
}
|
||||
|
||||
it("has clockwise winding") {
|
||||
rs.winding `should be equal to` Winding.CLOCKWISE
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
20
orx-shapes/src/jvmTest/kotlin/TestRoundedRectangle.kt
Normal file
20
orx-shapes/src/jvmTest/kotlin/TestRoundedRectangle.kt
Normal file
@@ -0,0 +1,20 @@
|
||||
import org.amshove.kluent.`should be equal to`
|
||||
import org.openrndr.extra.shapes.*
|
||||
import org.openrndr.shape.Winding
|
||||
import org.spekframework.spek2.Spek
|
||||
import org.spekframework.spek2.style.specification.describe
|
||||
|
||||
object TestRoundedRectangle : Spek({
|
||||
describe("a rounded square") {
|
||||
val rs = RoundedRectangle(100.0, 100.0, 200.0, 200.0, 20.0).contour
|
||||
|
||||
it("is closed") {
|
||||
rs.closed `should be equal to` true
|
||||
}
|
||||
|
||||
it("has clockwise winding") {
|
||||
rs.winding `should be equal to` Winding.CLOCKWISE
|
||||
}
|
||||
}
|
||||
|
||||
})
|
||||
Reference in New Issue
Block a user