成人无码视频,亚洲精品久久久久av无码,午夜精品久久久久久毛片,亚洲 中文字幕 日韩 无码

資訊專欄INFORMATION COLUMN

JAVA Polygon 在配送區(qū)域超區(qū)校驗的實踐

Me_Kun / 834人閱讀

摘要:業(yè)務(wù)背景物流同城配送,在用戶下單的時候會進(jìn)行配送超區(qū)校驗,前端會將用戶的定位傳入后臺服務(wù),后臺服務(wù)針對商家的自定義配送區(qū)域通過地圖控件拖拽出來的不規(guī)則圖形進(jìn)行校驗。

業(yè)務(wù)背景

物流同城配送,在用戶下單的時候會進(jìn)行配送超區(qū)校驗,前端會將用戶的定位傳入后臺服務(wù),后臺服務(wù)針對商家的自定義配送區(qū)域(通過地圖控件拖拽出來的不規(guī)則圖形)進(jìn)行校驗。

實現(xiàn)方案

利用java se工具類來做 java.awt.Polygon

api地址: https://docs.oracle.com/javas...

使用到的api主要有:

public Polygon(int[] xpoints,int[] ypoints,int npoints)
Parameters:
xpoints - an array of X coordinates 所有點的x坐標(biāo)
ypoints - an array of Y coordinates 所有點的y坐標(biāo)
npoints - the total number of points in the Polygon 總共的點數(shù)
scene:
把商家通過地圖拖拽的多邊形各點傳入進(jìn)來,實例化Polygon對象

public boolean contains(double x,double y)
Parameters:
x - the specified X coordinate to be tested x坐標(biāo)
y - the specified Y coordinate to be tested y坐標(biāo)
scene:
獲取用戶當(dāng)前定位的經(jīng)緯度,作為x,y坐標(biāo)系傳入進(jìn)行判斷

使用示例 判斷規(guī)則矩形包含點

   /**
     * 用例描述:測試場景 多邊形為矩形 判斷點是否在范圍內(nèi)
     *
     *
     * @since  2016-12-06 by 青芒
     */
    @Test
    public void test_rec_ContainsPoint(){
        try {
            int[] xpoints = {1,1,5,5};
            int[] ypoints = {1,5,5,1};
            Polygon polygon = new Polygon(xpoints, ypoints,4);

            boolean contains;

            Point p = new Point(2,2);
            contains = polygon.contains(p);
            Assert.assertTrue(contains);

            contains = polygon.contains(2, 2);
            Assert.assertTrue(contains);

            contains = polygon.contains(1, 4);
            Assert.assertTrue(contains);

            contains = polygon.contains(2, 2);
            Assert.assertTrue(contains);

            contains = polygon.contains(2.5, 2.5);
            Assert.assertTrue(contains);
        } catch (Exception e) {
            Assert.fail();
        }
    }
判斷規(guī)則矩形包含矩形(拓展下,當(dāng)前場景用不到)

   /**
     * 用例描述:測試場景 多邊形為矩形 判斷矩形是否在范圍內(nèi)
     *
     *
     * @since  2016-12-06 by 青芒
     */
    @Test
    public void test_rec_ContainsRectangle(){
        try {
            int[] xpoints = {1,1,5,5};
            int[] ypoints = {1,5,5,1};
            Polygon polygon = new Polygon(xpoints, ypoints,4);

            Rectangle2D rectangle = new Rectangle(2,2,1,1);
            boolean contains = polygon.contains(rectangle);
            Assert.assertTrue(contains);
        } catch (Exception e) {
            Assert.fail();
        }
    }
判斷不規(guī)則圖形包含點

   /**
     * 用例描述:測試場景 不規(guī)則多邊形 包含點
     *
     *
     * @since  2016-12-06 by 青芒
     */
    @Test
    public void test_polygon_ContainsPoint(){
        try {
            int[] xpoints = {1,2,4,1,2};
            int[] ypoints = {3,4,3,3,2};
            Polygon polygon = new Polygon(xpoints, ypoints,5);
            boolean contains = polygon.contains(3, 3 );
            Assert.assertTrue(contains);

            contains = polygon.contains(2, 1);
            Assert.assertFalse(contains);
        } catch (Exception e) {
            Assert.fail();
        }
    }
判斷交叉不規(guī)則多邊形包含點

    /**
     * 用例描述:測試場景 交叉多邊形 包含點
     *
     *
     * @since  2016-12-06 by 青芒
     */
    @Test
    public void test_crossing_ContainsPoint(){
        try {
            int[] xpoints = {1,2,1,3,3};
            int[] ypoints = {1,2,3,3,1};
            Polygon polygon = new Polygon(xpoints, ypoints,5);
            boolean contains = polygon.contains(2, 2 );
            Assert.assertTrue(contains);

            contains = polygon.contains(2, 1 );
            Assert.assertTrue(contains);

            contains = polygon.contains(2, 1.5);
            Assert.assertTrue(contains);

            contains = polygon.contains(2.5, 2.5 );
            Assert.assertTrue(contains);

            //多邊形外圍
            contains = polygon.contains(0, 1);
            Assert.assertFalse(contains);

            contains = polygon.contains(1, 2);
            Assert.assertFalse(contains);

            contains = polygon.contains(3, 2);
            Assert.assertFalse(contains);
        } catch (Exception e) {
            Assert.fail();
        }
    }
結(jié)束

至此對于該超區(qū)校驗場景的實踐已經(jīng)介紹完畢,使用起來也不難,主要是讓大家知道通過javase 的awt類也是可以容易實現(xiàn)的。

文章版權(quán)歸作者所有,未經(jīng)允許請勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請注明本文地址:http://m.hztianpu.com/yun/66338.html

相關(guān)文章

  • 為了30分鐘配送,盒馬工程師都有哪些“神操作”?

    摘要:阿里妹導(dǎo)讀提到盒馬鮮生,除了新鮮的大龍蝦以外,大家印象最深的就是快速配送門店附近公里范圍內(nèi),分鐘送貨上門。系統(tǒng)異常業(yè)務(wù)異常的處理,上線時門店灰度方案一個門店出問題,不影響整個盒馬門店,緩存機(jī)制柔性可用重試機(jī)制事務(wù)處理串并行打日志等等。 showImg(https://segmentfault.com/img/remote/1460000018587196); 阿里妹導(dǎo)讀:提到盒馬鮮生...

    Me_Kun 評論0 收藏0
  • 機(jī)器學(xué)習(xí)美團(tuán)配送系統(tǒng)實踐:用技術(shù)還原真實世界

    摘要:可以說,美團(tuán)要建設(shè)的就是配送系統(tǒng)的超級大腦。美團(tuán)超腦配送系統(tǒng)目前互聯(lián)網(wǎng)技術(shù),很大部分還是針對線上產(chǎn)品和系統(tǒng)研發(fā),整個流程可以在線上全部完成,而這也正是配送技術(shù)最大的不同和挑戰(zhàn)。 在2018 AI開發(fā)者大會(AI NEXTCon)上,美團(tuán)配送AI方向負(fù)責(zé)人何仁清,分享了美團(tuán)在即時配送領(lǐng)域中機(jī)器學(xué)習(xí)技術(shù)的最新進(jìn)展,以及如何通過大數(shù)據(jù)和機(jī)器學(xué)習(xí)手段,建立對線下真實世界各種場景的感知能力,還原...

    hearaway 評論0 收藏0

發(fā)表評論

0條評論

閱讀需要支付1元查看
<