commonMain.org.jetbrains.letsPlot.livemap.mapengine.Context2dEx.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of livemap-jvm Show documentation
Show all versions of livemap-jvm Show documentation
A part of the Lets-Plot library.
The newest version!
/*
* Copyright (c) 2023. JetBrains s.r.o.
* Use of this source code is governed by the MIT license that can be found in the LICENSE file.
*/
package org.jetbrains.letsPlot.livemap.mapengine
import org.jetbrains.letsPlot.commons.geometry.DoubleVector
import org.jetbrains.letsPlot.commons.intern.typedGeometry.MultiPolygon
import org.jetbrains.letsPlot.commons.intern.typedGeometry.Rect
import org.jetbrains.letsPlot.commons.intern.typedGeometry.Vec
import org.jetbrains.letsPlot.core.canvas.Context2d
import org.jetbrains.letsPlot.livemap.Client
import org.jetbrains.letsPlot.livemap.ClientPoint
fun Context2d.scale(scale: DoubleVector) = scale(scale.x, scale.y)
fun Context2d.scale(scale: ClientPoint) = scale(scale.x, scale.y)
fun Context2d.moveTo(p: Vec) = moveTo(p.x, p.y)
fun Context2d.lineTo(p: Vec) = lineTo(p.x, p.y)
fun Context2d.translate(p: Vec) = translate(p.x, p.y)
fun Context2d.fillRect(r: Rect) = fillRect(r.origin.x, r.origin.y, r.dimension.x, r.dimension.y)
fun Context2d.strokeRect(r: Rect) = strokeRect(r.origin.x, r.origin.y, r.dimension.x, r.dimension.y)
fun Context2d.drawMultiPolygon(geometry: MultiPolygon, afterPolygon: (Context2d) -> Unit) {
for (polygon in geometry) {
for (ring in polygon) {
ring[0].let(::moveTo)
ring.asSequence().drop(1).forEach(::lineTo)
}
}
afterPolygon(this)
}