All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.org.jetbrains.letsPlot.livemap.mapengine.Context2dEx.kt Maven / Gradle / Ivy

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)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy