semagrams.util

A package for useful non-Semagrams-specific functionality

Attributes

Members list

Concise view

Type members

Classlikes

case class Complex(x: Double, y: Double)

A class representing a complex number

A class representing a complex number

We use complex numbers for two-dimensional geometry because they can represent either:

  • A point
  • A vector
  • A translation
  • A rotation/scaling

Instead of having to remember APIs for all of these, you can just use familiar arithmetic operations.

The operations here are the standard mathematical ones for the complex numbers.

Attributes

Companion:
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
object Complex

Attributes

Companion:
class
Graph
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
Complex.type
object CustomAttr

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
class LensedVar[A, B](val v: UndoableVar[A], val l: Lens[A, B])

A view of a variable. Uses a lens to forward gets and sets to an underlying UndoableVar.

A view of a variable. Uses a lens to forward gets and sets to an underlying UndoableVar.

Note: this is specialized to UndoableVar right now because there isn't an informative superclass of both UndoableVar and Var. At some point we should fix this.

Maybe we should send a PR with UndoableVar and LensedVar to Laminar?

Attributes

Todo:

implement more of the Var api.

Graph
Supertypes
class Object
trait Matchable
class Any
case object NoneError extends Exception

Attributes

Graph
Supertypes
trait Singleton
trait Product
trait Mirror
trait Product
trait Equals
class Exception
class Throwable
trait Serializable
class Object
trait Matchable
class Any
Self type
object Path

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Path.type
case class Transform(z: Complex, w: Complex)

Represents an affine transformation of the 2d plane

Represents an affine transformation of the 2d plane

Attributes

w

the translation factor Note: scaling is applied before translation.

z

the scaling/twisting factor

Companion:
object
Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
object Transform

Attributes

Companion:
class
Graph
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
case class UndoState[A](recording: Boolean, past: List[A], present: A, future: List[A])

The internal state of an UndoableVar, implemented as a cursor into a list.

The internal state of an UndoableVar, implemented as a cursor into a list.

Attributes

future

states that we have undone (for redo). This goes away once you start editing from a state in the past; we don't have undo trees yet.

past

previous states (for undoing)

present

current state

recording

indicator for whether we should record updates or not

Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
class UndoableVar[A](init: A) extends SignalSource[A] with Sink[A]

A class similar to Var but with support for undo and redo.

A class similar to Var but with support for undo and redo.

Attributes

Graph
Supertypes
trait Sink[A]
trait SignalSource[A]
trait Source[A]
class Object
trait Matchable
class Any

Custom laminar attributes for using complex numbers with svg more easily

Custom laminar attributes for using complex numbers with svg more easily

These can be used both

  • with signals, i.e. xy <-- z,
  • with values, i.e. xy := z.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Value members

Concrete methods

def bijectiveRW[A](as: Iterable[A]): ReadWriter[A]
def boxSize(text: String, fontSize: Double): Complex

Returns the dimensions of the bounding box for text at fontSize

Returns the dimensions of the bounding box for text at fontSize

This caches computations, so that repeated queries are fast.

Attributes

Todo:

we hardcode most of the style for this; we should make this more flexible.

def fromMaybe[Model, A](a: IO[Option[A]]): IO[A]

A convenience wrapper around calling unwrap for IO

A convenience wrapper around calling unwrap for IO

Attributes

def msgError(msg: String): RuntimeException
def tikzInPorts(pts: Seq[Part], shape: String): String

Create the declarations for a sequence of input ports. Include a shape string to make the ports visible.

Create the declarations for a sequence of input ports. Include a shape string to make the ports visible.

Attributes

def tikzLabel(label: String, size: String): String

Convert strings to Tikz labels by converting "\n" to "\"

Convert strings to Tikz labels by converting "\n" to "\"

Attributes

def tikzNode(shape: String, nodename: String, ctr: Complex, label: String, draw: Boolean): String

Create the declaration of a Tikz node.

Create the declaration of a Tikz node.

