1
1
mirror of https://github.com/exyte/Macaw.git synced 2024-10-10 19:37:32 +03:00

Relative path bounds calculation

This commit is contained in:
Victor Sukochev 2016-05-07 15:49:14 +06:00
parent 888d55ec80
commit 52a71447f9
7 changed files with 70 additions and 9 deletions

View File

@ -28,6 +28,7 @@
574BDD9C1CAAA5D60031D313 /* TransformInterpolation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 574BDD9B1CAAA5D60031D313 /* TransformInterpolation.swift */; };
5754E63F1CB3B70D00657DA3 /* EasingAnimations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5754E63E1CB3B70D00657DA3 /* EasingAnimations.swift */; };
57982D531CB508E600111DAA /* PathAnimation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57982D521CB508E600111DAA /* PathAnimation.swift */; };
57B9DDD81CDDEEDE004300C2 /* CGExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 57B9DDD71CDDEEDE004300C2 /* CGExtensions.swift */; };
585C04481C27CFB100335FF2 /* MacawView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 585C04471C27CFB100335FF2 /* MacawView.swift */; };
B0086C561C789758008A4F69 /* GroupRenderer.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0086C551C789758008A4F69 /* GroupRenderer.swift */; };
B0097E081C706CAB00350E43 /* ObservableValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0097E071C706CAB00350E43 /* ObservableValue.swift */; };
@ -110,6 +111,7 @@
574BDD9B1CAAA5D60031D313 /* TransformInterpolation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TransformInterpolation.swift; sourceTree = "<group>"; };
5754E63E1CB3B70D00657DA3 /* EasingAnimations.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EasingAnimations.swift; sourceTree = "<group>"; };
57982D521CB508E600111DAA /* PathAnimation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PathAnimation.swift; sourceTree = "<group>"; };
57B9DDD71CDDEEDE004300C2 /* CGExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGExtensions.swift; sourceTree = "<group>"; };
585C04471C27CFB100335FF2 /* MacawView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MacawView.swift; sourceTree = "<group>"; };
B0086C551C789758008A4F69 /* GroupRenderer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GroupRenderer.swift; sourceTree = "<group>"; };
B0097E071C706CAB00350E43 /* ObservableValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ObservableValue.swift; sourceTree = "<group>"; };
@ -189,6 +191,7 @@
572661591CD233C50010D971 /* PathBounds.swift */,
571C63381CD37204008F4257 /* FuncBounds.swift */,
571C633A1CD373D0008F4257 /* PathFunctions.swift */,
57B9DDD71CDDEEDE004300C2 /* CGExtensions.swift */,
);
path = layer_animation;
sourceTree = "<group>";
@ -506,6 +509,7 @@
5754E63F1CB3B70D00657DA3 /* EasingAnimations.swift in Sources */,
B03275F41C78772F000BDD33 /* Circle.swift in Sources */,
B03276011C78772F000BDD33 /* Point.swift in Sources */,
57B9DDD81CDDEEDE004300C2 /* CGExtensions.swift in Sources */,
B03276141C78772F000BDD33 /* Text.swift in Sources */,
B03276051C78772F000BDD33 /* Rect.swift in Sources */,
571C63391CD37204008F4257 /* FuncBounds.swift in Sources */,

View File

@ -24,6 +24,10 @@ public class AnimationProducer {
return
}
guard let shape = animation.shape else {
return
}
// guard let bounds = animation.shape?.bounds() else {
// return
// }
@ -74,8 +78,15 @@ public class AnimationProducer {
let layer = ShapeLayer()
// layer.backgroundColor = UIColor.greenColor().CGColor
layer.frame = CGRectMake(0.0, 0.0, 100.0, 100.0)
layer.shape = animation.shape
layer.borderWidth = 1.0
layer.borderColor = UIColor.blueColor().CGColor
if let shapeBounds = shape.bounds() {
// layer.frame = shapeBounds.cgRect()
layer.frame = CGRectMake(0.0, 0.0, 100.0, 100.0)
}
layer.shape = shape
layer.setNeedsDisplay()
sceneLayer.addSublayer(layer)

View File

@ -0,0 +1,13 @@
import UIKit
extension Rect {
func cgRect() -> CGRect {
return CGRect(x: self.x, y: self.y, width: self.w, height: self.h)
}
}
extension Point {
func cgPoint() -> CGPoint {
return CGPoint(x: self.x, y: self.y)
}
}

View File

@ -1,5 +1,5 @@
func pathBounds(path: Path) -> Rect? {
func pathBounds(path: Path) -> Rect? {
guard let firstSegment = path.segments.first else {
return .None
@ -7,15 +7,25 @@ func pathBounds(path: Path) -> Rect? {
let firstSegmentInfo = pathSegmenInfo(firstSegment)
var bounds = firstSegmentInfo.0
var currentPoint = firstSegmentInfo.1
var currentPoint = firstSegmentInfo.1 ?? Point.zero()
for segment in path.segments {
let segmentInfo = pathSegmenInfo(segment)
if let segmentBounds = segmentInfo.0 {
bounds = bounds?.union(segmentBounds)
if segment.absolute {
bounds = bounds?.union(segmentBounds)
} else {
bounds = bounds?.union(segmentBounds).move(currentPoint)
}
}
currentPoint = segmentInfo.1
if let segmentLastPoint = segmentInfo.1 {
if segment.absolute {
currentPoint = segmentLastPoint
} else {
currentPoint = currentPoint.add(segmentLastPoint)
}
}
}
return bounds

View File

@ -1,13 +1,22 @@
import Foundation
public class Point: Locus {
public class Point: Locus {
public let x: Double
public let y: Double
public init(x: Double = 0, y: Double = 0) {
self.x = x
self.y = y
self.x = x
self.y = y
}
class func zero() -> Point {
return Point(x: 0.0, y: 0.0)
}
func add(point: Point) -> Point {
return Point(
x: self.x + point.x,
y: self.y + point.y)
}
}

View File

@ -32,6 +32,15 @@ public class Rect: Locus {
h: max(self.y + self.h, rect.y + rect.h))
}
// GENERATED NOT
public func move(offset: Point) -> Rect {
return Rect(
x: self.x + offset.x,
y: self.y + offset.y,
w: self.w,
h: self.h)
}
class func zero() -> Rect {
return Rect(x: 0.0, y: 0.0, w: 0.0, h: 0.0)
}

View File

@ -34,6 +34,11 @@ public class Shape: Node {
}
override public func bounds() -> Rect? {
if let path = form as? Path {
return pathBounds(path)
}
return form.bounds()
}
}