Coder Social home page Coder Social logo

ampere's People

Contributors

cutflame avatar gbreen12 avatar ole avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ampere's Issues

Introduce a typealias UnitMapping

public protocol UnitProduct {
    associatedtype Factor1: Dimension
    associatedtype Factor2: Dimension
    associatedtype Product: Dimension

    typealias UnitMapping = (Factor1, Factor2, Product)

    static func defaultUnitMapping() -> UnitMapping
    static func preferredUnitMappings() -> [UnitMapping]
}

This capability is described in SE-0092, which has been implemented a few days ago, but it is not available in Xcode 8 beta 4 yet.

Add Swift Package Manager support

It might make sense to change the directory structure to the one expected by the Swift Package Manager. We could then use swift package generate-xcodeproj to create the Xcode project.

I can’t do this at the moment because:

  • SwiftPM only supports macOS and Linux at this point (not iOS).
  • The units and measurement APIs require macOS 10.12.
  • I haven’t upgraded to macOS 10.12 yet.

Some relations not expressible due to conflicts

This currently produces an error because UnitForce already conforms to UnitProduct for force = mass × acceleration and we cannot add another conformance to the same protocol:

/// Pressure = Force / Area ⇔ Force = Pressure * Area
/// 1 Pa = 1 N / 1 m²
extension UnitForce: UnitProduct {
    public typealias Factor1 = UnitPressure
    public typealias Factor2 = UnitArea
    public typealias Product = UnitForce

    public static func defaultUnitMapping() -> (Factor1, Factor2, Product) {
        return (.newtonsPerMetersSquared, .squareMeters, .newtons)
    }
}

Is it necessary to introduce another protocol (like UnitRatio) for this?

Add additional relations

All meaningful relations between the built-in unit types should be pre-defined here. Users should not be required to add their own for the built-in types.

Tagged Version

Thanks @ole for putting your articles code into this library. When reading them through I thought "that would be great as a library for this project" and I've just included it in one of our projects. Builds fine with Carthage, but it would be great to have a tagged version so we don't have to specify the master branch. That would prevent unwanted updates including breaking changes.

Currently we include this in our Cartfile:

github "ole/Ampere" "master"

I'd rather see something like this though (even if it is a 0 major version, it's better than master):

github "ole/Ampere" ~> 1.0

UnitVolume tests fail on Linux

This test fails on Linux:

    func testWithNonBaseUnits() {
        let factor1 = Measurement(value: 100, unit: UnitArea.squareCentimeters)
        let factor2 = Measurement(value: 10, unit: UnitLength.millimeters)
        let actual: Measurement<UnitVolume> = factor1 * factor2
        let expected = Measurement(value: 100, unit: UnitVolume.cubicCentimeters)
        AmpereTest.assertEqual(actual, expected)
    }

XCTAssertEqual failed: ("0.0001 m³") is not equal to ("0.001 m³") - "0.0001 m³" is not equal to "100.0 cm³"

This is due to a bug in swift-corelibs-foundation. Some of the conversion coefficients for UnitVolume are wrong.

Doesn't compile with Swift 3.1

Using the current version (0.1) I get the following error when trying to build this project with Xcode 8.3 and Swift 3.1:

UnitAreaTests.swift:17:27: Binary operator '/' cannot be applied to operands of type 'Measurement<UnitArea>' and 'Measurement<UnitLength>'

I also wonder why the test classes build when I run the framework with Cmd+B ...

Investigate failing tests on Linux

4 tests are currently failing on Linux:

...
2019-10-29T00:29:17.9614291Z /__w/Ampere/Ampere/Tests/AmpereTests/UnitAreaTests.swift:18: error: UnitAreaTests.testDivisionWithDefaultUnits : XCTAssertTrue failed - "m" is not the same unit as "m"
...
2019-10-29T00:29:17.9616731Z /__w/Ampere/Ampere/Tests/AmpereTests/UnitAreaTests.swift:10: error: UnitAreaTests.testMultiplicationWithDefaultUnits : XCTAssertTrue failed - "m²" is not the same unit as "m²"
...
2019-10-29T00:29:17.9618076Z /__w/Ampere/Ampere/Tests/AmpereTests/UnitAreaTests.swift:26: error: UnitAreaTests.testMultiplicationWithNonDefaultUnits : XCTAssertTrue failed - "m²" is not the same unit as "m²"
...
2019-10-29T00:29:17.9666816Z /__w/Ampere/Ampere/Tests/AmpereTests/UnitVolumeTests.swift:19: error: UnitVolumeTests.testWithNonBaseUnits : XCTAssertEqual failed: ("0.0001 m³") is not equal to ("0.001 m³") - "0.0001 m³" is not equal to "100.0 cm³"
...

No readability-improving typealiases?

In your first article you state:

Now add one typealias per unit class to get rid of the UnitLength prefix and I really start to like it:

I just searched the code though and couldn't find things like typealias Length = Measurement<UnitLength> in the code. Why is this, wouldn't it make sense to include them in Ampere, too? I'm now adding them manually to my project, but I wonder the rationale behind not adding them. Not to pollute the API? Dunno, seems like they make sense to me. Would be great to have them IMHO. 👍

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.