Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adamwulf/touch-chart
Simplify and smooth UIBezierPaths by reducing the number of elements within the path.
https://github.com/adamwulf/touch-chart
Last synced: 3 days ago
JSON representation
Simplify and smooth UIBezierPaths by reducing the number of elements within the path.
- Host: GitHub
- URL: https://github.com/adamwulf/touch-chart
- Owner: adamwulf
- Created: 2012-03-12T08:12:57.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2021-04-11T05:10:09.000Z (over 3 years ago)
- Last Synced: 2024-05-01T12:30:07.441Z (7 months ago)
- Language: Objective-C
- Homepage: https://getlooseleaf.com
- Size: 32.9 MB
- Stars: 17
- Watchers: 5
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# TOUCH CHART V0.1
This repository is a part of [Loose Leaf](https://getlooseleaf.com).
In line with Sylion's work philosophy the design has been developed to greatly simplify the complexity of the code and maximizing the recycling of classes, as well as providing great ways for their extension.
The application comprises four new classes: `SYVectorView`, `SYFreePaintView`, `SYGeometricMathController` y `SYGeometry`. Following the design pattern MVC (Model View Controller), the `SYFreePaintView` class recieves taps from the user and sends them to the controller, namely `SYGeometricMathController`. The controller manages the data received from `SYFreePaintView` storing it until the user finishes the gesture lifting the finger from the iPad's screen. At that moment the `SYGeometricMathController` analyzes the result using the algorithms explained further, obtaining the figure that is ment to be represented. Once it finishes the analysis of the figure to be represented it sends an order to the class `SYVectorView` so it can draw it. `SYVectorView` will take care of displaying the finalized figure, drawing it as a vector shape.
The way in wich `SYGeometricMathController` communicates with SYVectorView is using the object `SYGeometry`. This object contains the needed parameters for the resulting figure's geometry to be displayed, such as trace color, fill color, kind of shape...## THE ALGORITHM
In the following sección we explain the used algorithm in very simple terms so it's easily undersood. The algorithm analyzes XY point sequence from the user's input during the gesture. These points are stored by the controller and are analyzed taking into account three key areas:- Maximum and minimum positions.
- Angles between adjacent points.
- Direction changes between points close in the list.## MAXIMUM AND MINIMUM POSITIONS
If we analyze the geometry of the square, rhombus and circle we notice that the relative position of maximums and minimums in the XY coordinate axis are different. The rhombus and circle contain their maximums in the middle point of the imaginary square that covers them, while the square has its maximums and minimums in each of its vertex. This feature is therefore very useful when we try to distinguish squares from circles or rhombus.## ANGLE CALCULATION
The controller also calculates the existing angles between a sequence of points in a path. If the angle in a three point sequence is around 180° it is known that the user is tracing a straight line. If by contrast these angles are inferior to an approximate value of 140° you can infer that the user is drastically changing the direction in the trace. This feature shows in a useful way the number of resulting vertices the figure could have.
## DIRECTION CHANGES
Just as we did with the angles `SYGeometricMathController` analyzes the point list and infers how they vary in the XY positions for each point regarding the previous. This reveals abrupt direction changes. Either the square or rhombus show abrupt direction changes while, in a properly traced circle, direction changes are gentle and progressive.## ASSUMPTIONS MADE BY THE ALGORITHM
The following values have been empirically obtained with successive trials in drawings by different users. It's known that for angle variations of zero or close to zero the figure has a high probability of being a circle. On the other hand, for changes in direction superior to eight it could be said with high probability that the figure to be drawn is a rhombus. For angle and direction values between two and five figure identification becomes less accurate or with an inferior chance of success.