Skip to content

Commit

Permalink
doc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
cormullion committed Jan 10, 2022
1 parent dfc55a0 commit 5875f44
Show file tree
Hide file tree
Showing 8 changed files with 267 additions and 44 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 2 additions & 3 deletions benchmark/simple-benchmarks.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# simple benchmars

using Luxor, BenchmarkTools
# simple benchmarks

using Luxor
using BenchmarkTools

function bm1()
Expand Down
188 changes: 188 additions & 0 deletions docs/src/assets/figures/latexequation.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
86 changes: 53 additions & 33 deletions docs/src/example/examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
```
15 changes: 12 additions & 3 deletions docs/src/howto/geometrytools.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/BoundingBox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions src/point.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5875f44

Please sign in to comment.