Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access control: open'ed things that was private #113

Merged
merged 2 commits into from
Feb 22, 2018

Conversation

neoneye
Copy link
Contributor

@neoneye neoneye commented Feb 2, 2018

RSBarcodes_Swift is a great framework. I use it in 2 projects. It's robust and easy.

In this PR I have inserted the open keyword a few places. In particular I need to access the internal videoPreviewLayer ivar and I need to override the reloadVideoOrientation() function.

Yesterday+today I have been writing code that restricts the scanning area to a tiny box centered on the screen. For this purpose Apple provides AVCaptureMetadataOutput.rectOfInterest. I had to figure out how to compute the rectOfInterest using camera coordinates in the range 0..1. It was especially challenging dealing with orientation changes on iPad. Invoking updateRectOfInterest() too early and then the coordinates would be wrong. I have tested on iPad Pro and on iPhone6s and the rectOfInterest is working.

My subclass looks like this:

class MyScannerViewController: RSCodeReaderViewController {
    @IBOutlet weak var restrictedScanArea: UIView!

    override func viewDidLayoutSubviews() {
        super.viewDidLayoutSubviews()
        updateRectOfInterest()
    }

    override func reloadVideoOrientation() {
        super.reloadVideoOrientation()
        updateRectOfInterest()
    }

    func updateRectOfInterest() {
        guard let videoPreviewLayer: AVCaptureVideoPreviewLayer = self.videoPreviewLayer else {
            return
        }
        let scanRect = self.restrictedScanArea.frame
        /// Convert from display coordinates (pixels) to camera coordinates (0..1 range)
        /// scanRect: (515.0, 443.0, 336.0, 138.0)  rectOfInterest: (0.408, 0.433, 0.185, 0.135)
        output.rectOfInterest = videoPreviewLayer.metadataOutputRectConverted(fromLayerRect: scanRect)
    }
}


I can see that there are other people that have asked about rectOfInterest, see issue 76 and issue 110.

… this in order to access `layerRectConverted()` and `metadataOutputRectConverted()`
…ewController` and override `reloadVideoOrientation()` because I need to update the `rectOfInterest`. Whenever the user changes orientation, then I have to update the `rectOfInterest`.
@codecov-io
Copy link

Codecov Report

Merging #113 into master will decrease coverage by 0.55%.
The diff coverage is 25%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #113      +/-   ##
==========================================
- Coverage   49.49%   48.94%   -0.56%     
==========================================
  Files          23       23              
  Lines        1388     1706     +318     
  Branches        0       53      +53     
==========================================
+ Hits          687      835     +148     
- Misses        701      846     +145     
- Partials        0       25      +25
Impacted Files Coverage Δ
Source/RSCodeReaderViewController.swift 12.25% <25%> (-1.09%) ⬇️
.../RSBarcodesSampleTests/RSBarcodesSampleTests.swift 76.54% <0%> (-23.46%) ⬇️
...RSBarcodesSample/BarcodeReaderViewController.swift 40.54% <0%> (-4.46%) ⬇️
Source/RSUnifiedCodeGenerator.swift 76.56% <0%> (-3.44%) ⬇️
...SBarcodesSample/RSBarcodesSample/AppDelegate.swift 36.36% <0%> (-1.14%) ⬇️
Source/RSEANGenerator.swift 96.96% <0%> (-0.99%) ⬇️
Source/RSUnifiedCodeValidator.swift 0% <0%> (ø) ⬆️
Source/RSFocusMarkLayer.swift 0% <0%> (ø) ⬆️
...SBarcodesSample/BarcodeDisplayViewController.swift 0% <0%> (ø) ⬆️
... and 13 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 458c789...14be9ff. Read the comment docs.

@neoneye neoneye changed the title Access control: open ivar+functions, that previous was private Access control: open'ed things that previously was private Feb 2, 2018
@neoneye neoneye changed the title Access control: open'ed things that previously was private Access control: open'ed things that was private Feb 2, 2018
@yeahdongcn yeahdongcn merged commit 23d830e into yeahdongcn:master Feb 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants