jsbean / geometrytools Goto Github PK
View Code? Open in Web Editor NEWGeometrical structures for graphical applications
Geometrical structures for graphical applications
Currently, it is entirely possible to create a Size
with negative values.
extension Point {
func scaled(by amount: Double, from reference: Point) -> Point {
return (self - reference) * amount + reference
}
}
Except for the case of Rectangle.unit
, we want to normalize Rectangle
values before composing them.
This involves making the Size
positive for width
and height
, then translating the origin accordingly.
extension Rectangle {
init(width: Double, height: Double) {
...
}
}
extension Rectangle {
init(minX: Double, minY: Double, maxX: Double, maxY: Double) {
...
}
}
Currently, scaledBy(...)
is uniform between horizontal and vertical coordinates.
extension Point {
func rotated(by angle: Angle, around reference: Point) -> Point {
let p = self - reference
let radius = hypot(p.x, p.y)
let azimuth = atan2(p.x, p.y) + angle.radians
let rotated = Point(x: radius * cos(azimuth), y: radius * sin(azimuth))
return rotated + reference
}
}
The algorithm used to calculate the convex hull of polygons is the gift-wrapping algorithm.
This runs on O(nh) (i.e., kind of O(n2)), whereas other algorithms run in O(n log n).
This is very low priority, though worth knowing.
Just do this in PathTools
.
So it can be called point.translatedBy(y: 10)
Usage:
let frame2 = frame1.translated(by: -ref)
extension BezierCurve {
func rotated(by angle: Angle, around reference: Point) -> BezierCurve {
return BezierCurve(points: points.map { $0.rotated(by: angle, around: reference) })
}
}
extension BezierCurve {
func scaled(by amount: Double, from reference: Point) -> Point {
return BezierCurve(points: points.map { $0.scaled(by: amount, from: reference) })
}
}
Here.
degrees to radians: degrees * .pi / 180
radians to degrees: radians * 180 / .pi
Conform Rectangle
, Polygon
, Point
, Vector2
(maybe even Angle
) to Monoid
, where appropriate.
Usage:
let path2 = path1.translated(by: -referencePoint)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.