From 5875f44612c0fc1cb13881bab8756ca4b717345d Mon Sep 17 00:00:00 2001 From: cormullion Date: Mon, 10 Jan 2022 11:37:25 +0000 Subject: [PATCH] doc updates --- CHANGELOG.md | 6 +- LICENSE.md | 2 +- benchmark/simple-benchmarks.jl | 5 +- docs/src/assets/figures/latexequation.svg | 188 ++++++++++++++++++++++ docs/src/example/examples.md | 86 ++++++---- docs/src/howto/geometrytools.md | 15 +- src/BoundingBox.jl | 1 + src/point.jl | 8 +- 8 files changed, 267 insertions(+), 44 deletions(-) create mode 100644 docs/src/assets/figures/latexequation.svg diff --git a/CHANGELOG.md b/CHANGELOG.md index 17701f83..1f93f9ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,11 +8,13 @@ ### Changed -- changed return values of circle/ellipse/rect to boundingbox pts -(for @TheCedarPrince) +- changed return values of circle/ellipse/rect to boundingbox-able pts +(for @TheCedarPrince :)) - switched to Graham Scan algorithm for polyhull() +- isapprox allow kwargs + ### Removed ### Deprecated diff --git a/LICENSE.md b/LICENSE.md index d12de605..e3c10e2c 100644 --- a/LICENSE.md +++ b/LICENSE.md @@ -1,6 +1,6 @@ The Luxor.jl package is licensed under the MIT "Expat" License: -> Copyright (c) 2017-2021: cormullion. +> Copyright (c) 2017-2022: cormullion. > > Permission is hereby granted, free of charge, to any person obtaining > a copy of this software and associated documentation files (the diff --git a/benchmark/simple-benchmarks.jl b/benchmark/simple-benchmarks.jl index c8a784b5..4e0f9271 100644 --- a/benchmark/simple-benchmarks.jl +++ b/benchmark/simple-benchmarks.jl @@ -1,7 +1,6 @@ -# simple benchmars - -using Luxor, BenchmarkTools +# simple benchmarks +using Luxor using BenchmarkTools function bm1() diff --git a/docs/src/assets/figures/latexequation.svg b/docs/src/assets/figures/latexequation.svg new file mode 100644 index 00000000..2419e325 --- /dev/null +++ b/docs/src/assets/figures/latexequation.svg @@ -0,0 +1,188 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/docs/src/example/examples.md b/docs/src/example/examples.md index e69bfd94..070bfaaf 100644 --- a/docs/src/example/examples.md +++ b/docs/src/example/examples.md @@ -262,6 +262,26 @@ A = rand(1:99, 5, 8) end ``` +## Simple ``\LaTeX`` equations + +If you have the right fonts installed, you can easily draw simple ``\LaTeX`` equations. + +```julia +background("khaki") +f(t) = Point(4cos(t) + 2cos(5t), 4sin(t) + 2sin(5t)) +setline(15) +fontsize(35) +@layer begin + setopacity(0.4) + sethue("purple") + poly(20f.(range(0, 2π, length=160)), :stroke) +end +sethue("grey5") +text(L"f(t) = [4cos(t) + 2cos(5t), 4sin(t) + 2sin(5t)]", halign=:center) +``` + +![LaTEX](../assets/figures/latexequation.svg) + ## Triangulations This example shows how a Delaunay triangulation of a set of @@ -273,48 +293,48 @@ using Luxor, Colors, Random # hide Random.seed!(42) # hide d = @drawsvg begin # hide - background("black") # hide - setlinejoin("bevel") # hide - verts = randompointarray(BoundingBox(), 40) +background("black") # hide +setlinejoin("bevel") # hide +verts = randompointarray(BoundingBox(), 40) - triangles = polytriangulate(verts) +triangles = polytriangulate(verts) # create Delaunay - @layer begin - for tri in triangles - sethue(HSB(rand(120:320), 0.7, 0.7)) - poly(tri, :stroke, close=true) - end +@layer begin + for tri in triangles + sethue(HSB(rand(120:320), 0.7, 0.7)) + poly(tri, :stroke, close=true) end +end - dict = Dict{Point, Vector{Int}}() +dict = Dict{Point, Vector{Int}}() - for (n, t) in enumerate(triangles) - for pt in t - if haskey(dict, pt) - push!(dict[pt], n) - else - dict[pt] = [n] - end +for (n, t) in enumerate(triangles) + for pt in t + if haskey(dict, pt) + push!(dict[pt], n) + else + dict[pt] = [n] end end +end - setopacity(0.9) - setline(3) - for v in verts - hull = Point[] - # vertex v belongs in triangle tri - tris = dict[v] - for tri in tris - push!(hull, trianglecenter(triangles[tri]...)) - end - sethue(HSB(rand(120:320), 0.7, 0.7)) - if length(hull) >= 3 - ph = polyhull(hull) - poly(ph, :fillpreserve, close=true) - sethue("black") - strokepath() - end +setopacity(0.9) +setline(3) +for v in verts + hull = Point[] + tris = dict[v] + # vertex v belongs to all triangles tris + for tri in tris + push!(hull, trianglecenter(triangles[tri]...)) end + sethue(HSB(rand(120:320), 0.7, 0.7)) + if length(hull) >= 3 + ph = polyhull(hull) + poly(ph, :fillpreserve, close=true) + sethue("black") + strokepath() + end +end end 800 500 # hide d # hide ``` diff --git a/docs/src/howto/geometrytools.md b/docs/src/howto/geometrytools.md index ecc5a4c7..1d52c942 100644 --- a/docs/src/howto/geometrytools.md +++ b/docs/src/howto/geometrytools.md @@ -170,7 +170,15 @@ Functions that help with geometry include [`distance`](@ref), [`getnearestpointo ## Triangle centers -To find the center of a triangle, use one of [`trianglecircumcenter`](@ref), [`triangleincenter`](@ref), [`trianglecenter`](@ref), [`triangleorthocenter`](@ref). +To find the center of a triangle, use one of: + +- [`trianglecircumcenter`](@ref) center of circumcircle/intersection of the perpendicular bisectors. + +- [`triangleincenter`](@ref) intersection of the interior angle bisectors + +- [`trianglecenter`](@ref) centroid + +- [`triangleorthocenter`](@ref) intersection of the altitudes ```@example using Luxor # hide @@ -323,9 +331,10 @@ bounding box. You can make a BoundingBox from the current drawing, two points, a text string, an existing polygon, a stored path, -or by modifying an existing one. +by modifying an existing one, or from calls to functions such +as `circle` or `box`. -`BoundingBox` without arguments defines an extent that +[`BoundingBox`](@ref) without arguments defines an extent that encloses the drawing (assuming that the origin is at the center of the drawing—see [`origin`](@ref)). Use `centered=false` if the drawing origin is still at the top diff --git a/src/BoundingBox.jl b/src/BoundingBox.jl index ce3846e3..6318940c 100644 --- a/src/BoundingBox.jl +++ b/src/BoundingBox.jl @@ -28,6 +28,7 @@ An instance of the BoundingBox type holds two Points, BoundingBox(;centered = true) # the bounding box of the Drawing BoundingBox(s::AbstractString) # the bounding box of a text string at the origin BoundingBox(pt::Array) # the bounding box of a polygon +BoundingBox(circle(O, 100)) # the bounding box of a circle function BoundingBox(path::Path) # the bounding box of a Path """ function BoundingBox(; centered = true) diff --git a/src/point.jl b/src/point.jl index 2527c3c2..743bd1d6 100644 --- a/src/point.jl +++ b/src/point.jl @@ -51,7 +51,6 @@ Base.eltype(::Point) = Float64 Base.iterate(p::Point, state = 1) = state > length(p) ? nothing : (p[state], state + 1) Base.length(::Point) = 2 - """ dotproduct(a::Point, b::Point) @@ -68,7 +67,12 @@ end # comparisons isequal(p1::Point, p2::Point) = isapprox(p1.x, p2.x, atol=0.00000001) && (isapprox(p1.y, p2.y, atol=0.00000001)) + isapprox(p1::Point, p2::Point) = isapprox(p1.x, p2.x, atol=0.00000001) && (isapprox(p1.y, p2.y, atol=0.00000001)) + +# allow kwargs +isapprox(p1::Point, p2::Point; kwargs...) = isapprox(p1.x, p2.x; kwargs...) && (isapprox(p1.y, p2.y; kwargs...)) + isless(p1::Point, p2::Point) = (p1.x < p2.x || (isapprox(p1.x, p2.x) && p1.y < p2.y)) !=(p1::Point, p2::Point) = !isequal(p1, p2) <(p1::Point, p2::Point) = isless(p1, p2) @@ -536,7 +540,7 @@ end Find the angle formed by two lines defined by three points. -If the angle is less than π, the line heads to the left. +If the angle is less than π, the line heads to the left. """ function anglethreepoints(A::Point, B::Point, C::Point) v1 = B - A # line from A to B