diff --git a/CHANGELOG.md b/CHANGELOG.md index 94f6e53f..d4dba905 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,12 @@ # Changelog -## [v2.7.0] - January 2021 probably. +## [v2.7.0] - January 7 2021 ### Added - triangle functions - perpendicular() bisector +- macros allow variables (thanks Mason!) ### Changed diff --git a/src/point.jl b/src/point.jl index 31e2de4c..f92dd623 100644 --- a/src/point.jl +++ b/src/point.jl @@ -307,75 +307,6 @@ function ispointonline(pt::Point, pt1::Point, pt2::Point; end end -# """ -# intersection(p1::Point, p2::Point, p3::Point, p4::Point; -# commonendpoints = false, -# crossingonly = false, -# collinearintersect = false) -# -# Find intersection of two lines `p1`-`p2` and `p3`-`p4` -# -# Deprecated. Use `intersectionlines().` -# """ -# function intersection(A::Point, B::Point, C::Point, D::Point; -# commonendpoints = false, -# crossingonly = false, -# collinearintersect = false -# ) -# # false if either line is undefined -# if (A == B) || (C == D) -# return (false, Point(0, 0)) -# end -# -# # false if the lines share a common end point -# if commonendpoints -# if (A == C) || (B == C) || (A == D) || (B == D) -# return (false, Point(0, 0)) -# end -# end -# -# # Cramer's ? -# A1 = (A.y - B.y) -# B1 = (B.x - A.x) -# C1 = (A.x * B.y - B.x * A.y) -# -# L1 = (A1, B1, -C1) -# -# A2 = (C.y - D.y) -# B2 = (D.x - C.x) -# C2 = (C.x * D.y - D.x * C.y) -# -# L2 = (A2, B2, -C2) -# -# d = L1[1] * L2[2] - L1[2] * L2[1] -# dx = L1[3] * L2[2] - L1[2] * L2[3] -# dy = L1[1] * L2[3] - L1[3] * L2[1] -# -# # if you ask me collinear points don't really intersect -# if (C1 == C2) && (collinearintersect == false) -# return (false, Point(0, 0)) -# end -# -# if d != 0 -# pt = Point(dx/d, dy/d) -# if crossingonly == true -# if ispointonline(pt, A, B) && ispointonline(pt, C, D) -# return (true, pt) -# else -# return (false, pt) -# end -# else -# if ispointonline(pt, A, B, extended=true) && ispointonline(pt, C, D, extended=true) -# return (true, pt) -# else -# return (false, pt) -# end -# end -# else -# return (false, Point(0, 0)) -# end -# end - """ slope(pointA::Point, pointB::Point) @@ -383,12 +314,16 @@ Find angle of a line starting at `pointA` and ending at `pointB`. Return a value between 0 and 2pi. Value will be relative to the current axes. - slope(O, Point(0, 100)) |> rad2deg # y is positive down the page - 90.0 +``` +slope(O, Point(0, 100)) |> rad2deg # y is positive down the page +90.0 - slope(Point(0, 100), O) |> rad2deg - 270.0 +slope(Point(0, 100), O) |> rad2deg +270.0 +``` +The slope isn't the same as the gradient. A vertical line going up has a +slope of 3π/2. """ function slope(pointA, pointB) return mod2pi(atan(pointB.y - pointA.y, pointB.x - pointA.x)) diff --git a/test/runtests.jl b/test/runtests.jl index a59a7028..cf23e22e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -154,6 +154,7 @@ function run_all_tests() include("boxmaptest.jl") include("noise-test.jl") include("dashtests.jl") + include("triangles.jl") end end diff --git a/test/triangles.jl b/test/triangles.jl new file mode 100644 index 00000000..235f5238 --- /dev/null +++ b/test/triangles.jl @@ -0,0 +1,58 @@ +#!/usr/bin/env julia + +using Luxor + +using Test + +using Random +Random.seed!(42) + +function triangle_tests(fname) + Drawing(800, 800, fname) + origin() + background("white") + fontsize(10) + + panes = Tiler(500, 500, 1, 2) + + @layer begin + translate(first(panes[1])) + # equilateral + tri1 = [polar(100, θ) for θ in (0, 2π/3, 4π/3)] + prettypoly(tri1, :stroke, close=true) + + orthocenter = triangleorthocenter(tri1...) + incenter = triangleincenter(tri1...) + center = trianglecenter(tri1...) + circumcenter = trianglecircumcenter(tri1...) + circle.((orthocenter, incenter, center, circumcenter), 2, :fill) + + # all centers are the same + @test isapprox(orthocenter, incenter) + @test isapprox(orthocenter, center) + @test isapprox(orthocenter, circumcenter) + end + + @layer begin + translate(first(panes[2])) + # isosceles + tri2 = [Point(0, 0), Point(80, -80), Point(160, 0)] + prettypoly(tri2, :stroke, close=true) + + orthocenter = triangleorthocenter(tri2...) + incenter = triangleincenter(tri2...) + center = trianglecenter(tri2...) + circumcenter = trianglecircumcenter(tri2...) + circle.((orthocenter, incenter, center, circumcenter), 2, :fill) + + # all centers lie on the same vetical line + @test isapprox(orthocenter.x, incenter.x) + @test isapprox(orthocenter.x, center.x) + @test isapprox(orthocenter.x, circumcenter.x) + end + + @test finish() == true + println("...finished test: output in $(fname)") +end + +triangle_tests("triangle-tests.svg")