Attributes

def tikzOutPorts(pts: Seq[Part], shape: String): String

Create the declarations for a sequence of input ports. Include a shape string to make the ports visible.

Create the declarations for a sequence of input ports. Include a shape string to make the ports visible.

Attributes

def tikzPort(p: Part, idx: Int, n_ports: Int, shape: String): String

Create the declaration for a single node along a path.

Create the declaration for a single node along a path.

Attributes

def tikzPorts(pts: Seq[Part], start: String, stop: String, shape: String): String

Create the declarations for a sequence of nodes along a path from start to stop. Include a shape string to make the nodes visible.

Create the declarations for a sequence of nodes along a path from start to stop. Include a shape string to make the nodes visible.

Attributes

def tikzWrapper(inside: String): String

Wrap tikz declarations in the surrounding LaTeX

Wrap tikz declarations in the surrounding LaTeX

Attributes

def wrappedHtml(el: Element, pos: Signal[Complex], dims: Signal[Complex]): ReactiveSvgElement[SVGElement]

Make an SVG element containing the html object.

Make an SVG element containing the html object.

We have to specify manually the dimensions and position of the html, because SVG does not have automatic layout (unlike html).

One way of getting "automatic layout" is to make an html element which takes up the entire semagrams window but is transparent and doesn't intercept mouse actions, and then doing layout within that.

Attributes

Extensions

Extensions

extension [A](action: IO[A])
def onCancelOrError(fin: IO[A]): IO[A]

Perform fin if the action is cancelled or errors.

Perform fin if the action is cancelled or errors.

Note that if the action is cancelled, it never returns, so we only get the result of fin if it errors.

Attributes

def toOption: IO[Option[A]]

Convert a possibly erroring IO action to one that safely returns an Option

Convert a possibly erroring IO action to one that safely returns an Option

Attributes

extension (elts: Seq[Element])
def toSvg: String

Produce an SVG string representing a whole path. Used in the d attribute.

Produce an SVG string representing a whole path. Used in the d attribute.

Attributes

extension (t: Double)
def *(z: Complex): Complex

Multiplication by a complex implictly converts to complex

Multiplication by a complex implictly converts to complex

Attributes

def ^(x: Double): Double

Exponentiation as an infix operator

Exponentiation as an infix operator

Attributes

extension [A](x: Option[A])
def unwrap[F[_]](implicit F: MonadError[F, Throwable]): F[A]

Get the value of an option, throwing an error in a monad if the option is None. The advantage of throwing the error in the monad is that its more easily catchable.

Get the value of an option, throwing an error in a monad if the option is None. The advantage of throwing the error in the monad is that its more easily catchable.

Attributes

Implicits

Implicits

implicit def intToComplex(n: Int): Complex
implicit def realToComplex(x: Double): Complex

Exports

Defined exports

Exported from complexattrs

A custom svg attribute for setting cx and cy from one complex number

A custom svg attribute for setting cx and cy from one complex number

Attributes

Exported from complexattrs

A custom svg attribute for setting d (the svg element for describing a path) from a sequence of Path.Element.

A custom svg attribute for setting d (the svg element for describing a path) from a sequence of Path.Element.

Attributes

Exported from complexattrs

A custom svg attribute for setting points from a sequence of complex numbers

A custom svg attribute for setting points from a sequence of complex numbers

Attributes

Exported from complexattrs

A custom svg attribute for setting w and h from one complex number

A custom svg attribute for setting w and h from one complex number

Attributes

Exported from complexattrs

A custom svg attribute for setting x and y from one complex number

A custom svg attribute for setting x and y from one complex number

Attributes

Exported from complexattrs

A custom svg attribute for setting x1 and y1 from a complex number

A custom svg attribute for setting x1 and y1 from a complex number

Attributes

Exported from complexattrs

A custom svg attribute for setting x2 and y2 from a complex number

A custom svg attribute for setting x2 and y2 from a complex number

Attributes