Fix polygon builders

This commit is contained in:
Alexander Nozik 2023-08-22 22:52:17 +03:00
parent 1e29c5dbaa
commit 3529d0efc6
6 changed files with 27 additions and 10 deletions

View File

@ -209,9 +209,9 @@ private fun SolidGroup.addShape(
require(fNz > 1) { "The polyhedron geometry requires at least two planes" } require(fNz > 1) { "The polyhedron geometry requires at least two planes" }
val baseRadius = fRmax[0] val baseRadius = fRmax[0]
shape { shape {
(0..fNedges).forEach { (0..<fNedges).forEach {
val phi = deltaphi * fNedges * it + startphi val phi = deltaphi / fNedges * it + startphi
(baseRadius * cos(phi) to baseRadius * sin(phi)) point(baseRadius * cos(phi), baseRadius * sin(phi))
} }
} }
(0 until fNz).forEach { index -> (0 until fNz).forEach { index ->

View File

@ -0,0 +1,21 @@
package space.kscience.visionforge.examples
import space.kscience.visionforge.solid.ambientLight
import space.kscience.visionforge.solid.extruded
import space.kscience.visionforge.solid.polygon
import space.kscience.visionforge.solid.solid
fun main() = makeVisionFile {
vision("canvas") {
solid {
ambientLight()
extruded("extruded") {
shape{
polygon(8, 100)
layer(-30)
layer(30)
}
}
}
}
}

View File

@ -46,7 +46,7 @@ fun main() {
ambientLight { ambientLight {
color(Colors.white) color(Colors.white)
} }
rootGeo(geo,"BM@N", maxLayer = 3, ignoreRootColors = true).also { rootGeo(geo,"BM@N", ignoreRootColors = true).also {
Path("data/BM@N.vf.json").writeText(Solids.encodeToString(it)) Path("data/BM@N.vf.json").writeText(Solids.encodeToString(it))
} }
} }

View File

@ -35,7 +35,6 @@ public class VisionManager(meta: Meta) : AbstractPlugin(meta), MutableVisionCont
public val jsonFormat: Json public val jsonFormat: Json
get() = Json(defaultJson) { get() = Json(defaultJson) {
encodeDefaults = false
serializersModule = this@VisionManager.serializersModule serializersModule = this@VisionManager.serializersModule
} }
@ -85,7 +84,6 @@ public class VisionManager(meta: Meta) : AbstractPlugin(meta), MutableVisionCont
serializersModule = defaultSerialModule serializersModule = defaultSerialModule
prettyPrint = true prettyPrint = true
useArrayPolymorphism = false useArrayPolymorphism = false
encodeDefaults = false
ignoreUnknownKeys = true ignoreUnknownKeys = true
explicitNulls = false explicitNulls = false
} }

View File

@ -207,9 +207,9 @@ private class GdmlLoader(val settings: GdmlLoaderOptions) {
require(solid.planes.size > 1) { "The polyhedron geometry requires at least two planes" } require(solid.planes.size > 1) { "The polyhedron geometry requires at least two planes" }
val baseRadius = solid.planes.first().rmax * lScale val baseRadius = solid.planes.first().rmax * lScale
shape { shape {
(0..solid.numsides).forEach { (0..<solid.numsides).forEach {
val phi = solid.deltaphi * aScale / solid.numsides * it + solid.startphi * aScale val phi = solid.deltaphi * aScale / solid.numsides * it + solid.startphi * aScale
(baseRadius * cos(phi) to baseRadius * sin(phi)) point(baseRadius * cos(phi), baseRadius * sin(phi))
} }
} }
solid.planes.forEach { plane -> solid.planes.forEach { plane ->

View File

@ -23,8 +23,6 @@ public class Shape2DBuilder(private val points: ArrayList<Float32Vector2D> = Arr
points.add(Float32Vector2D(x, y)) points.add(Float32Vector2D(x, y))
} }
public infix fun Number.to(y: Number): Unit = point(this, y)
public fun build(): Shape2D = points public fun build(): Shape2D = points
} }