<commit_before>/*
*   GFPoint.mm
*
*   Copyright 2015 The Climate Corporation
*   Copyright 2015 <NAME>
*
*   Licensed under the Apache License, Version 2.0 (the "License");
*   you may not use this file except in compliance with the License.
*   You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
*   Unless required by applicable law or agreed to in writing, software
*   distributed under the License is distributed on an "AS IS" BASIS,
*   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*   See the License for the specific language governing permissions and
*   limitations under the License.
*
*   Created by <NAME> on 6/4/15.
*
*   MODIFIED 2015 BY <NAME>. Modifications licensed under Apache License, Version 2.0.
*
*/

#import "GFPoint.h"

#include "GFPoint+Primitives.hpp"
#include "GFGeometry+Protected.hpp"

#include "geofeatures/internal/Point.hpp"

#include <boost/geometry/io/wkt/wkt.hpp>

namespace gf = geofeatures::internal;

/**
 * @class       GFPoint
 *
 * @brief       A brief description.
 *
 * Here typically goes a more extensive explanation of what the header
 * defines. Doxygens tags are words preceeded by either a backslash @\
 * or by an at symbol @@.
 *
 * @author      <NAME>
 * @date        6/8/15
 */
@implementation GFPoint

    - (instancetype) init {
        self = [super initWithCPPGeometryVariant: gf::Point()];
        return self;
    }

    - (instancetype) initWithX:(double)x y:(double)y {
        gf::Point point;

        try {
            point.set<0>(x);
            point.set<1>(y);

        } catch (std::exception & e) {
            @throw [NSException exceptionWithName:@"Exception" reason: [NSString stringWithUTF8String: e.what()] userInfo:nil];
        }

        self = [super initWithCPPGeometryVariant: point];
        return self;
    }

    - (instancetype) initWithWKT:(NSString *)wkt {
        NSParameterAssert(wkt != nil);

        try {
            gf::Point point;

            boost::geometry::read_wkt([wkt cStringUsingEncoding: NSUTF8StringEncoding], point);

            self = [super initWithCPPGeometryVariant: point];

        } catch (std::exception & e) {
            @throw [NSException exceptionWithName:@"Exception" reason:[NSString stringWithUTF8String:e.what()] userInfo:nil];
        }
        return self;
    }

    - (instancetype) initWithGeoJSONGeometry:(NSDictionary *)jsonDictionary {

        id coordinates = jsonDictionary[@"coordinates"];

        if (!coordinates || ![coordinates isKindOfClass: [NSArray  class]]) {
            @throw [NSException exceptionWithName: NSInvalidArgumentException reason: @"Invalid GeoJSON Geometry Object, no coordinates found or coordinates of an invalid type."  userInfo: nil];
        }

        self = [super initWithCPPGeometryVariant: gf::GFPoint::pointWithGeoJSONCoordinates(coordinates)];
        return self;
    }

    - (double) x {
        const auto& point = boost::polymorphic_strict_get<gf::Point>(_members->geometryVariant);

        return point.get<0>();
    }

    - (double) y {<commit_msg>Update  GFPoint.mm - Removing try/catch wrapper on constructor as Point does not throw on construction. - Changed the exception type thrown for invalid wkt to NSInvalidArgumentException.<commit_after>/*
*   GFPoint.mm
*
*   Copyright 2015 The Climate Corporation
*   Copyright 2015 <NAME>
*
*   Licensed under the Apache License, Version 2.0 (the "License");
*   you may not use this file except in compliance with the License.
*   You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
*   Unless required by applicable law or agreed to in writing, software
*   distributed under the License is distributed on an "AS IS" BASIS,
*   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*   See the License for the specific language governing permissions and
*   limitations under the License.
*
*   Created by <NAME> on 6/4/15.
*
*   MODIFIED 2015 BY <NAME>. Modifications licensed under Apache License, Version 2.0.
*
*/

#import "GFPoint.h"

#include "GFPoint+Primitives.hpp"
#include "GFGeometry+Protected.hpp"

#include "geofeatures/internal/Point.hpp"

#include <boost/geometry/io/wkt/wkt.hpp>

namespace gf = geofeatures::internal;

/**
 * @class       GFPoint
 *
 * @brief       A brief description.
 *
 * Here typically goes a more extensive explanation of what the header
 * defines. Doxygens tags are words preceeded by either a backslash @\
 * or by an at symbol @@.
 *
 * @author      <NAME>
 * @date        6/8/15
 */
@implementation GFPoint

    - (instancetype) init {
        self = [super initWithCPPGeometryVariant: gf::Point()];
        return self;
    }

    - (instancetype) initWithX:(double)x y:(double)y {
        self = [super initWithCPPGeometryVariant: gf::Point(x,y)];
        return self;
    }

    - (instancetype) initWithWKT:(NSString *)wkt {
        NSParameterAssert(wkt != nil);

        try {
            gf::Point point;

            boost::geometry::read_wkt([wkt cStringUsingEncoding: NSUTF8StringEncoding], point);

            self = [super initWithCPPGeometryVariant: point];

        } catch (std::exception & e) {
            @throw [NSException exceptionWithName: NSInvalidArgumentException reason:[NSString stringWithUTF8String:e.what()] userInfo:nil];
        }
        return self;
    }

    - (instancetype) initWithGeoJSONGeometry:(NSDictionary *)jsonDictionary {

        id coordinates = jsonDictionary[@"coordinates"];

        if (!coordinates || ![coordinates isKindOfClass: [NSArray  class]]) {
            @throw [NSException exceptionWithName: NSInvalidArgumentException reason: @"Invalid GeoJSON Geometry Object, no coordinates found or coordinates of an invalid type."  userInfo: nil];
        }

        self = [super initWithCPPGeometryVariant: gf::GFPoint::pointWithGeoJSONCoordinates(coordinates)];
        return self;
    }

    - (double) x {
        const auto& point = boost::polymorphic_strict_get<gf::Point>(_members->geometryVariant);

        return point.get<0>();
    }

    - (double) y {
{'fraction_non_alphanumeric': 0.10610512569376428, 'fraction_numerical': 0.009957557949722494, 'mean_word_length': 3.103817816476892, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5486402', 'n_tokens_mistral': 1844, 'n_tokens_neox': 1704, 'n_words': 534}