/*
* Copyright (c) 2025 LG Electronics Inc.
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
*/
using Aurora.Api;
using System;
using System.Runtime.InteropServices;
namespace VisionCommon {
[Serializable]
[StructLayout(LayoutKind.Sequential)]
public struct PointData {
public double X;
public double Y;
}
public static class NativePattern {
private const string FILE_NAME_VISION_DLL = "VisionCore.dll";
private static Logger _Logger = new Logger("NativePattern");
[DllImport(FILE_NAME_VISION_DLL)]
extern private static PointData IntersectionPoint(
double line1A, double line1B, double line1C,
double line2A, double line2B, double line2C);
[DllImport(FILE_NAME_VISION_DLL)]
extern private static PointData VerticalIntersectionPoint(
PointData line1Point,
double line1A, double line1B, double line1C,
double line2A, double line2B, double line2C);
[DllImport(FILE_NAME_VISION_DLL)]
extern private static double DistancePointToLine(
PointData point,
double lineA, double lineB, double lineC);
///
/// 라인1,2 간에 교점 계산
///
/// 라인1
/// 라인2
/// 라인1,2 간에 교점
public static T GetIntersectionPoint(LineEquation le1, LineEquation le2) where T : DoublePoint {
PointData pointData = IntersectionPoint(
le1.A, le1.B, le1.C,
le2.A, le2.B, le2.C);
return (T)Activator.CreateInstance(typeof(T), pointData.X, pointData.Y);
}
///
/// 라인1을 지나는 점에서 수직인 라인과 라인2 간에 교점 계산
///
/// 라인1을 지나는 점
/// 라인1
/// 라인2
/// 라인1을 지나는 점에서 수직인 라인과 라인2 간에 교점
public static ImagePoint GetVerticalIntersectionPoint(ImagePoint le1Point, LineEquation le1, LineEquation le2) {
PointData le1PointData = new PointData() {
X = le1Point.X,
Y = le1Point.Y
};
PointData pointData = VerticalIntersectionPoint(
le1PointData,
le1.A, le1.B, le1.C,
le2.A, le2.B, le2.C);
return new ImagePoint(pointData.X, pointData.Y);
}
///
/// 점과 라인 간에 거리 계산
///
/// 점
/// 라인
/// 점과 라인 간에 거리
public static double GetDistancePointToLine(ImagePoint point, LineEquation le) {
PointData le1PointData = new PointData() {
X = point.X,
Y = point.Y
};
double distance = DistancePointToLine(
le1PointData,
le.A, le.B, le.C);
return distance;
}
}
}