This commit is contained in:
Gavin Nishizawa 2023-03-14 11:18:46 -07:00
parent 133c8aa8ec
commit 8fe2eee56d
No known key found for this signature in database
GPG key ID: AE3B177777CE55CD
8 changed files with 100 additions and 92 deletions

View file

@ -355,13 +355,13 @@ func (sd *sequenceDiagram) placeActors() {
}
// addLifelineEdges adds a new edge for each actor in the graph that represents the its lifeline
// ┌──────────────┐
// │ actor │
// └──────┬───────┘
//
// │ lifeline
//
//
// . ┌──────────────┐
// . │ actor │
// . └──────┬───────┘
// .
// . │ lifeline
// .
// .
func (sd *sequenceDiagram) addLifelineEdges() {
endY := 0.
if len(sd.messages) > 0 {
@ -433,17 +433,17 @@ func (sd *sequenceDiagram) placeNotes() {
}
// placeSpans places spans over the object lifeline
// ┌──────────┐
// │ actor │
// └────┬─────┘
// ┌─┴──┐
// │ │
// |span|
// │ │
// └─┬──┘
//
// lifeline
//
// . ┌──────────┐
// . │ actor │
// . └────┬─────┘
// . ┌─┴──┐
// . │ │
// . |span|
// . │ │
// . └─┬──┘
// .
// . lifeline
// .
func (sd *sequenceDiagram) placeSpans() {
// quickly find the span center X
rankToX := make(map[int]float64)

View file

@ -97,11 +97,12 @@ func ParseValue(value string) (d2ast.Value, error) {
}
// TODO: refactor parser to keep entire file in memory as []rune
// - trivial to then convert positions
// - lookahead is gone, just forward back as much as you want :)
// - streaming parser isn't really helpful.
// - just read into a string even and decode runes forward/back as needed
// - the whole file essentially exists within the parser as the AST anyway...
// - trivial to then convert positions
// - lookahead is gone, just forward back as much as you want :)
// - streaming parser isn't really helpful.
// - just read into a string even and decode runes forward/back as needed
// - the whole file essentially exists within the parser as the AST anyway...
//
// TODO: ast struct that combines map & errors and pass that around
type parser struct {
path string
@ -315,13 +316,15 @@ func (p *parser) commit() {
//
// TODO: make each parse function read its delimiter and return nil if not as expected
// TODO: lookahead *must* always be empty in between parse calls. you either commit or
// rewind in each function. if you don't, you pass a hint.
//
// rewind in each function. if you don't, you pass a hint.
//
// TODO: omg we don't need two buffers, just a single lookahead and an index...
// TODO: get rid of lookaheadPos or at least never use directly. maybe rename to beforePeekPos?
// or better yet keep positions in the lookahead buffer.
// ok so plan here is to get rid of lookaheadPos and add a rewindPos that stores
// the pos to rewind to.
//
// or better yet keep positions in the lookahead buffer.
// ok so plan here is to get rid of lookaheadPos and add a rewindPos that stores
// the pos to rewind to.
func (p *parser) rewind() {
if len(p.lookahead) == 0 {
return

View file

@ -22,18 +22,18 @@ import (
// The layout plugin protocol works as follows.
//
// Info
// 1. The binary is invoked with info as the first argument.
// 2. The stdout of the binary is unmarshalled into PluginInfo.
// 1. The binary is invoked with info as the first argument.
// 2. The stdout of the binary is unmarshalled into PluginInfo.
//
// Layout
// 1. The binary is invoked with layout as the first argument and the json marshalled
// d2graph.Graph on stdin.
// 2. The stdout of the binary is unmarshalled into a d2graph.Graph
// 1. The binary is invoked with layout as the first argument and the json marshalled
// d2graph.Graph on stdin.
// 2. The stdout of the binary is unmarshalled into a d2graph.Graph
//
// PostProcess
// 1. The binary is invoked with postprocess as the first argument and the
// bytes of the SVG render on stdin.
// 2. The stdout of the binary is bytes of SVG with any post-processing.
// 1. The binary is invoked with postprocess as the first argument and the
// bytes of the SVG render on stdin.
// 2. The stdout of the binary is bytes of SVG with any post-processing.
//
// If any errors occur the binary will exit with a non zero status code and write
// the error to stderr.

View file

@ -132,12 +132,12 @@ func ListPluginInfos(ctx context.Context, ps []Plugin) ([]*PluginInfo, error) {
}
// FindPlugin finds the plugin with the given name.
// 1. It first searches the bundled plugins in the global plugins slice.
// 2. If not found, it then searches each directory in $PATH for a binary with the name
// d2plugin-<name>.
// **NOTE** When D2 upgrades to go 1.19, remember to ignore exec.ErrDot
// 3. If such a binary is found, it builds an execPlugin in exec.go
// to get a plugin implementation around the binary and returns it.
// 1. It first searches the bundled plugins in the global plugins slice.
// 2. If not found, it then searches each directory in $PATH for a binary with the name
// d2plugin-<name>.
// **NOTE** When D2 upgrades to go 1.19, remember to ignore exec.ErrDot
// 3. If such a binary is found, it builds an execPlugin in exec.go
// to get a plugin implementation around the binary and returns it.
func FindPlugin(ctx context.Context, ps []Plugin, name string) (Plugin, error) {
for _, p := range ps {
info, err := p.Info(ctx)

View file

@ -65,7 +65,7 @@ func (bc BezierCurve) At(point float64) *Point {
return NewPoint(float64(curvePoint.X), float64(curvePoint.Y))
}
//nolint
// nolint
func ComputeIntersections(px, py, lx, ly []float64) []*Point {
out := make([]*Point, 0)
@ -111,7 +111,7 @@ func ComputeIntersections(px, py, lx, ly []float64) []*Point {
return out
}
//nolint
// nolint
func cubicRoots(P []float64) []float64 {
if PrecisionCompare(P[0], 0, PRECISION) == 0 {
if PrecisionCompare(P[1], 0, PRECISION) == 0 {
@ -209,7 +209,7 @@ func cubicRoots(P []float64) []float64 {
return t
}
//nolint
// nolint
func sortSpecial(a []float64) []float64 {
var flip bool
var temp float64
@ -235,7 +235,7 @@ func sortSpecial(a []float64) []float64 {
return a
}
//nolint
// nolint
func sgn(x float64) float64 {
if x < 0.0 {
return -1
@ -243,7 +243,7 @@ func sgn(x float64) float64 {
return 1
}
//nolint
// nolint
func bezierCoeffs(P0, P1, P2, P3 float64) []float64 {
Z := make([]float64, 4)
Z[0] = -P0 + 3*P1 + -3*P2 + P3

View file

@ -55,24 +55,24 @@ func (segment Segment) Intersections(otherSegment Segment) []*Point {
// If there is no floor or ceiling, negative or positive infinity is used, respectively
// The direction is inferred, e.g. b/c the passed in segment is vertical, it's inferred we want horizontal bounds
// buffer says how close the segment can be, on both axes, to other segments given
// │ │
// │ │
// │ │
// │ │
// │ non-overlap
//
//
//
// │ segment
// │ │
// │ │ ceil
// │ │ │
// │ │
// floor │ │
//
//
//
//
// . │ │
// . │ │
// . │ │
// . │ │
// . │ non-overlap
// .
// .
// .
// . │ segment
// . │ │
// . │ │ ceil
// . │ │ │
// . │ │
// . floor │ │
// .
// .
// .
// .
// NOTE: the assumption is that all segments given are orthogonal
func (segment *Segment) GetBounds(segments []*Segment, buffer float64) (float64, float64) {
ceil := math.Inf(1)

View file

@ -175,22 +175,22 @@ func NewShape(shapeType string, box *geo.Box) Shape {
// p is the prev point (used to calculate slope)
// s is the point on the actual shape border that'll be returned
//
// p
//
//
//
// ┌────r─────────────────────────┐
// │ │
// │ │ │
// │ │ xxxxxxxx │
// │ ▼ xxxxx xxxx │
// │ sxxx xx │
// │ x xx │
// │ xx xx │
// │ x xx │
// │ xx xxx │
// │ xxxx xxxx │
// └──────xxxxxxxxxxxxxx──────────┘
// . p
// .
// .
// .
// . ┌────r─────────────────────────┐
// . │ │
// . │ │ │
// . │ │ xxxxxxxx │
// . │ ▼ xxxxx xxxx │
// . │ sxxx xx │
// . │ x xx │
// . │ xx xx │
// . │ x xx │
// . │ xx xxx │
// . │ xxxx xxxx │
// . └──────xxxxxxxxxxxxxx──────────┘
func TraceToShapeBorder(shape Shape, rectBorderPoint, prevPoint *geo.Point) *geo.Point {
if shape.Is("") || shape.IsRectangular() {
return rectBorderPoint

View file

@ -32,23 +32,27 @@ func init() {
// Ruler allows for effiecient and convenient text drawing.
//
// To create a Ruler object, use the New constructor:
// txt := text.New(pixel.ZV, text.NewAtlas(face, text.ASCII))
//
// txt := text.New(pixel.ZV, text.NewAtlas(face, text.ASCII))
//
// As suggested by the constructor, a Ruler object is always associated with one font face and a
// fixed set of runes. For example, the Ruler we created above can draw text using the font face
// contained in the face variable and is capable of drawing ASCII characters.
//
// Here we create a Ruler object which can draw ASCII and Katakana characters:
// txt := text.New(0, text.NewAtlas(face, text.ASCII, text.RangeTable(unicode.Katakana)))
//
// txt := text.New(0, text.NewAtlas(face, text.ASCII, text.RangeTable(unicode.Katakana)))
//
// Similarly to IMDraw, Ruler functions as a buffer. It implements io.Writer interface, so writing
// text to it is really simple:
// fmt.Print(txt, "Hello, world!")
//
// fmt.Print(txt, "Hello, world!")
//
// Newlines, tabs and carriage returns are supported.
//
// Finally, if we want the written text to show up on some other Target, we can draw it:
// txt.Draw(target)
//
// txt.Draw(target)
//
// Ruler exports two important fields: Orig and Dot. Dot is the position where the next character
// will be written. Dot is automatically moved when writing to a Ruler object, but you can also
@ -93,14 +97,15 @@ type Ruler struct {
// will be initially set to orig.
//
// Here we create a Ruler capable of drawing ASCII characters using the Go Regular font.
// ttf, err := truetype.Parse(goregular.TTF)
// if err != nil {
// panic(err)
// }
// face := truetype.NewFace(ttf, &truetype.Options{
// Size: 14,
// })
// txt := text.New(orig, text.NewAtlas(face, text.ASCII))
//
// ttf, err := truetype.Parse(goregular.TTF)
// if err != nil {
// panic(err)
// }
// face := truetype.NewFace(ttf, &truetype.Options{
// Size: 14,
// })
// txt := text.New(orig, text.NewAtlas(face, text.ASCII))
func NewRuler() (*Ruler, error) {
origin := geo.NewPoint(0, 0)
r := &Ruler{